From d98d173e31542533528f667035db5928e9193e07 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Sat, 19 Nov 2016 11:03:37 -0500 Subject: [PATCH 01/23] stop overwriting hostapd.conf on update For some reason, this line was added and it caused the hostapd.conf(but not hostapd-edimax.conf) to be replaced at each update. This caused the users custom SSID and channel settings to be replaced!! --- selfupdate/makeupdate.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/selfupdate/makeupdate.sh b/selfupdate/makeupdate.sh index 64c01b25..eb316864 100755 --- a/selfupdate/makeupdate.sh +++ b/selfupdate/makeupdate.sh @@ -22,7 +22,6 @@ cp __lib__systemd__system__stratux.service work/bin/ cp __root__stratux-pre-start.sh work/bin/ cp dump1090/dump1090 work/bin/ cp -r web work/bin/ -cp image/hostapd.conf work/bin/ cp image/config.txt work/bin/ cp image/rtl-sdr-blacklist.conf work/bin/ cp image/bashrc.txt work/bin/ From 948993323374ec941a48cba4d259ed17a8486d19 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 15:50:32 -0500 Subject: [PATCH 02/23] removed user configurable values removed user configurable values to be placed in a global hosapd file --- image/hostapd.conf | 2 -- 1 file changed, 2 deletions(-) diff --git a/image/hostapd.conf b/image/hostapd.conf index ca3c19f0..10909401 100644 --- a/image/hostapd.conf +++ b/image/hostapd.conf @@ -1,7 +1,5 @@ interface=wlan0 -ssid=stratux hw_mode=g -channel=1 wmm_enabled=1 ieee80211n=1 ignore_broadcast_ssid=0 From 11f513c1dad2764ce27be94d6526251fe0e32437 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 15:50:55 -0500 Subject: [PATCH 03/23] removed user configurable values --- image/hostapd-edimax.conf | 2 -- 1 file changed, 2 deletions(-) diff --git a/image/hostapd-edimax.conf b/image/hostapd-edimax.conf index f1e7552f..19f599a0 100644 --- a/image/hostapd-edimax.conf +++ b/image/hostapd-edimax.conf @@ -1,8 +1,6 @@ interface=wlan0 driver=rtl871xdrv -ssid=stratux hw_mode=g -channel=1 wme_enabled=1 ieee80211n=1 ignore_broadcast_ssid=0 From 3cca4ba525ee364985a22722f782cac5c46a7f8d Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 15:52:44 -0500 Subject: [PATCH 04/23] loading user config settings update the file to create a tmp file that adds all the user config valuse to the hostapd.conf and uses the new /tmp/hostapd.conf to run the hostapd deamon --- image/stratux-wifi.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/image/stratux-wifi.sh b/image/stratux-wifi.sh index 55e6a87a..ea415788 100755 --- a/image/stratux-wifi.sh +++ b/image/stratux-wifi.sh @@ -8,21 +8,32 @@ # Detect RPi version. # Per http://elinux.org/RPi_HardwareHistory - +#Assume PI3 settings DAEMON_CONF=/etc/hostapd/hostapd.conf DAEMON_SBIN=/usr/sbin/hostapd + +#User settings for hostapd.conf and hostapd-edimax.conf +DAEMON_USER_PREF=/etc/hostapd/hostapd.user + +DAEMON_TMP=/tmp/hostapd.conf + EW7811Un=$(lsusb | grep EW-7811Un) RPI_REV=`cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//'` if [ "$RPI_REV" = "a01041" ] || [ "$RPI_REV" = "a21041" ] || [ "$RPI_REV" = "900092" ] || [ "$RPI_REV" = "900093" ] && [ "$EW7811Un" != '' ]; then # This is a RPi2B or RPi0 with Edimax USB Wifi dongle. DAEMON_CONF=/etc/hostapd/hostapd-edimax.conf - DAEMON_SBIN=/usr/sbin/hostapd-edimax -else - DAEMON_CONF=/etc/hostapd/hostapd.conf + DAEMON_SBIN=/etc/hostapd/hostapd-edimax +# else +# DAEMON_CONF=/etc/hostapd/hostapd.conf fi +#Make a new hostapd or hostapd-edimax conf file based on logic above +cp -f ${DAEMON_CONF} ${DAEMON_TMP} -${DAEMON_SBIN} -B ${DAEMON_CONF} +#inject user settings from file to tmp conf +cat ${DAEMON_USER_PREF} >> ${DAEMON_TMP} + +${DAEMON_SBIN} -B ${DAEMON_TMP} sleep 5 From c0a945bb8804cb75a9d539fbbf2754b138f75997 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 15:54:49 -0500 Subject: [PATCH 05/23] edits hostapd.user this file now edits hostapd.user to change user configurable values for hostapd --- image/hostapd_manager.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image/hostapd_manager.sh b/image/hostapd_manager.sh index 13963310..d48c5ce3 100644 --- a/image/hostapd_manager.sh +++ b/image/hostapd_manager.sh @@ -161,7 +161,7 @@ echo "${BOLD}No errors found. Continuning...${NORMAL}" echo "" # files to edit -HOSTAPD=('/etc/hostapd/hostapd.conf' '/etc/hostapd/hostapd-edimax.conf') +HOSTAPD=('/etc/hostapd/hostapd.user') #### #### File modification loop From 3ad982e1c0d4b912380d31554b191199f9b33113 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 16:13:35 -0500 Subject: [PATCH 06/23] copy both hostapd.comf and hostapd-edimax.conf this is now able because we moved the user configurable options away from the package files and build a temp hostapd.conf on the fly. see https://github.com/cyoung/stratux/blob/master/image/stratux-wifi.sh --- selfupdate/makeupdate.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/selfupdate/makeupdate.sh b/selfupdate/makeupdate.sh index eb316864..aac2f469 100755 --- a/selfupdate/makeupdate.sh +++ b/selfupdate/makeupdate.sh @@ -22,6 +22,8 @@ cp __lib__systemd__system__stratux.service work/bin/ cp __root__stratux-pre-start.sh work/bin/ cp dump1090/dump1090 work/bin/ cp -r web work/bin/ +cp image/hostapd.conf work/bin/ +cp image/hostapd-edimax.conf work/bin/ cp image/config.txt work/bin/ cp image/rtl-sdr-blacklist.conf work/bin/ cp image/bashrc.txt work/bin/ From 4a1ce917a33a0828e93ddccf522cec81bc9d7a38 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 16:37:19 -0500 Subject: [PATCH 07/23] update comments --- image/stratux-wifi.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/image/stratux-wifi.sh b/image/stratux-wifi.sh index ea415788..ba750bda 100755 --- a/image/stratux-wifi.sh +++ b/image/stratux-wifi.sh @@ -15,16 +15,16 @@ DAEMON_SBIN=/usr/sbin/hostapd #User settings for hostapd.conf and hostapd-edimax.conf DAEMON_USER_PREF=/etc/hostapd/hostapd.user +#temp hostapd.conf DAEMON_TMP=/tmp/hostapd.conf +#check for pi2 and change files EW7811Un=$(lsusb | grep EW-7811Un) RPI_REV=`cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//'` if [ "$RPI_REV" = "a01041" ] || [ "$RPI_REV" = "a21041" ] || [ "$RPI_REV" = "900092" ] || [ "$RPI_REV" = "900093" ] && [ "$EW7811Un" != '' ]; then # This is a RPi2B or RPi0 with Edimax USB Wifi dongle. DAEMON_CONF=/etc/hostapd/hostapd-edimax.conf DAEMON_SBIN=/etc/hostapd/hostapd-edimax -# else -# DAEMON_CONF=/etc/hostapd/hostapd.conf fi #Make a new hostapd or hostapd-edimax conf file based on logic above @@ -33,6 +33,7 @@ cp -f ${DAEMON_CONF} ${DAEMON_TMP} #inject user settings from file to tmp conf cat ${DAEMON_USER_PREF} >> ${DAEMON_TMP} +#start the daemon with the temp file ${DAEMON_SBIN} -B ${DAEMON_TMP} sleep 5 From 31dc1a14fd5047d8f394fa2bbe47140e35451f0a Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 17:01:28 -0500 Subject: [PATCH 08/23] user configurable hostapd values this is where the user valies are stored and used to build /tmp/hostapd.conf --- image/hostapd.user | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 image/hostapd.user diff --git a/image/hostapd.user b/image/hostapd.user new file mode 100644 index 00000000..c8a8d28d --- /dev/null +++ b/image/hostapd.user @@ -0,0 +1,2 @@ +ssid=stratux +channel=1 From d2c50f09218aca486712245a839d41e4f2e89279 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 17:03:24 -0500 Subject: [PATCH 09/23] Delete hostapd.user --- image/hostapd.user | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 image/hostapd.user diff --git a/image/hostapd.user b/image/hostapd.user deleted file mode 100644 index c8a8d28d..00000000 --- a/image/hostapd.user +++ /dev/null @@ -1,2 +0,0 @@ -ssid=stratux -channel=1 From 454da41fd21ef78acafac2606f909de476ed0d77 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 17:25:21 -0500 Subject: [PATCH 10/23] Update stratux-wifi.sh --- image/stratux-wifi.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/image/stratux-wifi.sh b/image/stratux-wifi.sh index ba750bda..bb87cf2c 100755 --- a/image/stratux-wifi.sh +++ b/image/stratux-wifi.sh @@ -5,9 +5,6 @@ /usr/bin/killall -9 hostapd hostapd-edimax /usr/sbin/service isc-dhcp-server stop - -# Detect RPi version. -# Per http://elinux.org/RPi_HardwareHistory #Assume PI3 settings DAEMON_CONF=/etc/hostapd/hostapd.conf DAEMON_SBIN=/usr/sbin/hostapd @@ -18,7 +15,8 @@ DAEMON_USER_PREF=/etc/hostapd/hostapd.user #temp hostapd.conf DAEMON_TMP=/tmp/hostapd.conf -#check for pi2 and change files +# Detect RPi version. +# Per http://elinux.org/RPi_HardwareHistory EW7811Un=$(lsusb | grep EW-7811Un) RPI_REV=`cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//'` if [ "$RPI_REV" = "a01041" ] || [ "$RPI_REV" = "a21041" ] || [ "$RPI_REV" = "900092" ] || [ "$RPI_REV" = "900093" ] && [ "$EW7811Un" != '' ]; then From 226b8442f74b9f562f83b523d2908a3a46918476 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 19:22:18 -0500 Subject: [PATCH 11/23] Check for and handle hostapd.user This script now not only starts hostapd using the proper driver(standard/edimax). It now checks for the existance of the hostapd.user file and if found uses it. if not found creates it with the values from the existing hostapd.conf I choose to only carry over the values from the hostaod.conf and not the edimax because they should be the same. If there is no user configurable values in hostapd.conf and no hostapd.user file then a default hostapd.user file is created. --- image/stratux-wifi.sh | 45 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/image/stratux-wifi.sh b/image/stratux-wifi.sh index bb87cf2c..cc8e7c13 100755 --- a/image/stratux-wifi.sh +++ b/image/stratux-wifi.sh @@ -1,6 +1,5 @@ #!/bin/bash - # Preliminaries. Kill off old services. /usr/bin/killall -9 hostapd hostapd-edimax /usr/sbin/service isc-dhcp-server stop @@ -9,12 +8,51 @@ DAEMON_CONF=/etc/hostapd/hostapd.conf DAEMON_SBIN=/usr/sbin/hostapd +DAEMON_CONF_EDIMAX=/etc/hostapd/hostapd-edimax.conf + #User settings for hostapd.conf and hostapd-edimax.conf DAEMON_USER_PREF=/etc/hostapd/hostapd.user -#temp hostapd.conf DAEMON_TMP=/tmp/hostapd.conf +# values to move +HOSTAPD_VALUES=('ssid=' 'channel=' 'auth_algs=' 'wpa=' 'wpa_passphrase=' 'wpa_key_mgmt=' 'wpa_pairwise=' 'rsn_pairwise=') + +#values to remove +HOSTAPD_VALUES_RM=('#auth_algs=' '#wpa=' '#wpa_passphrase=' '#wpa_key_mgmt=' '#wpa_pairwise=' '#rsn_pairwise=') + + +# This code checks for the existence of ostapd.user and if it exists it leaves it alone. +# If the file does not exist it copys over the values from the existing hostapd.conf to hostapd.user and removes them +# check for hostapd.user and if needed create properly +if [ ! -f $DAEMON_USER_PREF ]; then +# move any custom values + for i in "${HOSTAPD_VALUES[@]}" + do + if grep -q "^$i" $DAEMON_CONF + then + grep "^$i" $DAEMON_CONF >> $DAEMON_USER_PREF + echo "deleting lines..." + sed -i '/^'"$i"'/d' $DAEMON_CONF + sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX + fi + done +# just remove commented values + for i in "${HOSTAPD_VALUES_RM[@]}" + do + if grep -q "^$i" $DAEMON_CONF + then + sed -i '/^'"$i"'/d' $DAEMON_CONF + sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX + fi + done +fi + +# If once the code above runs and there is still no hostapd.user file then something is wrong and we will just create the file with basic settings. +#Any more then this they somebody was messing with things and its not our fault things are this bad +if [ ! -f $DAEMON_USER_PREF ]; then + echo $"ssid=stratux\nchannel=1\n" >> $DAEMON_USER_PREF +fi # Detect RPi version. # Per http://elinux.org/RPi_HardwareHistory EW7811Un=$(lsusb | grep EW-7811Un) @@ -23,6 +61,8 @@ if [ "$RPI_REV" = "a01041" ] || [ "$RPI_REV" = "a21041" ] || [ "$RPI_REV" = "900 # This is a RPi2B or RPi0 with Edimax USB Wifi dongle. DAEMON_CONF=/etc/hostapd/hostapd-edimax.conf DAEMON_SBIN=/etc/hostapd/hostapd-edimax +# else +# DAEMON_CONF=/etc/hostapd/hostapd.conf fi #Make a new hostapd or hostapd-edimax conf file based on logic above @@ -31,7 +71,6 @@ cp -f ${DAEMON_CONF} ${DAEMON_TMP} #inject user settings from file to tmp conf cat ${DAEMON_USER_PREF} >> ${DAEMON_TMP} -#start the daemon with the temp file ${DAEMON_SBIN} -B ${DAEMON_TMP} sleep 5 From 94da60ed06475e45e1270e5c6c4ea7652d3e975a Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 19:35:36 -0500 Subject: [PATCH 12/23] formatting --- image/stratux-wifi.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/image/stratux-wifi.sh b/image/stratux-wifi.sh index cc8e7c13..994da9b4 100755 --- a/image/stratux-wifi.sh +++ b/image/stratux-wifi.sh @@ -32,9 +32,8 @@ if [ ! -f $DAEMON_USER_PREF ]; then if grep -q "^$i" $DAEMON_CONF then grep "^$i" $DAEMON_CONF >> $DAEMON_USER_PREF - echo "deleting lines..." sed -i '/^'"$i"'/d' $DAEMON_CONF - sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX + sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX fi done # just remove commented values @@ -43,7 +42,7 @@ if [ ! -f $DAEMON_USER_PREF ]; then if grep -q "^$i" $DAEMON_CONF then sed -i '/^'"$i"'/d' $DAEMON_CONF - sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX + sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX fi done fi From 7b104be3dc7c0f033ce7ebcce3a8ebf1957596c3 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 20:37:19 -0500 Subject: [PATCH 13/23] formatting --- image/stratux-wifi.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image/stratux-wifi.sh b/image/stratux-wifi.sh index 994da9b4..8a749313 100755 --- a/image/stratux-wifi.sh +++ b/image/stratux-wifi.sh @@ -50,7 +50,7 @@ fi # If once the code above runs and there is still no hostapd.user file then something is wrong and we will just create the file with basic settings. #Any more then this they somebody was messing with things and its not our fault things are this bad if [ ! -f $DAEMON_USER_PREF ]; then - echo $"ssid=stratux\nchannel=1\n" >> $DAEMON_USER_PREF + echo $"ssid=stratux\nchannel=1" >> $DAEMON_USER_PREF fi # Detect RPi version. # Per http://elinux.org/RPi_HardwareHistory From e3e7fd7aab7a50cd33229bf8ff63f44206851c8b Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 21:20:42 -0500 Subject: [PATCH 14/23] logic reorder --- image/stratux-wifi.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/image/stratux-wifi.sh b/image/stratux-wifi.sh index 8a749313..69b75f88 100755 --- a/image/stratux-wifi.sh +++ b/image/stratux-wifi.sh @@ -45,13 +45,14 @@ if [ ! -f $DAEMON_USER_PREF ]; then sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX fi done + # If once the code above runs and there is still no hostapd.user file then something is wrong and we will just create the file with basic settings. + #Any more then this they somebody was messing with things and its not our fault things are this bad + if [ ! -f $DAEMON_USER_PREF ]; then + echo "ssid=stratux" >> $DAEMON_USER_PREF + echo "channel=1" >> $DAEMON_USER_PREF + fi fi -# If once the code above runs and there is still no hostapd.user file then something is wrong and we will just create the file with basic settings. -#Any more then this they somebody was messing with things and its not our fault things are this bad -if [ ! -f $DAEMON_USER_PREF ]; then - echo $"ssid=stratux\nchannel=1" >> $DAEMON_USER_PREF -fi # Detect RPi version. # Per http://elinux.org/RPi_HardwareHistory EW7811Un=$(lsusb | grep EW-7811Un) From 27db95f749a88357d2515d0fcbb048e9e205be09 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 22:09:35 -0500 Subject: [PATCH 15/23] hopefully better speed --- image/stratux-wifi.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/image/stratux-wifi.sh b/image/stratux-wifi.sh index 69b75f88..f1b6738e 100755 --- a/image/stratux-wifi.sh +++ b/image/stratux-wifi.sh @@ -8,24 +8,22 @@ DAEMON_CONF=/etc/hostapd/hostapd.conf DAEMON_SBIN=/usr/sbin/hostapd -DAEMON_CONF_EDIMAX=/etc/hostapd/hostapd-edimax.conf - #User settings for hostapd.conf and hostapd-edimax.conf DAEMON_USER_PREF=/etc/hostapd/hostapd.user DAEMON_TMP=/tmp/hostapd.conf -# values to move -HOSTAPD_VALUES=('ssid=' 'channel=' 'auth_algs=' 'wpa=' 'wpa_passphrase=' 'wpa_key_mgmt=' 'wpa_pairwise=' 'rsn_pairwise=') - -#values to remove -HOSTAPD_VALUES_RM=('#auth_algs=' '#wpa=' '#wpa_passphrase=' '#wpa_key_mgmt=' '#wpa_pairwise=' '#rsn_pairwise=') - - # This code checks for the existence of ostapd.user and if it exists it leaves it alone. # If the file does not exist it copys over the values from the existing hostapd.conf to hostapd.user and removes them # check for hostapd.user and if needed create properly if [ ! -f $DAEMON_USER_PREF ]; then +# values to move +HOSTAPD_VALUES=('ssid=' 'channel=' 'auth_algs=' 'wpa=' 'wpa_passphrase=' 'wpa_key_mgmt=' 'wpa_pairwise=' 'rsn_pairwise=') +#values to remove +HOSTAPD_VALUES_RM=('#auth_algs=' '#wpa=' '#wpa_passphrase=' '#wpa_key_mgmt=' '#wpa_pairwise=' '#rsn_pairwise=') + +DAEMON_CONF_EDIMAX=/etc/hostapd/hostapd-edimax.conf + # move any custom values for i in "${HOSTAPD_VALUES[@]}" do From 18b0bf53ef27d2a51fd00dd9ae91cad460aa3ae8 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 23:31:03 -0500 Subject: [PATCH 16/23] clean up --- image/stratux-wifi.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/image/stratux-wifi.sh b/image/stratux-wifi.sh index f1b6738e..9c52d1ed 100755 --- a/image/stratux-wifi.sh +++ b/image/stratux-wifi.sh @@ -59,8 +59,6 @@ if [ "$RPI_REV" = "a01041" ] || [ "$RPI_REV" = "a21041" ] || [ "$RPI_REV" = "900 # This is a RPi2B or RPi0 with Edimax USB Wifi dongle. DAEMON_CONF=/etc/hostapd/hostapd-edimax.conf DAEMON_SBIN=/etc/hostapd/hostapd-edimax -# else -# DAEMON_CONF=/etc/hostapd/hostapd.conf fi #Make a new hostapd or hostapd-edimax conf file based on logic above From 6c5352e3a1cc533cef3e5a633365baab22709f2f Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 23:35:14 -0500 Subject: [PATCH 17/23] clean up code --- image/stratux-wifi.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/image/stratux-wifi.sh b/image/stratux-wifi.sh index 9c52d1ed..69490daa 100755 --- a/image/stratux-wifi.sh +++ b/image/stratux-wifi.sh @@ -17,14 +17,14 @@ DAEMON_TMP=/tmp/hostapd.conf # If the file does not exist it copys over the values from the existing hostapd.conf to hostapd.user and removes them # check for hostapd.user and if needed create properly if [ ! -f $DAEMON_USER_PREF ]; then -# values to move -HOSTAPD_VALUES=('ssid=' 'channel=' 'auth_algs=' 'wpa=' 'wpa_passphrase=' 'wpa_key_mgmt=' 'wpa_pairwise=' 'rsn_pairwise=') -#values to remove -HOSTAPD_VALUES_RM=('#auth_algs=' '#wpa=' '#wpa_passphrase=' '#wpa_key_mgmt=' '#wpa_pairwise=' '#rsn_pairwise=') + # values to move + HOSTAPD_VALUES=('ssid=' 'channel=' 'auth_algs=' 'wpa=' 'wpa_passphrase=' 'wpa_key_mgmt=' 'wpa_pairwise=' 'rsn_pairwise=') + #values to remove + HOSTAPD_VALUES_RM=('#auth_algs=' '#wpa=' '#wpa_passphrase=' '#wpa_key_mgmt=' '#wpa_pairwise=' '#rsn_pairwise=') -DAEMON_CONF_EDIMAX=/etc/hostapd/hostapd-edimax.conf + DAEMON_CONF_EDIMAX=/etc/hostapd/hostapd-edimax.conf -# move any custom values + # move any custom values for i in "${HOSTAPD_VALUES[@]}" do if grep -q "^$i" $DAEMON_CONF From 2ef42ea8d0f8fdbce0a071d86e8a1fff65c433a8 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Wed, 23 Nov 2016 23:51:18 -0500 Subject: [PATCH 18/23] add sleep add sleep to make sure the file write has time to finish before checking for the file --- image/stratux-wifi.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/image/stratux-wifi.sh b/image/stratux-wifi.sh index 69490daa..af35455b 100755 --- a/image/stratux-wifi.sh +++ b/image/stratux-wifi.sh @@ -43,6 +43,10 @@ if [ ! -f $DAEMON_USER_PREF ]; then sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX fi done + + #make sure there is time to get the file written before checking for it again + sleep 1 + # If once the code above runs and there is still no hostapd.user file then something is wrong and we will just create the file with basic settings. #Any more then this they somebody was messing with things and its not our fault things are this bad if [ ! -f $DAEMON_USER_PREF ]; then @@ -69,6 +73,6 @@ cat ${DAEMON_USER_PREF} >> ${DAEMON_TMP} ${DAEMON_SBIN} -B ${DAEMON_TMP} -sleep 5 +sleep 3 /usr/sbin/service isc-dhcp-server start From 737df68e4621582c42d168c28c742124776c5529 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Thu, 24 Nov 2016 00:00:52 -0500 Subject: [PATCH 19/23] clean up --- image/stratux-wifi.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/image/stratux-wifi.sh b/image/stratux-wifi.sh index af35455b..cb646286 100755 --- a/image/stratux-wifi.sh +++ b/image/stratux-wifi.sh @@ -27,20 +27,20 @@ if [ ! -f $DAEMON_USER_PREF ]; then # move any custom values for i in "${HOSTAPD_VALUES[@]}" do - if grep -q "^$i" $DAEMON_CONF + if grep -q "^$i" $DAEMON_CONF then - grep "^$i" $DAEMON_CONF >> $DAEMON_USER_PREF - sed -i '/^'"$i"'/d' $DAEMON_CONF - sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX + grep "^$i" $DAEMON_CONF >> $DAEMON_USER_PREF + sed -i '/^'"$i"'/d' $DAEMON_CONF + sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX fi done # just remove commented values for i in "${HOSTAPD_VALUES_RM[@]}" do - if grep -q "^$i" $DAEMON_CONF + if grep -q "^$i" $DAEMON_CONF then - sed -i '/^'"$i"'/d' $DAEMON_CONF - sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX + sed -i '/^'"$i"'/d' $DAEMON_CONF + sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX fi done From 469a413bb325f58c8796b1e18d20c4b68aa205ac Mon Sep 17 00:00:00 2001 From: peepsnet Date: Thu, 24 Nov 2016 10:41:50 -0500 Subject: [PATCH 20/23] Change is logic placement I removes all my code from this file and moved to stratux-pre-start.sh. This seems like a logical place to monkey around with stuff that must be ready for the start of stratux. --- image/stratux-wifi.sh | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/image/stratux-wifi.sh b/image/stratux-wifi.sh index cb646286..6211dbc9 100755 --- a/image/stratux-wifi.sh +++ b/image/stratux-wifi.sh @@ -13,48 +13,6 @@ DAEMON_USER_PREF=/etc/hostapd/hostapd.user DAEMON_TMP=/tmp/hostapd.conf -# This code checks for the existence of ostapd.user and if it exists it leaves it alone. -# If the file does not exist it copys over the values from the existing hostapd.conf to hostapd.user and removes them -# check for hostapd.user and if needed create properly -if [ ! -f $DAEMON_USER_PREF ]; then - # values to move - HOSTAPD_VALUES=('ssid=' 'channel=' 'auth_algs=' 'wpa=' 'wpa_passphrase=' 'wpa_key_mgmt=' 'wpa_pairwise=' 'rsn_pairwise=') - #values to remove - HOSTAPD_VALUES_RM=('#auth_algs=' '#wpa=' '#wpa_passphrase=' '#wpa_key_mgmt=' '#wpa_pairwise=' '#rsn_pairwise=') - - DAEMON_CONF_EDIMAX=/etc/hostapd/hostapd-edimax.conf - - # move any custom values - for i in "${HOSTAPD_VALUES[@]}" - do - if grep -q "^$i" $DAEMON_CONF - then - grep "^$i" $DAEMON_CONF >> $DAEMON_USER_PREF - sed -i '/^'"$i"'/d' $DAEMON_CONF - sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX - fi - done -# just remove commented values - for i in "${HOSTAPD_VALUES_RM[@]}" - do - if grep -q "^$i" $DAEMON_CONF - then - sed -i '/^'"$i"'/d' $DAEMON_CONF - sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX - fi - done - - #make sure there is time to get the file written before checking for it again - sleep 1 - - # If once the code above runs and there is still no hostapd.user file then something is wrong and we will just create the file with basic settings. - #Any more then this they somebody was messing with things and its not our fault things are this bad - if [ ! -f $DAEMON_USER_PREF ]; then - echo "ssid=stratux" >> $DAEMON_USER_PREF - echo "channel=1" >> $DAEMON_USER_PREF - fi -fi - # Detect RPi version. # Per http://elinux.org/RPi_HardwareHistory EW7811Un=$(lsusb | grep EW-7811Un) From 96a67ee5fc530b312d54423e5ea27ee3819f2d8b Mon Sep 17 00:00:00 2001 From: peepsnet Date: Thu, 24 Nov 2016 10:47:43 -0500 Subject: [PATCH 21/23] adding hostapd.user building code Adding the code needed to update previous version of stratux with the new file structure needed while keeping custom user settings already used --- __root__stratux-pre-start.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/__root__stratux-pre-start.sh b/__root__stratux-pre-start.sh index cda14e54..4e250df8 100755 --- a/__root__stratux-pre-start.sh +++ b/__root__stratux-pre-start.sh @@ -15,3 +15,39 @@ if [ -e /root/update*stratux*v*.sh ] ; then fi fi +##### Script for setting up new file structure for hostapd settings +##### Look for hostapd.user and if found do nothing. +##### If not assume because of previous version and convert to new file structure +DAEMON_USER_PREF=/etc/hostapd/hostapd.user +if [ ! -f $DAEMON_USER_PREF ]; then + DAEMON_CONF=/etc/hostapd/hostapd.conf + DAEMON_CONF_EDIMAX=/etc/hostapd/hostapd-edimax.conf + HOSTAPD_VALUES=('ssid=' 'channel=' 'auth_algs=' 'wpa=' 'wpa_passphrase=' 'wpa_key_mgmt=' 'wpa_pairwise=' 'rsn_pairwise=') + HOSTAPD_VALUES_RM=('#auth_algs=' '#wpa=' '#wpa_passphrase=' '#wpa_key_mgmt=' '#wpa_pairwise=' '#rsn_pairwise=') + + for i in "${HOSTAPD_VALUES[@]}" + do + if grep -q "^$i" $DAEMON_CONF + then + grep "^$i" $DAEMON_CONF >> $DAEMON_USER_PREF + sed -i '/^'"$i"'/d' $DAEMON_CONF + sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX + fi + done + for i in "${HOSTAPD_VALUES_RM[@]}" + do + if grep -q "^$i" $DAEMON_CONF + then + sed -i '/^'"$i"'/d' $DAEMON_CONF + sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX + fi + done + sleep 1 #make sure there is time to get the file written before checking for it again + # If once the code above runs and there is still no hostapd.user file then something is wrong and we will just create the file with basic settings. + # Any more then this they somebody was messing with things and its not our fault things are this bad + if [ ! -f $DAEMON_USER_PREF ]; then + echo "ssid=stratux" >> $DAEMON_USER_PREF + echo "channel=1" >> $DAEMON_USER_PREF + fi +fi +##### End hostapd settings structure script From a951410f3f23f99ae535bbcdfb04f8d22f2b1ad8 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Thu, 24 Nov 2016 11:48:14 -0500 Subject: [PATCH 22/23] Restart WiFi in script This change now restarts the WiFI services in the script and no longer needs a restart!! --- image/hostapd_manager.sh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/image/hostapd_manager.sh b/image/hostapd_manager.sh index d48c5ce3..72908b59 100644 --- a/image/hostapd_manager.sh +++ b/image/hostapd_manager.sh @@ -90,7 +90,7 @@ while getopts $options option; do OPT_C=$OPTARG echo "$parm Channel option -c used: $OPT_C" if [[ "$OPT_C" =~ ^[0-9]+$ ]] && [ "$OPT_C" -ge 1 -a "$OPT_C" -le 13 ]; then - echo "${GREEN} Channel will now be set to ${BOLD}${UNDR}$OPT_C.${WHITE}${NORMAL}" + echo "${GREEN} Channel will now be set to ${BOLD}${UNDR}$OPT_C${NORMAL}.${WHITE}${NORMAL}" else echo "${BOLD}${RED}$err Channel is not within acceptable values, exiting...${WHITE}${NORMAL}" exit 1 @@ -254,9 +254,31 @@ do echo "" fi done -echo "${YELLOW}$att Don't forget to reboot... $att ${WHITE}" +echo "${RED}${BOLD} $att At this time the script will restart your WiFi services. $att ${WHITE}${NORMAL}" +echo "If you are connected to Stratux through the ${BOLD}192.168.10.1${NORMAL} interface then you will be disconnected" +echo "Please wait 1 min and look for the new SSID on your wireless device." +sleep 3 +echo "${YELLOW}$att Restarting Stratux WiFi Services... $att ${WHITE}" +echo "Killing hostapd..." +/usr/bin/killall -9 hostapd hostapd-edimax +echo "Killed..." +echo "" +echo "Killing DHCP Server..." +echo "" +/usr/sbin/service isc-dhcp-server stop +sleep 0.5 +echo "Killed..." +echo "" +echo "ifdown wlan0..." +ifdown wlan0 +sleep 0.5 +echo "ifup wlan0..." +echo "Calling Stratux WiFI Start Script(stratux-wifi.sh)..." +ifup wlan0 +sleep 0.5 echo "" echo "" +echo "All systems should be up and running and you should see your new SSID!" ### End main loop ### From ed0cc5bd7488e6fa78b8b1eb69228d5ff7ce5ee6 Mon Sep 17 00:00:00 2001 From: peepsnet Date: Thu, 24 Nov 2016 12:00:24 -0500 Subject: [PATCH 23/23] set a default passphrase if not choosen Fixed the script to use a default passphrase("Squawk1200") if option -e used but no passphrase entered. --- image/hostapd_manager.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/image/hostapd_manager.sh b/image/hostapd_manager.sh index 72908b59..2901bcec 100644 --- a/image/hostapd_manager.sh +++ b/image/hostapd_manager.sh @@ -69,7 +69,7 @@ fi #If an option should be followed by an argument, it should be followed by a ":". #Notice there is no ":" after "oqh". The leading ":" suppresses error messages from #getopts. This is required to get my unrecognized option code to work. -options=':s:c:e:oqh' +options=':s:c:eoqh' while getopts $options option; do case $option in s) #set option "s" @@ -90,7 +90,7 @@ while getopts $options option; do OPT_C=$OPTARG echo "$parm Channel option -c used: $OPT_C" if [[ "$OPT_C" =~ ^[0-9]+$ ]] && [ "$OPT_C" -ge 1 -a "$OPT_C" -le 13 ]; then - echo "${GREEN} Channel will now be set to ${BOLD}${UNDR}$OPT_C${NORMAL}.${WHITE}${NORMAL}" + echo "${GREEN} Channel will now be set to ${BOLD}${UNDR}$OPT_C${WHITE}${NORMAL}." else echo "${BOLD}${RED}$err Channel is not within acceptable values, exiting...${WHITE}${NORMAL}" exit 1 @@ -99,8 +99,8 @@ while getopts $options option; do ;; e) #set option "e" if [[ -z "${OPTARG}" || "${OPTARG}" == *[[:space:]]* || "${OPTARG}" == -* ]]; then - echo "${BOLD}${RED}$err Encryption option(-e) used without passphrase, exiting...${WHITE}${NORMAL}" - exit 1 + echo "${BOLD}${RED}$err Encryption option(-e) used without passphrase, Passphrase will be set to ${BOLD}$defaultPass${NORMAL}...${WHITE}${NORMAL}" + OPT_E=$defaultPass else OPT_E=$OPTARG echo "$parm Encryption option -e used:" @@ -126,7 +126,7 @@ while getopts $options option; do HELP ;; \?) # invalid option - echo "${BOLD}${RED}$err Invalid option -$OPTARG" >&2 + echo "${BOLD}${RED}$err Invalid option -$OPTARG ${WHITE}${NORMAL}" >&2 exit 1 ;; :) # Missing Arg @@ -254,7 +254,7 @@ do echo "" fi done -echo "${RED}${BOLD} $att At this time the script will restart your WiFi services. $att ${WHITE}${NORMAL}" +echo "${RED}${BOLD} $att At this time the script will restart your WiFi services.${WHITE}${NORMAL}" echo "If you are connected to Stratux through the ${BOLD}192.168.10.1${NORMAL} interface then you will be disconnected" echo "Please wait 1 min and look for the new SSID on your wireless device." sleep 3