Bob Mottram 9 лет назад
Родитель
Сommit
91871787cd
Аккаунт пользователя с таким Email не найден
1 измененных файлов: 83 добавлений и 64 удалений
  1. 83
    64
      src/freedombone-wifi

+ 83
- 64
src/freedombone-wifi Просмотреть файл

@@ -44,6 +44,7 @@ WIFI_HOTSPOT='no'
44 44
 WIFI_CONFIG=/etc/wpa_supplicant/wpa_supplicant.conf
45 45
 WIFI_NETWORKS_FILE=~/${PROJECT_NAME}-wifi.cfg
46 46
 NETWORKS_INTERACTIVE=
47
+WIFI_DISABLE=
47 48
 
48 49
 function wifi_get_psk {
49 50
     ssid=$1
@@ -261,51 +262,59 @@ function networks_from_file {
261 262
 }
262 263
 
263 264
 function create_networks_interactive {
264
-	if [ -f $WIFI_NETWORKS_FILE ]; then
265
-		rm $WIFI_NETWORKS_FILE
266
-	fi
265
+    if [ -f $WIFI_NETWORKS_FILE ]; then
266
+        rm $WIFI_NETWORKS_FILE
267
+    fi
267 268
 
268
-	wifi_ctr=0
269
-	wifi_networks_done=
269
+    wifi_ctr=0
270
+    wifi_networks_done=
270 271
     while [ ! $wifi_networks_done ]
271 272
     do
272
-		data=$(tempfile 2>/dev/null)
273
-		trap "rm -f $data" 0 1 2 5 15
274
-		dialog --backtitle $"Freedombone Configuration" \
275
-			   --title $"Wifi Settings ${wifi_ctr}" \
276
-			   --form $"\nIf you wish to use wifi and have a Free Software compatible adapter (eg. Atheros) rather than wired ethernet then enter the details below, otherwise just select Ok:" 15 55 4 \
277
-			   $"SSID:" 1 1 "$WIFI_SSID" 1 16 30 30 \
278
-			   $"Type:" 2 1 "$WIFI_TYPE" 2 16 10 10 \
279
-			   $"Passphrase:" 3 1 "$WIFI_PASSPHRASE" 3 16 30 30 \
280
-			   2> $data
281
-		sel=$?
282
-		case $sel in
283
-			1) return;;
284
-			255) return;;
285
-		esac
286
-		WIFI_SSID=$(cat $data | sed -n 1p)
287
-		WIFI_TYPE=$(cat $data | sed -n 2p)
288
-		WIFI_PASSPHRASE=$(cat $data | sed -n 3p)
289
-
290
-		# if these fields are empty then there are no more wifi networks
291
-		if [ ${#WIFI_SSID} -lt 2 ]; then
292
-			wifi_networks_done='yes'
293
-			continue
294
-		fi	
295
-		if [ ${#WIFI_TYPE} -lt 2 ]; then
296
-			wifi_networks_done='yes'
297
-			continue
298
-		fi
299
-		
300
-		# update the wifi networks file
301
-		echo '' >> $WIFI_NETWORKS_FILE
302
-		echo "$WIFI_SSID" >> $WIFI_NETWORKS_FILE
303
-		echo "$WIFI_TYPE" >> $WIFI_NETWORKS_FILE
304
-		if [ ${#WIFI_PASSPHRASE} -gt 1 ]; then
305
-			echo "$WIFI_PASSPHRASE" >> $WIFI_NETWORKS_FILE
306
-		fi
307
-		wifi_ctr=$((wifi_ctr + 1))
308
-	done
273
+        data=$(tempfile 2>/dev/null)
274
+        trap "rm -f $data" 0 1 2 5 15
275
+        dialog --backtitle $"Freedombone Configuration" \
276
+               --title $"Wifi Settings ${wifi_ctr}" \
277
+               --form $"\nIf you wish to use wifi and have a Free Software compatible adapter (eg. Atheros) rather than wired ethernet then enter the details below, otherwise just select Ok:" 15 55 4 \
278
+               $"SSID:" 1 1 "$WIFI_SSID" 1 16 30 30 \
279
+               $"Type:" 2 1 "$WIFI_TYPE" 2 16 10 10 \
280
+               $"Passphrase:" 3 1 "$WIFI_PASSPHRASE" 3 16 30 30 \
281
+               2> $data
282
+        sel=$?
283
+        case $sel in
284
+            1) return;;
285
+            255) return;;
286
+        esac
287
+        WIFI_SSID=$(cat $data | sed -n 1p)
288
+        WIFI_TYPE=$(cat $data | sed -n 2p)
289
+        WIFI_PASSPHRASE=$(cat $data | sed -n 3p)
290
+
291
+        # if these fields are empty then there are no more wifi networks
292
+        if [ ${#WIFI_SSID} -lt 2 ]; then
293
+            wifi_networks_done='yes'
294
+            continue
295
+        fi  
296
+        if [ ${#WIFI_TYPE} -lt 2 ]; then
297
+            wifi_networks_done='yes'
298
+            continue
299
+        fi
300
+        
301
+        # update the wifi networks file
302
+        echo '' >> $WIFI_NETWORKS_FILE
303
+        echo "$WIFI_SSID" >> $WIFI_NETWORKS_FILE
304
+        echo "$WIFI_TYPE" >> $WIFI_NETWORKS_FILE
305
+        if [ ${#WIFI_PASSPHRASE} -gt 1 ]; then
306
+            echo "$WIFI_PASSPHRASE" >> $WIFI_NETWORKS_FILE
307
+        fi
308
+        wifi_ctr=$((wifi_ctr + 1))
309
+    done
310
+}
311
+
312
+function disable {
313
+    hotspot_off
314
+    echo '# interfaces(5) file used by ifup(8) and ifdown(8)' > /etc/network/interfaces
315
+    echo '# Include files from /etc/network/interfaces.d:' >> /etc/network/interfaces
316
+    echo 'source-directory /etc/network/interfaces.d' >> /etc/network/interfaces
317
+    systemctl restart network-manager
309 318
 }
310 319
 
311 320
 function show_help {
@@ -322,6 +331,7 @@ function show_help {
322 331
     echo $'     --hotspot [yes|no]            Create a hotspot'
323 332
     echo $'     --networks [filename]         File containing wifi networks'
324 333
     echo $'     --createnetworks [filename]   Create file containing wifi networks'
334
+    echo $'     --disable [yes/no]            Disable wifi'
325 335
     echo ''
326 336
     exit 0
327 337
 }
@@ -360,9 +370,13 @@ do
360 370
             ;;
361 371
         --networksinteractive)
362 372
             shift
363
-			NETWORKS_INTERACTIVE='yes'
373
+            NETWORKS_INTERACTIVE='yes'
364 374
             WIFI_NETWORKS_FILE=${1}
365 375
             ;;
376
+        --disable)
377
+            shift
378
+            WIFI_DISABLE=${1}
379
+            ;;
366 380
         *)
367 381
             # unknown option
368 382
             ;;
@@ -370,47 +384,52 @@ do
370 384
     shift
371 385
 done
372 386
 
387
+if [[ $WIFI_DISABLE == $'yes' || $WIFI_DISABLE == $'y' ]]; then
388
+    disable
389
+    exit 0
390
+fi
391
+
373 392
 if [ $NETWORKS_INTERACTIVE ]; then
374
-	create_networks_interactive
375
-	exit 0
393
+    create_networks_interactive
394
+    exit 0
376 395
 fi
377 396
 
378 397
 if [ -f $WIFI_NETWORKS_FILE ]; then
379
-	networks_from_file
380
-	exit 0
398
+    networks_from_file
399
+    exit 0
381 400
 fi
382 401
 
383 402
 if [ ! $WIFI_SSID ]; then
384
-	echo $'No SSID given'
385
-	exit 1
403
+    echo $'No SSID given'
404
+    exit 1
386 405
 fi
387 406
 
388 407
 if [[ $WIFI_HOTSPOT != 'no' ]]; then
389
-	hotspot_on
390
-	exit 0
408
+    hotspot_on
409
+    exit 0
391 410
 else
392
-	hotspot_off
411
+    hotspot_off
393 412
 fi
394 413
 
395 414
 if [[ $WIFI_TYPE != 'none' ]]; then
396
-	if [ ! $WIFI_PASSPHRASE ]; then
397
-		echo $'No wifi passphrase was given'
398
-		exit 2
399
-	fi
415
+    if [ ! $WIFI_PASSPHRASE ]; then
416
+        echo $'No wifi passphrase was given'
417
+        exit 2
418
+    fi
400 419
 fi
401 420
 
402 421
 if [[ $WIFI_TYPE == 'wpa2-psk' ]]; then
403
-	if [ ! -d /etc/wpa_supplicant ]; then
404
-		echo $'wpasupplicant package is not installed'
405
-		exit 3
406
-	fi
407
-	wifi_wpa2_psk "$WIFI_SSID" "$WIFI_PASSPHRASE"
408
-	exit 0
422
+    if [ ! -d /etc/wpa_supplicant ]; then
423
+        echo $'wpasupplicant package is not installed'
424
+        exit 3
425
+    fi
426
+    wifi_wpa2_psk "$WIFI_SSID" "$WIFI_PASSPHRASE"
427
+    exit 0
409 428
 fi
410 429
 
411 430
 if [[ $WIFI_TYPE == 'none' ]]; then
412
-	wifi_none "$WIFI_SSID"
413
-	exit 0
431
+    wifi_none "$WIFI_SSID"
432
+    exit 0
414 433
 fi
415 434
 
416 435
 exit 0