wifi/files/all/usr/bin/wifi-sentinel.sh

67 lines
1.3 KiB
Bash
Raw Normal View History

2019-10-28 17:18:40 +02:00
#!/bin/sh
. /lib/functions/network.sh
p=$(uci get wifi-sentinel.@wifi-sentinel[0].packets)
if [ -z "$p" ]; then
PACKETS='3'
else
PACKETS="$p"
fi
p=$(uci get wifi-sentinel.@wifi-sentinel[0].interval)
if [ -z "$p" ]; then
INTERVAL='10'
else
INTERVAL="$p"
fi
p=$(uci get wifi-sentinel.@wifi-sentinel[0].network)
if [ -z "$p" ]; then
NETWORK='management'
else
NETWORK="$p"
fi
2019-10-28 17:18:40 +02:00
STATUS='unknown'
lightsoff()
{
if [ "$STATUS" != 'down' ]; then
/usr/bin/logger -t wifi-sentinel -p daemon.alert Shutting down wireless interfaces due to lack of connectivity to the gateway.
/sbin/wifi down
STATUS='down'
fi
}
lightson()
{
if [ "$STATUS" != 'up' ]; then
/usr/bin/logger -t wifi-sentinel -p daemon.notice Bringing up wireless interfaces. Gateway connectivity restored.
/sbin/wifi up
STATUS='up'
fi
}
ping_check()
{
local target
network_get_gateway target $NETWORK
RET=`ping -c $PACKETS $target 2> /dev/null | awk '/packets received/ {print $4}'`
if [ "$RET" -eq "$PACKETS" ]; then
return 0
else
return 1
fi
}
/usr/bin/logger -t wifi-sentinel -p daemon.info "Starting Wi-Fi Sentinel on the $NETWORK network with $PACKETS checks every $INTERVAL seconds."
while true ; do
if ping_check; then
2019-10-28 17:18:40 +02:00
lightson
else
lightsoff
fi
sleep $INTERVAL
done