From d1ac3cddadd486f1103db0a7d5c6a9b9bf0c90cf Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 27 Apr 2016 19:15:11 +0100 Subject: [PATCH] Wifi status --- src/freedombone-controlpanel | 34 ++++++++++++++++++++++++++-------- src/freedombone-wifi | 23 ++++++++++++++--------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/freedombone-controlpanel b/src/freedombone-controlpanel index 09a9bddc..93885eff 100755 --- a/src/freedombone-controlpanel +++ b/src/freedombone-controlpanel @@ -1685,6 +1685,10 @@ Enter a static local IP address for this system.\n\nIt will typically be 192.168 } function wifi_settings { + if [ -f /etc/hostapd/hostapd.conf ]; then + return + fi + TEMP_WIFI_NETWORKS_FILE=~/.temp-${PROJECT_NAME}-wifi.cfg ${PROJECT_NAME}-wifi --networksinteractive $TEMP_WIFI_NETWORKS_FILE if [ -f $TEMP_WIFI_NETWORKS_FILE ]; then @@ -1696,6 +1700,16 @@ function wifi_settings { fi } +function wifi_edit_networks { + if [ -f /etc/hostapd/hostapd.conf ]; then + return + fi + editor $WIFI_NETWORKS_FILE + if [ -f $WIFI_NETWORKS_FILE ]; then + ${PROJECT_NAME}-wifi --networks $WIFI_NETWORKS_FILE + fi +} + function hotspot_settings { data=$(tempfile 2>/dev/null) trap "rm -f $data" 0 1 2 5 15 @@ -1947,19 +1961,23 @@ function wifi_enable { ${PROJECT_NAME}-wifi --disable $disable_wifi } -function menu_wifi { - hotspot_state=$'off' - if [ -f /etc/hostapd/hostapd.conf ]; then - hotspot_state=$'on' - fi - +function menu_wifi { while true do + status_str=$'Wifi OFF' + if [ -f /etc/hostapd/hostapd.conf ]; then + status_str=$'Hotspot ON' + else + if grep -q "# wifi enabled" /etc/network/interfaces; then + status_str=$'Wifi ON' + fi + fi + data=$(tempfile 2>/dev/null) trap "rm -f $data" 0 1 2 5 15 dialog --backtitle $"Freedombone Control Panel" \ --title $"Wifi Menu" \ - --radiolist $"Choose an operation:" 13 70 5 \ + --radiolist $"${status_str}\n\nChoose an operation:" 14 70 6 \ 1 $"Enable or disable Wifi" off \ 2 $"Configure wifi networks" off \ 3 $"Manually edit wifi networks file" off \ @@ -1973,7 +1991,7 @@ function menu_wifi { case $(cat $data) in 1) wifi_enable;; 2) wifi_settings;; - 3) editor $WIFI_NETWORKS_FILE;; + 3) wifi_edit_networks;; 4) hotspot_settings;; 5) break;; esac diff --git a/src/freedombone-wifi b/src/freedombone-wifi index 47b280ca..4f7e010f 100755 --- a/src/freedombone-wifi +++ b/src/freedombone-wifi @@ -310,15 +310,15 @@ function create_networks_interactive { } function disable_wifi { - if [[ ${1} == 'yes' || ${1} == 'y' ]]; then - hotspot_off - echo '# interfaces(5) file used by ifup(8) and ifdown(8)' > /etc/network/interfaces - echo '# Include files from /etc/network/interfaces.d:' >> /etc/network/interfaces - echo 'source-directory /etc/network/interfaces.d' >> /etc/network/interfaces - systemctl restart network-manager - else - networks_from_file - fi + if [[ ${1} == 'yes' || ${1} == 'y' ]]; then + hotspot_off + echo '# interfaces(5) file used by ifup(8) and ifdown(8)' > /etc/network/interfaces + echo '# Include files from /etc/network/interfaces.d:' >> /etc/network/interfaces + echo 'source-directory /etc/network/interfaces.d' >> /etc/network/interfaces + systemctl restart network-manager + else + networks_from_file + fi } function show_help { @@ -380,6 +380,11 @@ do --disable) shift WIFI_DISABLE=${1} + if [[ $WIFI_DISABLE == $'yes' || $WIFI_DISABLE == $'y' ]]; then + WIFI_DISABLE='yes' + else + WIFI_DISABLE='no' + fi ;; *) # unknown option