From d32ada32b6631f6df15c2d7a6abe972e49cdaf9b Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@robotics.uk.to>
Date: Sun, 30 Oct 2016 11:19:32 +0000
Subject: [PATCH] Setting static IP with wifi

---
 src/freedombone-controlpanel | 25 ++++++++++++++++++-------
 src/freedombone-utils-wifi   | 13 +++++++++++++
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/src/freedombone-controlpanel b/src/freedombone-controlpanel
index f2b5116bc..630ff8600 100755
--- a/src/freedombone-controlpanel
+++ b/src/freedombone-controlpanel
@@ -1203,12 +1203,6 @@ function change_system_name {
 }
 
 function set_dynamic_IP {
-    NETWORK_IS_STATIC=0
-    read_config_param "NETWORK_IS_STATIC"
-    if [ ${NETWORK_IS_STATIC} -eq 0 ]; then
-        return
-    fi
-
     revert_to_dynamic=
     dialog --title $"Return to using a dynamic IP address" \
            --backtitle $"Freedombone Control Panel" \
@@ -1293,8 +1287,22 @@ Enter a static local IP address for this system.\n\nIt will typically be ${IPv4_
 
             email_change_relay "$NEW_STATIC_IP"
 
-            if [[ $(config_param_exists "WIFI_INTERFACE") == "0" ]]; then
+            static_wifi_address=
+            if [[ $(config_param_exists "WIFI_INTERFACE") == "1" ]]; then
+                dialog --title $"Static local IP address" \
+                       --backtitle $"Freedombone Control Panel" \
+                       --yesno $"\nSet a static address for the wifi adapter?\n\nIf you select 'no' then wired ethernet will be used." 10 60
+                sel=$?
+                case $sel in
+                    0) static_wifi_address=1
+                       write_config_param "NETWORK_IS_STATIC" "1"
+                       ;;
+                esac
+            fi
+
+            if [ ! $static_wifi_address ]; then
                 # wired network
+                remove_wifi_startup_script
                 echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces
                 echo '# and how to activate them. For more information, see interfaces(5).' >> /etc/network/interfaces
                 echo '' >> /etc/network/interfaces
@@ -1330,6 +1338,9 @@ Enter a static local IP address for this system.\n\nIt will typically be ${IPv4_
                 echo '#    netmask 255.255.255.0' >> /etc/network/interfaces
                 echo '#    network 192.168.7.0' >> /etc/network/interfaces
                 echo '#    gateway 192.168.7.1' >> /etc/network/interfaces
+            else
+                # wifi network
+                wifi_settings
             fi
 
             clear
diff --git a/src/freedombone-utils-wifi b/src/freedombone-utils-wifi
index 36975a6db..c1f697b07 100755
--- a/src/freedombone-utils-wifi
+++ b/src/freedombone-utils-wifi
@@ -573,6 +573,19 @@ function count_wlan {
     echo $ctr
 }
 
+function remove_wifi_startup_script {
+    remove_config_param "WIFI_INTERFACE"
+    systemd_file=/etc/systemd/system/wifistart.service
+    if [ -f $systemd_file ]; then
+        systemctl stop wifistart
+        systemctl disable wifistart
+        rm $systemd_file
+    fi
+    if [ -f $HOME/${PROJECT_NAME}-wifi.cfg ]; then
+        rm $HOME/${PROJECT_NAME}-wifi.cfg
+    fi
+}
+
 function create_wifi_startup_script {
     systemd_file=/etc/systemd/system/wifistart.service
     echo '[Unit]' > $systemd_file
-- 
GitLab