diff --git a/files/lib/gluon/ssid-changer/ssid-changer.sh b/files/lib/gluon/ssid-changer/ssid-changer.sh index 71e3aade8360c91c84b06a90b7b41e11f043af8d..8cc9564de3eaabba63f74c591ef82b902c9f6e9d 100755 --- a/files/lib/gluon/ssid-changer/ssid-changer.sh +++ b/files/lib/gluon/ssid-changer/ssid-changer.sh @@ -10,34 +10,34 @@ ONLINE_SSID=$(uci get wireless.client_radio0.ssid -q) # 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 + 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 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 - if [ "$(uci get wireless.client_radio0.ssid)" == "$OFFLINE_SSID" ]; 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 - uci set wireless.client_radio0.ssid="$OFFLINE_SSID" - sed -i s~^ssid=$ONLINE_SSID~ssid=$OFFLINE_SSID~ /var/run/hostapd-phy0.conf + sed -i s~^ssid=$ONLINE_SSID~ssid=$OFFLINE_SSID~ $HOSTAPD killall -HUP hostapd fi fi if [ $CHECK -gt 0 ] ; then - if [ "$(uci get wireless.client_radio0.ssid)" == "$ONLINE_SSID" ]; 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 - uci set wireless.client_radio0.ssid="$ONLINE_SSID" - sed -i s~^ssid=$OFFLINE_SSID~ssid=$ONLINE_SSID~ /var/run/hostapd-phy0.conf + sed -i s~^ssid=$OFFLINE_SSID~ssid=$ONLINE_SSID~ $HOSTAPD killall -HUP hostapd fi