Automatic detection of wifi adaptor

This commit is contained in:
Bob Mottram 2016-10-21 10:03:33 +01:00
parent 904d8d60af
commit e6e21d0b24
1 changed files with 39 additions and 3 deletions

View File

@ -37,6 +37,7 @@ CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
WIFI_INTERFACE=wlan0
wifi_interface_specified=
WIFI_TYPE='wpa2-psk'
WIFI_SSID=
WIFI_PASSPHRASE=
@ -46,6 +47,25 @@ WIFI_NETWORKS_FILE=~/${PROJECT_NAME}-wifi.cfg
NETWORKS_INTERACTIVE=
WIFI_DISABLE=
IFACE=
IFACE_SECONDARY=
function update_wifi_adaptors {
IFACE=
IFACE_SECONDARY=
for i in $(seq 10 -1 0); do
if grep -q "wlan${i}" /proc/net/dev; then
if [ ! $IFACE ]; then
IFACE="wlan${i}"
else
IFACE_SECONDARY="wlan${i}"
return
fi
fi
done
}
function wifi_get_psk {
ssid=$1
passphrase=$2
@ -267,6 +287,12 @@ function networks_from_file {
}
function create_networks_interactive {
update_wifi_adaptors
if [ ! $IFACE ]; then
# Don't try to configure wifi if there are no adaptors
return
fi
if [ -f $WIFI_NETWORKS_FILE ]; then
rm $WIFI_NETWORKS_FILE
fi
@ -384,6 +410,7 @@ do
-i|--if|--interface)
shift
WIFI_INTERFACE=${1}
wifi_interface_specified=1
;;
-t|--type)
shift
@ -426,14 +453,23 @@ do
shift
done
if [ $NETWORKS_INTERACTIVE ]; then
create_networks_interactive
exit 0
fi
if [ $WIFI_DISABLE ]; then
disable_wifi $WIFI_DISABLE
exit 0
fi
if [ $NETWORKS_INTERACTIVE ]; then
create_networks_interactive
exit 0
if [ ! $wifi_interface_specified= ]; then
update_wifi_adaptors
if [ ! $IFACE ]; then
echo $'No wifi adaptors were found'
exit 872356
fi
WIFI_INTERFACE=$IFACE
fi
if [ -f $WIFI_NETWORKS_FILE ]; then