summaryrefslogtreecommitdiffstats
path: root/retiolum/scripts/routing
diff options
context:
space:
mode:
Diffstat (limited to 'retiolum/scripts/routing')
-rwxr-xr-xretiolum/scripts/routing/defaultroute.sh38
1 files changed, 38 insertions, 0 deletions
diff --git a/retiolum/scripts/routing/defaultroute.sh b/retiolum/scripts/routing/defaultroute.sh
new file mode 100755
index 00000000..d54e8bcf
--- /dev/null
+++ b/retiolum/scripts/routing/defaultroute.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+usage()
+{
+ echo "usage:"
+ echo "-h, print this help youre currently reading"
+ echo "-a activate routing"
+ echo "-d deactivate routing"
+}
+
+defaultroute=$(ip route show | grep default | awk '{ print $3 }')
+tincdir="/etc/tinc/retiolum"
+
+if [[ $(id -u) -gt 0 ]]; then
+ echo "This script should be run as root."
+ exit 1
+fi
+
+case "$1" in
+ -h|-help)
+ usage
+ exit 0;;
+ -a)
+ command="add"
+ ;;
+ -d)
+ command="del"
+ ;;
+ -*|*)
+ usage
+ exit 1;;
+esac
+
+cat $tincdir/tinc.conf | grep ConnectTo | cut -b 13- |
+while read host
+do
+ addr=$(cat $tincdir/hosts/$host | grep Address | cut -b 11-)
+ route $command $addr gw $defaultroute && echo $command $addr via $defaultroute
+done