Bläddra i källkod

Static settings for wifi

Bob Mottram 8 år sedan
förälder
incheckning
6ce080543d
2 ändrade filer med 71 tillägg och 55 borttagningar
  1. 41
    35
      src/freedombone-controlpanel
  2. 30
    20
      src/freedombone-utils-wifi

+ 41
- 35
src/freedombone-controlpanel Visa fil

@@ -1309,41 +1309,47 @@ Enter a static local IP address for this system.\n\nIt will typically be ${IPv4_
1309 1309
             ip_addresses_have_changed=1
1310 1310
         fi
1311 1311
         if [ $ip_addresses_have_changed ]; then
1312
-            echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces
1313
-            echo '# and how to activate them. For more information, see interfaces(5).' >> /etc/network/interfaces
1314
-            echo '' >> /etc/network/interfaces
1315
-            echo '# The loopback network interface' >> /etc/network/interfaces
1316
-            echo 'auto lo' >> /etc/network/interfaces
1317
-            echo 'iface lo inet loopback' >> /etc/network/interfaces
1318
-            echo '' >> /etc/network/interfaces
1319
-            echo '# The primary network interface' >> /etc/network/interfaces
1320
-            echo 'auto eth0' >> /etc/network/interfaces
1321
-            echo 'iface eth0 inet static' >> /etc/network/interfaces
1322
-            echo "    address ${NEW_STATIC_IP}" >> /etc/network/interfaces
1323
-            echo '    netmask 255.255.255.0' >> /etc/network/interfaces
1324
-            echo "    gateway ${NEW_STATIC_GATEWAY}" >> /etc/network/interfaces
1325
-            echo "    dns-nameservers 213.73.91.35 85.214.20.141" >> /etc/network/interfaces
1326
-            echo '# Example to keep MAC address between reboots' >> /etc/network/interfaces
1327
-            echo '#hwaddress ether DE:AD:BE:EF:CA:FE' >> /etc/network/interfaces
1328
-            echo '' >> /etc/network/interfaces
1329
-            echo '# The secondary network interface' >> /etc/network/interfaces
1330
-            echo '#auto eth1' >> /etc/network/interfaces
1331
-            echo '#iface eth1 inet dhcp' >> /etc/network/interfaces
1332
-            echo '' >> /etc/network/interfaces
1333
-            echo '# WiFi Example' >> /etc/network/interfaces
1334
-            echo "#auto $WIFI_INTERFACE" >> /etc/network/interfaces
1335
-            echo "#iface $WIFI_INTERFACE inet dhcp" >> /etc/network/interfaces
1336
-            echo '#    wpa-ssid "essid"' >> /etc/network/interfaces
1337
-            echo '#    wpa-psk  "password"' >> /etc/network/interfaces
1338
-            echo '' >> /etc/network/interfaces
1339
-            echo '# Ethernet/RNDIS gadget (g_ether)' >> /etc/network/interfaces
1340
-            echo '# ... or on host side, usbnet and random hwaddr' >> /etc/network/interfaces
1341
-            echo '# Note on some boards, usb0 is automaticly setup with an init script' >> /etc/network/interfaces
1342
-            echo '#iface usb0 inet static' >> /etc/network/interfaces
1343
-            echo '#    address 192.168.7.2' >> /etc/network/interfaces
1344
-            echo '#    netmask 255.255.255.0' >> /etc/network/interfaces
1345
-            echo '#    network 192.168.7.0' >> /etc/network/interfaces
1346
-            echo '#    gateway 192.168.7.1' >> /etc/network/interfaces
1312
+            write_config_param "NETWORK_IS_STATIC" "1"
1313
+            write_config_param "STATIC_IP_ADDRESS" "$NEW_STATIC_IP"
1314
+            write_config_param "ROUTER_IP_ADDRESS" "$NEW_STATIC_GATEWAY"
1315
+            if [[ $(config_param_exists "WIFI_INTERFACE") == "0" ]]; then
1316
+                # wired network
1317
+                echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces
1318
+                echo '# and how to activate them. For more information, see interfaces(5).' >> /etc/network/interfaces
1319
+                echo '' >> /etc/network/interfaces
1320
+                echo '# The loopback network interface' >> /etc/network/interfaces
1321
+                echo 'auto lo' >> /etc/network/interfaces
1322
+                echo 'iface lo inet loopback' >> /etc/network/interfaces
1323
+                echo '' >> /etc/network/interfaces
1324
+                echo '# The primary network interface' >> /etc/network/interfaces
1325
+                echo 'auto eth0' >> /etc/network/interfaces
1326
+                echo 'iface eth0 inet static' >> /etc/network/interfaces
1327
+                echo "    address ${NEW_STATIC_IP}" >> /etc/network/interfaces
1328
+                echo '    netmask 255.255.255.0' >> /etc/network/interfaces
1329
+                echo "    gateway ${NEW_STATIC_GATEWAY}" >> /etc/network/interfaces
1330
+                echo "    dns-nameservers 213.73.91.35 85.214.20.141" >> /etc/network/interfaces
1331
+                echo '# Example to keep MAC address between reboots' >> /etc/network/interfaces
1332
+                echo '#hwaddress ether DE:AD:BE:EF:CA:FE' >> /etc/network/interfaces
1333
+                echo '' >> /etc/network/interfaces
1334
+                echo '# The secondary network interface' >> /etc/network/interfaces
1335
+                echo '#auto eth1' >> /etc/network/interfaces
1336
+                echo '#iface eth1 inet dhcp' >> /etc/network/interfaces
1337
+                echo '' >> /etc/network/interfaces
1338
+                echo '# WiFi Example' >> /etc/network/interfaces
1339
+                echo "#auto $WIFI_INTERFACE" >> /etc/network/interfaces
1340
+                echo "#iface $WIFI_INTERFACE inet dhcp" >> /etc/network/interfaces
1341
+                echo '#    wpa-ssid "essid"' >> /etc/network/interfaces
1342
+                echo '#    wpa-psk  "password"' >> /etc/network/interfaces
1343
+                echo '' >> /etc/network/interfaces
1344
+                echo '# Ethernet/RNDIS gadget (g_ether)' >> /etc/network/interfaces
1345
+                echo '# ... or on host side, usbnet and random hwaddr' >> /etc/network/interfaces
1346
+                echo '# Note on some boards, usb0 is automaticly setup with an init script' >> /etc/network/interfaces
1347
+                echo '#iface usb0 inet static' >> /etc/network/interfaces
1348
+                echo '#    address 192.168.7.2' >> /etc/network/interfaces
1349
+                echo '#    netmask 255.255.255.0' >> /etc/network/interfaces
1350
+                echo '#    network 192.168.7.0' >> /etc/network/interfaces
1351
+                echo '#    gateway 192.168.7.1' >> /etc/network/interfaces
1352
+            fi
1347 1353
 
1348 1354
             clear
1349 1355
             echo ''

+ 30
- 20
src/freedombone-utils-wifi Visa fil

@@ -48,6 +48,23 @@ function wifi_is_running {
48 48
     fi
49 49
 }
50 50
 
51
+function wifi_static_network_interface {
52
+    NETWORK_IS_STATIC=0
53
+    read_config_param "NETWORK_IS_STATIC"
54
+    if [ ${NETWORK_IS_STATIC} -eq 0 ]; then
55
+        echo '#this line must always be here' >> /etc/network/interfaces
56
+        echo 'iface default inet dhcp' >> /etc/network/interfaces
57
+    else
58
+        read_config_param "STATIC_IP_ADDRESS"
59
+        read_config_param "ROUTER_IP_ADDRESS"
60
+        echo '#static address' >> /etc/network/interfaces
61
+        echo 'iface default inet static' >> /etc/network/interfaces
62
+        echo "    address ${STATIC_IP_ADDRESS}" >> /etc/network/interfaces
63
+        echo '    netmask 255.255.255.0' >> /etc/network/interfaces
64
+        echo "    gateway ${ROUTER_IP_ADDRESS}" >> /etc/network/interfaces
65
+    fi
66
+}
67
+
51 68
 function setup_wifi_atheros {
52 69
     if [[ $(running_as_root) == "0" ]]; then
53 70
         return
@@ -290,15 +307,19 @@ function hotspot_on {
290 307
     systemctl restart hostapd
291 308
 }
292 309
 
293
-function wifi_wpa2_psk {
294
-    ssid=$1
295
-    passphrase=$2
296
-
310
+function wifi_store_original_network_settings {
297 311
     if [ ! -f /etc/network/interfaces_original ]; then
298 312
         if ! grep -q "# wifi enabled" /etc/network/interfaces; then
299 313
             cp /etc/network/interfaces /etc/network/interfaces_original
300 314
         fi
301 315
     fi
316
+}
317
+
318
+function wifi_wpa2_psk {
319
+    ssid=$1
320
+    passphrase=$2
321
+
322
+    wifi_store_original_network_settings
302 323
 
303 324
     echo '# wifi enabled' > /etc/network/interfaces
304 325
     echo 'auto lo' >> /etc/network/interfaces
@@ -311,8 +332,7 @@ function wifi_wpa2_psk {
311 332
     echo "iface ${WIFI_INTERFACE} inet manual" >> /etc/network/interfaces
312 333
     echo "  wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
313 334
     echo '' >> /etc/network/interfaces
314
-    echo '#this line must always be here' >> /etc/network/interfaces
315
-    echo 'iface default inet dhcp' >> /etc/network/interfaces
335
+    wifi_static_network_interface
316 336
 
317 337
     wpa_passphrase "$ssid" "$passphrase" > $WIFI_CONFIG
318 338
 
@@ -323,11 +343,7 @@ function wifi_wpa2_psk {
323 343
 function wifi_none {
324 344
     ssid=$1
325 345
 
326
-    if [ ! -f /etc/network/interfaces_original ]; then
327
-        if ! grep -q "# wifi enabled" /etc/network/interfaces; then
328
-            cp /etc/network/interfaces /etc/network/interfaces_original
329
-        fi
330
-    fi
346
+    wifi_store_original_network_settings
331 347
 
332 348
     echo '# wifi enabled' > /etc/network/interfaces
333 349
     echo 'auto lo' >> /etc/network/interfaces
@@ -340,8 +356,7 @@ function wifi_none {
340 356
     echo "iface ${WIFI_INTERFACE} inet manual" >> /etc/network/interfaces
341 357
     echo "  wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
342 358
     echo '' >> /etc/network/interfaces
343
-    echo '#this line must always be here' >> /etc/network/interfaces
344
-    echo 'iface default inet dhcp' >> /etc/network/interfaces
359
+    wifi_static_network_interface
345 360
 
346 361
     echo 'update_config=1' > $WIFI_CONFIG
347 362
     echo 'eapol_version=1' >> $WIFI_CONFIG
@@ -368,11 +383,7 @@ function networks_from_file {
368 383
     fi
369 384
     read_config_param "WIFI_INTERFACE"
370 385
 
371
-    if [ ! -f /etc/network/interfaces_original ]; then
372
-        if ! grep -q "# wifi enabled" /etc/network/interfaces; then
373
-            cp /etc/network/interfaces /etc/network/interfaces_original
374
-        fi
375
-    fi
386
+    wifi_store_original_network_settings
376 387
 
377 388
     echo '# wifi enabled' > /etc/network/interfaces
378 389
     echo 'auto lo' >> /etc/network/interfaces
@@ -385,8 +396,7 @@ function networks_from_file {
385 396
     echo "iface ${WIFI_INTERFACE} inet manual" >> /etc/network/interfaces
386 397
     echo "  wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
387 398
     echo '' >> /etc/network/interfaces
388
-    echo '#this line must always be here' >> /etc/network/interfaces
389
-    echo 'iface default inet dhcp' >> /etc/network/interfaces
399
+    wifi_static_network_interface
390 400
 
391 401
     # remove wpa_supplicant.conf if it exists
392 402
     if [ -f $WIFI_CONFIG ]; then