2014-03-31 23:18:29 +02:00
|
|
|
#!/bin/bash
|
2014-08-19 11:19:59 +02:00
|
|
|
INTERFACE=mullvad # Set to name of VPN interface
|
2014-03-31 23:18:29 +02:00
|
|
|
shopt -s nullglob
|
|
|
|
|
2014-08-19 11:19:59 +02:00
|
|
|
# Test whether gateway is connected to the outer world via VPN
|
2014-03-31 23:18:29 +02:00
|
|
|
ping -q -I $INTERFACE 8.8.8.8 -c 4 -i 1 -W 5 >/dev/null 2>&1
|
|
|
|
|
|
|
|
if test $? -eq 0; then
|
|
|
|
NEW_STATE=server
|
|
|
|
else
|
|
|
|
NEW_STATE=off
|
|
|
|
fi
|
|
|
|
|
2014-08-19 11:19:59 +02:00
|
|
|
# Iterate through network interfaces in sys file system
|
2014-03-31 23:18:29 +02:00
|
|
|
for MESH in /sys/class/net/*/mesh; do
|
2014-08-19 11:19:59 +02:00
|
|
|
# Check whether gateway modus needs to be changed
|
2014-03-31 23:18:29 +02:00
|
|
|
OLD_STATE="$(cat $MESH/gw_mode)"
|
|
|
|
[ "$OLD_STATE" == "$NEW_STATE" ] && continue
|
2014-08-19 11:19:59 +02:00
|
|
|
echo $NEW_STATE > $MESH/gw_mode
|
|
|
|
echo 54MBit/54MBit > $MESH/gw_bandwidth
|
|
|
|
logger "batman gateway mode changed to $NEW_STATE"
|
2014-03-31 23:18:29 +02:00
|
|
|
|
2014-08-19 11:19:59 +02:00
|
|
|
# Check whether gateway modus has been deactivated
|
|
|
|
if [ "$NEW_STATE" == "off" ]; then
|
|
|
|
# Shutdown DHCP server to prevent renewal of leases
|
|
|
|
service isc-dhcp-server stop
|
|
|
|
# Shutdown radvd daemon to prevent advertisment of server as gateway
|
|
|
|
service radvd stop
|
|
|
|
fi
|
2014-03-31 23:18:29 +02:00
|
|
|
|
2014-08-19 11:19:59 +02:00
|
|
|
# Check whether gateway modus has been activated
|
|
|
|
if [ "$NEW_STATE" == "server" ]; then
|
|
|
|
# Restart DHCP server and radvd daemon
|
|
|
|
service isc-dhcp-server start
|
|
|
|
service radvd start
|
|
|
|
fi
|
|
|
|
done
|