Add nonint mode to wireless setup

This commit is contained in:
Serge Schneider 2017-11-08 15:15:24 +00:00
parent 3929227971
commit 5fd793fcbf

View File

@ -1309,17 +1309,21 @@ do_wifi_ssid_passphrase() {
IFACE="$(echo "$IFACE_LIST" | head -n 1)" IFACE="$(echo "$IFACE_LIST" | head -n 1)"
if [ -z "$IFACE" ]; then if [ -z "$IFACE" ]; then
whiptail --msgbox "No wireless interface found" 20 60 if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "No wireless interface found" 20 60
fi
return 1 return 1
fi fi
if ! wpa_cli -i "$IFACE" status > /dev/null 2>&1; then if ! wpa_cli -i "$IFACE" status > /dev/null 2>&1; then
whiptail --msgbox "Could not communicate with wpa_supplicant" 20 60 if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Could not communicate with wpa_supplicant" 20 60
fi
return 1 return 1
fi fi
SSID= SSID="$1"
while [ -z "$SSID" ]; do while [ -z "$SSID" ] && [ "$INTERACTIVE" = True ]; do
SSID=$(whiptail --inputbox "Please enter SSID" 20 60 3>&1 1>&2 2>&3) SSID=$(whiptail --inputbox "Please enter SSID" 20 60 3>&1 1>&2 2>&3)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
return 0 return 0
@ -1328,7 +1332,8 @@ do_wifi_ssid_passphrase() {
fi fi
done done
while true; do PASSPHRASE="$2"
while [ "$INTERACTIVE" = True ]; do
PASSPHRASE=$(whiptail --passwordbox "Please enter passphrase. Leave it empty if none." 20 60 3>&1 1>&2 2>&3) PASSPHRASE=$(whiptail --passwordbox "Please enter passphrase. Leave it empty if none." 20 60 3>&1 1>&2 2>&3)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
return 0 return 0
@ -1338,7 +1343,7 @@ do_wifi_ssid_passphrase() {
done done
# Escape special characters for embedding in regex below # Escape special characters for embedding in regex below
local ssid=$(echo "$SSID" \ local ssid="$(echo "$SSID" \
| sed 's;\\;\\\\;g' \ | sed 's;\\;\\\\;g' \
| sed -e 's;\.;\\\.;g' \ | sed -e 's;\.;\\\.;g' \
-e 's;\*;\\\*;g' \ -e 's;\*;\\\*;g' \
@ -1353,7 +1358,7 @@ do_wifi_ssid_passphrase() {
-e 's;};\\};g' \ -e 's;};\\};g' \
-e 's;(;\\(;g' \ -e 's;(;\\(;g' \
-e 's;);\\);g' \ -e 's;);\\);g' \
-e 's;";\\\\\";g') -e 's;";\\\\\";g')"
wpa_cli -i "$IFACE" list_networks \ wpa_cli -i "$IFACE" list_networks \
| tail -n +2 | cut -f -2 | grep -P "\t$ssid$" | cut -f1 \ | tail -n +2 | cut -f -2 | grep -P "\t$ssid$" | cut -f1 \
@ -1377,7 +1382,9 @@ do_wifi_ssid_passphrase() {
wpa_cli -i "$IFACE" enable_network "$ID" > /dev/null 2>&1 wpa_cli -i "$IFACE" enable_network "$ID" > /dev/null 2>&1
else else
wpa_cli -i "$IFACE" remove_network "$ID" > /dev/null 2>&1 wpa_cli -i "$IFACE" remove_network "$ID" > /dev/null 2>&1
whiptail --msgbox "Failed to set SSID or passphrase" 20 60 if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Failed to set SSID or passphrase" 20 60
fi
fi fi
wpa_cli -i "$IFACE" save_config > /dev/null 2>&1 wpa_cli -i "$IFACE" save_config > /dev/null 2>&1
@ -1484,7 +1491,7 @@ EOF
} }
nonint() { nonint() {
$* "$@"
} }
# #
@ -1516,7 +1523,8 @@ do
;; ;;
nonint) nonint)
INTERACTIVE=False INTERACTIVE=False
$@ "$@"
exit $?
;; ;;
*) *)
# unknown option # unknown option