From 6dea0a87ff8439819fdc7d1578236959a9913304 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 22 Oct 2016 15:43:15 +0100 Subject: [PATCH] Daemon to start wifi --- src/freedombone-controlpanel | 5 ++++- src/freedombone-image-customise | 17 ++++++++++++++++- src/freedombone-utils-final | 11 ++++++----- src/freedombone-utils-wifi | 30 ++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/freedombone-controlpanel b/src/freedombone-controlpanel index dae6c171..bdd675dd 100755 --- a/src/freedombone-controlpanel +++ b/src/freedombone-controlpanel @@ -1384,13 +1384,16 @@ function wifi_settings { cp $TEMP_WIFI_NETWORKS_FILE $WIFI_NETWORKS_FILE rm $TEMP_WIFI_NETWORKS_FILE ${PROJECT_NAME}-wifi --networks $WIFI_NETWORKS_FILE + create_wifi_startup_script if [[ $(wifi_is_running) == "1" ]]; then dialog --title $"Wifi Settings" \ --msgbox $"Wifi settings were changed." 6 60 else dialog --title $"Wifi Settings" \ - --msgbox $"Wifi settings were changed. You will need to restart the system for the changes to take effect." 6 60 + --msgbox $"Wifi settings were changed. You will need to restart the system with ethernet cable removed for the changes to take effect." 7 60 fi + else + remove_wifi_startup_script fi } diff --git a/src/freedombone-image-customise b/src/freedombone-image-customise index 85cd58f2..f42382d2 100755 --- a/src/freedombone-image-customise +++ b/src/freedombone-image-customise @@ -409,7 +409,22 @@ EOF END_MESSAGE_HEIGHT=12 fi echo " if [ -f /root/${PROJECT_NAME}-wifi.cfg ]; then" >> $rootdir/root/.bashrc - echo " ${PROJECT_NAME}-wifi" >> $rootdir/root/.bashrc + echo " echo '[Unit]' > /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " echo 'Description=WifiStartup (Start wifi networking)' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " echo 'After=syslog.target' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " echo 'After=network.target' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " echo '' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " echo '[Service]' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " echo 'Type=simple' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " echo 'User=root' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " echo 'Group=root' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " echo 'WorkingDirectory=/root' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " echo 'ExecStart=/usr/local/bin/freedombone-wifi' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " echo '' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " echo '[Install]' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " echo 'WantedBy=multi-user.target' >> /etc/systemd/system/wifistart.service" >> $rootdir/root/.bashrc + echo " systemctl enable wifistart" >> $rootdir/root/.bashrc + echo " systemctl daemon-reload" >> $rootdir/root/.bashrc echo ' fi' >> $rootdir/root/.bashrc echo " dialog --title '$END_MESSAGE1' --msgbox \"$END_MESSAGE2\" ${END_MESSAGE_HEIGHT} 60" >> $rootdir/root/.bashrc echo ' reboot' >> $rootdir/root/.bashrc diff --git a/src/freedombone-utils-final b/src/freedombone-utils-final index aaf25a70..2fa2d565 100755 --- a/src/freedombone-utils-final +++ b/src/freedombone-utils-final @@ -44,9 +44,9 @@ function install_final { echo '' echo $" - *** ${PROJECT_NAME} installation is complete. Rebooting... *** + *** ${PROJECT_NAME} installation is complete *** - Ensure that these ports are forwarded from your internet router + Ensure that ports are forwarded from your internet router " echo '' @@ -60,9 +60,10 @@ function install_final { fi if [ ! -f $IMAGE_PASSWORD_FILE ]; then if [ -f /root/${PROJECT_NAME}-wifi.cfg ]; then - if [[ $(wifi_is_running) == "0" ]]; then - ${PROJECT_NAME}-wifi - fi + create_wifi_startup_script + echo $'Shutting down the system. Detatch the ethernet cable, then power on again.' + shutdown now + return fi reboot fi diff --git a/src/freedombone-utils-wifi b/src/freedombone-utils-wifi index 0ceba8e8..56ccb10c 100755 --- a/src/freedombone-utils-wifi +++ b/src/freedombone-utils-wifi @@ -549,4 +549,34 @@ function count_wlan { echo $ctr } +function create_wifi_startup_script { + systemd_file=/etc/systemd/system/wifistart.service + echo '[Unit]' > $systemd_file + echo 'Description=WifiStartup (Start wifi networking)' >> $systemd_file + echo 'After=syslog.target' >> $systemd_file + echo 'After=network.target' >> $systemd_file + echo '' >> $systemd_file + echo '[Service]' >> $systemd_file + echo 'Type=simple' >> $systemd_file + echo 'User=root' >> $systemd_file + echo 'Group=root' >> $systemd_file + echo 'WorkingDirectory=/root' >> $systemd_file + echo "ExecStart=/usr/local/bin/${PROJECT_NAME}-wifi" >> $systemd_file + echo '' >> $systemd_file + echo '[Install]' >> $systemd_file + echo 'WantedBy=multi-user.target' >> $systemd_file + + systemctl enable wifistart + systemctl daemon-reload +} + +function remove_wifi_startup_script { + systemd_file=/etc/systemd/system/wifistart.service + if [ -f $systemd_file ]; then + systemctl disable wifistart + systemctl daemon-reload + rm $systemd_file + fi +} + # NOTE: deliberately no exit 0