contrib/freifunk-gwcheck: Some fixes suggested by Patrick grimm

This commit is contained in:
Manuel Munz 2011-11-13 13:45:17 +00:00
parent 32be6cea93
commit 256daa259b
2 changed files with 10 additions and 9 deletions

View file

@ -3,7 +3,7 @@
#check if dyngw_plain is installed and enabled, else exit #check if dyngw_plain is installed and enabled, else exit
dyngwplainlib=`uci show olsrd |grep dyn_gw_plain |awk {' FS="."; print $1"."$2 '}` dyngwplainlib=`uci show olsrd |grep dyn_gw_plain |awk {' FS="."; print $1"."$2 '}`
if [ -n "$dyngwplainlib" ]; then if [ -n "$dyngwplainlib" ]; then
if [ ! "$(uci -q get $dyngwplainlib.ignore)" == 0 ]; then if [ "$(uci -q get $dyngwplainlib.ignore)" == 1 ]; then
exit 1 exit 1
fi fi
else else
@ -15,8 +15,8 @@ fi
# check if we have a defaultroute with metric=0 in one of these tables: main table and gw-check table. # check if we have a defaultroute with metric=0 in one of these tables: main table and gw-check table.
# If not exit here. # If not exit here.
defroutemain="$(ip r s |grep default |grep -v metric)" defroutemain="$(ip r s |grep default |grep -v metric)"
defroutegw-check="$(ip r s t gw-check |grep default |grep -v metric)" defroutegwcheck="$(ip r s t gw-check |grep default |grep -v metric)"
if [ -z "$defroutegw-check" -a -z "$defroutemain" ]; then if [ -z "$defroutegwcheck" -a -z "$defroutemain" ]; then
exit 1 exit 1
fi fi
@ -57,14 +57,14 @@ iw=$(check_internet)
if [ "$iw" == 0 ]; then if [ "$iw" == 0 ]; then
# check if we have a seperate routing table for our tests. # check if we have a seperate routing table for our tests.
# If yes, move defaultroute to normal table and delete table gw-check # If yes, move defaultroute to normal table and delete table gw-check
if [ -n "$defroutegw-check" ]; then if [ -n "$defroutegwcheck" ]; then
ip r a $defroutegw-check ip r a $defroutegwcheck
ip r d $defroutegw-check t gw-check ip r d $defroutegwcheck t gw-check
ip ru del fwmark 0x2 lookup gw-check ip ru del fwmark 0x2 lookup gw-check
for host in $testserver; do for host in $testserver; do
iptables -t mangle -D OUTPUT -d $host -p tcp --dport 80 -j MARK --set-mark 0x2 iptables -t mangle -D OUTPUT -d $host -p tcp --dport 80 -j MARK --set-mark 0x2
done done
logger -t gw-check "Internet is available again, restoring default route ( $defroutegw-check)" logger -t gw-check "Internet is available again, restoring default route ( $defroutegwcheck)"
fi fi
else else

View file

@ -1,5 +1,6 @@
#!/bin/sh #!/bin/sh
tables="/etc/iproute2/rt_tables" tables="/etc/iproute2/rt_tables"
test -d /etc/iproute2/ || mkdir -p /etc/iproute2/
grep -q "gw-check" $tables || echo "200 gw-check" >> $tables grep -q "gw-check" $tables || echo "200 gw-check" >> $tables
test -f /etc/crontabs/root || touch /etc/crontabs/root test -f /etc/crontabs/root || touch /etc/crontabs/root
grep -q "ff_olsr_test_gw.sh" /etc/crontabs/root || echo "* * * * * /usr/sbin/ff_olsr_test_gw.sh" >> /etc/crontabs/root grep -q "ff_olsr_test_gw.sh" /etc/crontabs/root || echo "* * * * * /usr/sbin/ff_olsr_test_gw.sh" >> /etc/crontabs/root