mirror of
https://github.com/brain-hackers/brain-config.git
synced 2024-12-22 20:20:06 +09:00
Add nonint mode to wireless setup
This commit is contained in:
parent
3929227971
commit
5fd793fcbf
22
raspi-config
22
raspi-config
@ -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
|
||||||
|
if [ "$INTERACTIVE" = True ]; then
|
||||||
whiptail --msgbox "No wireless interface found" 20 60
|
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
|
||||||
|
if [ "$INTERACTIVE" = True ]; then
|
||||||
whiptail --msgbox "Could not communicate with wpa_supplicant" 20 60
|
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,8 +1382,10 @@ 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
|
||||||
|
if [ "$INTERACTIVE" = True ]; then
|
||||||
whiptail --msgbox "Failed to set SSID or passphrase" 20 60
|
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
|
||||||
|
|
||||||
echo "$IFACE_LIST" | while read IFACE; do
|
echo "$IFACE_LIST" | while read IFACE; do
|
||||||
@ -1484,7 +1491,7 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
nonint() {
|
nonint() {
|
||||||
$*
|
"$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -1516,7 +1523,8 @@ do
|
|||||||
;;
|
;;
|
||||||
nonint)
|
nonint)
|
||||||
INTERACTIVE=False
|
INTERACTIVE=False
|
||||||
$@
|
"$@"
|
||||||
|
exit $?
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# unknown option
|
# unknown option
|
||||||
|
Loading…
Reference in New Issue
Block a user