Browse Source

Automatic detection of wifi adaptor

Bob Mottram 8 years ago
parent
commit
e6e21d0b24
1 changed files with 39 additions and 3 deletions
  1. 39
    3
      src/freedombone-wifi

+ 39
- 3
src/freedombone-wifi View File

37
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
37
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
38
 
38
 
39
 WIFI_INTERFACE=wlan0
39
 WIFI_INTERFACE=wlan0
40
+wifi_interface_specified=
40
 WIFI_TYPE='wpa2-psk'
41
 WIFI_TYPE='wpa2-psk'
41
 WIFI_SSID=
42
 WIFI_SSID=
42
 WIFI_PASSPHRASE=
43
 WIFI_PASSPHRASE=
46
 NETWORKS_INTERACTIVE=
47
 NETWORKS_INTERACTIVE=
47
 WIFI_DISABLE=
48
 WIFI_DISABLE=
48
 
49
 
50
+IFACE=
51
+IFACE_SECONDARY=
52
+
53
+function update_wifi_adaptors {
54
+    IFACE=
55
+    IFACE_SECONDARY=
56
+
57
+    for i in $(seq 10 -1 0); do
58
+        if grep -q "wlan${i}" /proc/net/dev; then
59
+            if [ ! $IFACE ]; then
60
+                IFACE="wlan${i}"
61
+            else
62
+                IFACE_SECONDARY="wlan${i}"
63
+                return
64
+            fi
65
+        fi
66
+    done
67
+}
68
+
49
 function wifi_get_psk {
69
 function wifi_get_psk {
50
     ssid=$1
70
     ssid=$1
51
     passphrase=$2
71
     passphrase=$2
267
 }
287
 }
268
 
288
 
269
 function create_networks_interactive {
289
 function create_networks_interactive {
290
+    update_wifi_adaptors
291
+    if [ ! $IFACE ]; then
292
+        # Don't try to configure wifi if there are no adaptors
293
+        return
294
+    fi
295
+
270
     if [ -f $WIFI_NETWORKS_FILE ]; then
296
     if [ -f $WIFI_NETWORKS_FILE ]; then
271
         rm $WIFI_NETWORKS_FILE
297
         rm $WIFI_NETWORKS_FILE
272
     fi
298
     fi
384
         -i|--if|--interface)
410
         -i|--if|--interface)
385
             shift
411
             shift
386
             WIFI_INTERFACE=${1}
412
             WIFI_INTERFACE=${1}
413
+            wifi_interface_specified=1
387
             ;;
414
             ;;
388
         -t|--type)
415
         -t|--type)
389
             shift
416
             shift
426
     shift
453
     shift
427
 done
454
 done
428
 
455
 
456
+if [ $NETWORKS_INTERACTIVE ]; then
457
+    create_networks_interactive
458
+    exit 0
459
+fi
460
+
429
 if [ $WIFI_DISABLE ]; then
461
 if [ $WIFI_DISABLE ]; then
430
     disable_wifi $WIFI_DISABLE
462
     disable_wifi $WIFI_DISABLE
431
     exit 0
463
     exit 0
432
 fi
464
 fi
433
 
465
 
434
-if [ $NETWORKS_INTERACTIVE ]; then
435
-    create_networks_interactive
436
-    exit 0
466
+if [ ! $wifi_interface_specified= ]; then
467
+    update_wifi_adaptors
468
+    if [ ! $IFACE ]; then
469
+        echo $'No wifi adaptors were found'
470
+        exit 872356
471
+    fi
472
+    WIFI_INTERFACE=$IFACE
437
 fi
473
 fi
438
 
474
 
439
 if [ -f $WIFI_NETWORKS_FILE ]; then
475
 if [ -f $WIFI_NETWORKS_FILE ]; then