diff --git a/README.md b/README.md index 107ff49625902a67bec7e854b6409038e6bc74c2..5184e11f7f7ec57e3707035d2afb82acbf3d09d5 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ This script changes the SSID when there is no connection to the selected Gateway Once a minute it checks if there is a gateway reacheable with `batctl gwl -H` and decides if a change of the SSID is necessary. -*It is a simplified rewrite of https://github.com/ffac/gluon-ssid-changer that doesn't check -the tx value any more. It is in use in Freifunk Freiburg* +*It is a fork of https://github.com/ffac/gluon-ssid-changer that doesn't check +the tx value any more. It will be in use in Freifunk Nord* Gluon versions ============== diff --git a/files/lib/gluon/ssid-changer/ssid-changer.sh b/files/lib/gluon/ssid-changer/ssid-changer.sh index 8cc9564de3eaabba63f74c591ef82b902c9f6e9d..1259be00eca1503976e0988558e5121b96c69d99 100755 --- a/files/lib/gluon/ssid-changer/ssid-changer.sh +++ b/files/lib/gluon/ssid-changer/ssid-changer.sh @@ -4,40 +4,63 @@ MINUTES=1440 # only once every timeframe the SSID will change to OFFLINE (set to 1 minute to change every time the router gets offline) OFFLINE_PREFIX='FF_OFFLINE_' # use something short to leave space for the nodename (no '~' allowed!) -ONLINE_SSID=$(uci get wireless.client_radio0.ssid -q) +ONLINE_SSID="$(uci get wireless.client_radio0.ssid -q)" : ${ONLINE_SSID:="FREIFUNK"} # if for whatever reason ONLINE_SSID is NULL # Generate an Offline SSID with the first and last part of the nodename to allow owner to recognise wich node is down -NODENAME=`uname -n` -if [ ${#NODENAME} -gt $((30 - ${#OFFLINE_PREFIX})) ] ; then # 32 would be possible as well - HALF=$(( (28 - ${#OFFLINE_PREFIX} ) / 2 )) # calculate the length of the first part of the node identifier in the offline-ssid - SKIP=$(( ${#NODENAME} - $HALF )) # jump to this charakter for the last part of the name - OFFLINE_SSID=$OFFLINE_PREFIX${NODENAME:0:$HALF}...${NODENAME:$SKIP:${#NODENAME}} # use the first and last part of the nodename for nodes with long name +NODENAME="$(uname -n)" +if [ ${#NODENAME} -gt $((30 - ${#OFFLINE_PREFIX})) ]; then # 32 would be possible as well + HALF=$(( (28 - ${#OFFLINE_PREFIX} ) / 2 )) # calculate the length of the first part of the node identifier in the offline-ssid + SKIP=$(( ${#NODENAME} - $HALF )) # jump to this charakter for the last part of the name + OFFLINE_SSID=$OFFLINE_PREFIX${NODENAME:0:$HALF}...${NODENAME:$SKIP:${#NODENAME}} # use the first and last part of the nodename for nodes with long name else - OFFLINE_SSID="$OFFLINE_PREFIX$NODENAME" # great! we are able to use the full nodename in the offline ssid + OFFLINE_SSID="$OFFLINE_PREFIX$NODENAME" # great! we are able to use the full nodename in the offline ssid fi -# maximum simplyfied, no more ttvn rating + +# maximum simplified, no more ttvn rating CHECK=$(batctl gwl -H|grep -v "gateways in range"|wc -l) -HOSTAPD=/var/run/hostapd-phy0.conf -if [ $CHECK -eq 0 ] ; then - if [ $(expr $(date "+%s") / 60 % $MINUTES) -eq 0 ]; then - CURRENT_SSID=`grep "^ssid=$ONLINE_SSID" $HOSTAPD | cut -d"=" -f2` - if [ "$CURRENT_SSID" == "$OFFLINE_SSID" ]; then - echo "$0 - still on $OFFLINE_SSID" - exit 0 - fi - echo "$0 change ssid to $OFFLINE_SSID" | logger - sed -i s~^ssid=$ONLINE_SSID~ssid=$OFFLINE_SSID~ $HOSTAPD - killall -HUP hostapd - fi +HUP_NEEDED=0 +if [ $CHECK -gt 0 ]; then + echo "node is online" + for HOSTAPD in $(ls /var/run/hostapd-phy*); do # check status for all physical devices + CURRENT_SSID="$(grep "^ssid=$ONLINE_SSID" $HOSTAPD | cut -d"=" -f2)" + if [ "$CURRENT_SSID" == "$ONLINE_SSID" ] + then + echo "SSID $CURRENT_SSID is correct, noting to do" + break + fi + CURRENT_SSID="$(grep "^ssid=$OFFLINE_SSID" $HOSTAPD | cut -d"=" -f2)" + if [ "$CURRENT_SSID" == "$OFFLINE_SSID" ]; then + logger -s -t "gluon-offline-ssid" -p 5 "SSID is $CURRENT_SSID, change to $ONLINE_SSID" + sed -i "s~^ssid=$CURRENT_SSID~ssid=$ONLINE_SSID~" $HOSTAPD + HUP_NEEDED=1 # HUP here would be to early for dualband devices + else + echo "There is something wrong, did not find SSID $ONLINE_SSID or $OFFLINE_SSID" + fi +done +elif [ $CHECK -eq 0 ]; then + echo "node is considered offline" + if [ $(expr $(date "+%s") / 60 % $MINUTES) -eq 0 ]; then + for HOSTAPD in $(ls /var/run/hostapd-phy*); do + CURRENT_SSID="$(grep "^ssid=$OFFLINE_SSID" $HOSTAPD | cut -d"=" -f2)" + if [ "$CURRENT_SSID" == "$OFFLINE_SSID" ]; then + echo "SSID $CURRENT_SSID is correct, noting to do" + break + fi + CURRENT_SSID="$(grep "^ssid=$ONLINE_SSID" $HOSTAPD | cut -d"=" -f2)" + if [ "$CURRENT_SSID" == "$ONLINE_SSID" ]; then + logger -s -t "gluon-offline-ssid" -p 5 "SSID is $CURRENT_SSID, change to $OFFLINE_SSID" + sed -i "s~^ssid=$ONLINE_SSID~ssid=$OFFLINE_SSID~" $HOSTAPD + HUP_NEEDED=1 + else + echo "There is something wrong: did neither find SSID '$ONLINE_SSID' nor '$OFFLINE_SSID'" + fi + done + fi fi -if [ $CHECK -gt 0 ] ; then - CURRENT_SSID=`grep "^ssid=$ONLINE_SSID" $HOSTAPD | cut -d"=" -f2` - if [ "$CURRENT_SSID" == "$ONLINE_SSID" ]; then - echo "$0 - still on $ONLINE_SSID" - exit 0 - fi - echo "$0 change ssid to $ONLINE_SSID"| logger - sed -i s~^ssid=$OFFLINE_SSID~ssid=$ONLINE_SSID~ $HOSTAPD - killall -HUP hostapd + +if [ $HUP_NEEDED == 1 ]; then + killall -HUP hostapd # send HUP to all hostapd to load the new SSID + HUP_NEEDED=0 + echo "HUP!" fi