From e6e21d0b2414e6a4bebe62640a203034b3945a54 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 21 Oct 2016 10:03:33 +0100 Subject: [PATCH] Automatic detection of wifi adaptor --- src/freedombone-wifi | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/freedombone-wifi b/src/freedombone-wifi index 40e5b27f..1995b906 100755 --- a/src/freedombone-wifi +++ b/src/freedombone-wifi @@ -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