Skip to content

Commit

Permalink
harmonize logging and opts
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvinSchiller committed Jan 26, 2024
1 parent 415d378 commit 23b7e77
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
4 changes: 2 additions & 2 deletions installation/routines/setup_autohotspot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ setup_autohotspot() {
if [ "$ENABLE_AUTOHOTSPOT" == true ] ; then
local installed=false
if [[ $(is_dhcpcd_enabled) == true || "${CI_RUNNING}" == "true" ]]; then
run_with_log_frame _run_setup_autohotspot_dhcpcd "Install AutoHotspot dhcpcd"
run_with_log_frame _run_setup_autohotspot_dhcpcd "Install AutoHotspot"
installed=true
fi

if [[ $(is_NetworkManager_enabled) == true || "${CI_RUNNING}" == "true" ]]; then
run_with_log_frame _run_setup_autohotspot_NetworkManager "Install AutoHotspot NetworkManager"
run_with_log_frame _run_setup_autohotspot_NetworkManager "Install AutoHotspot"
installed=true
fi

Expand Down
1 change: 1 addition & 0 deletions installation/routines/setup_autohotspot_NetworkManager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ _autohotspot_check_NetworkManager() {
}

_run_setup_autohotspot_NetworkManager() {
log "Install AutoHotspot NetworkManager"
_install_packages_NetworkManager
_get_interface
_uninstall_autohotspot_NetworkManager
Expand Down
1 change: 1 addition & 0 deletions installation/routines/setup_autohotspot_dhcpcd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ _autohotspot_check_dhcpcd() {
}

_run_setup_autohotspot_dhcpcd() {
log "Install AutoHotspot dhcpcd"
_install_packages_dhcpcd
_get_interface
_uninstall_autohotspot_dhcpcd
Expand Down
2 changes: 1 addition & 1 deletion resources/autohotspot/NetworkManager/autohotspot
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ nearby_ssids_iw()
local idssid=$(nmcli -t con show "${profile}" | grep "wireless.ssid")
if (echo "$ssidreply" | grep -F -- "${idssid:21}" ) >/dev/null 2>&1
then
echo "Valid SSID detected, assesing Wifi status"
echo "Valid SSID detected, assessing Wifi status"
ssidChk+="${profile}"
fi
done
Expand Down
45 changes: 26 additions & 19 deletions resources/autohotspot/dhcpcd/autohotspot
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
#Additions where made for the Phoniebox project
#https://github.com/MiczFlor/RPi-Jukebox-RFID

if [ $# -gt 0 ] ; then
if [ $# -eq 1 ] && [ "$1" == "--force-hotspot" ]; then
FORCE_HOTSPOT=1
else
echo "ignoring unrecognized parameter: $*"
fi
fi
while getopts "a" opt; do
case $opt in
a )
FORCE_HOTSPOT=true
;;
* )
echo "option not valid"
exit
;;
esac
done

NO_SSID='NoSSid'
ssidChk="$NO_SSID"
Expand Down Expand Up @@ -109,28 +113,29 @@ CheckServices()

CheckDevice()
{
echo "Device availability check"
local j=0
while [ true ] #wait for wifi if busy, usb wifi is slower.
do
echo "Device availability check: try $j"

if [ $j -ge 5 ]; then
#if no wifi device,ie usb wifi removed, activate wifi so when it is
#reconnected wifi to a router will be available
echo "No wifi device connected"
echo "No wifi device '$wifidev' connected"
InitWPA
exit 1
elif (iw dev "$wifidev" info 2>&1 >/dev/null) ; then
echo "wifi device available"
echo "Wifi device '$wifidev' available"
if (rfkill list wifi -rno HARD,SOFT | grep -i "unblocked.*unblocked") >/dev/null 2>&1 ; then
local wifidev_up=$(ip link show "$wifidev" up)
if [ -z "$wifidev_up" ]; then
echo "wifi is down. setting up"
echo "Wifi is down. Setting up"
ip link set dev "$wifidev" up
sleep 2
fi
return
else
echo "wifi is deactivated"
echo "Wifi is deactivated"
exit 0
fi
else
Expand All @@ -145,22 +150,21 @@ FindSSID()
if [ -n "$FORCE_HOTSPOT" ]; then return; fi

#Check to see what SSID's and MAC addresses are in range
echo "SSID availability check"
local i=0; j=0
while [ $i -eq 0 ]
do
scanreply=$(iw dev "$wifidev" scan ap-force 2>&1)
ssidreply=$(echo "$scanreply" | egrep "^BSS|SSID:")
echo "SSID availability check: try $j"
if [ $j -ge 5 ]; then
ssidreply=""
i=1
elif [ -z "$ssidreply" ] ; then
echo "Error scan SSID's: $scanreply"
echo "Error scan SSID's, try $j: $scanreply"
j=$((j + 1))
sleep 2
else
echo "SSID's in range:"
echo "$ssidreply"
#success
i=1
fi
done
Expand All @@ -169,12 +173,15 @@ FindSSID()
do
if (echo "$ssidreply" | grep "$ssid") >/dev/null 2>&1
then
#Valid SSid found, passing to script
echo "Valid SSID Detected, assesing Wifi status"
echo "Valid SSID detected, assessing Wifi status"
ssidChk=$ssid
return 0
break
fi
done

if [ "$ssidChk" == "$NO_SSID" ]; then
echo "No Valid SSID detected"
fi
}

CheckSSID()
Expand Down

0 comments on commit 23b7e77

Please sign in to comment.