summaryrefslogtreecommitdiffstats
path: root/retiolum/bin/update_tinc_hosts
diff options
context:
space:
mode:
authorFelix Richter <Felix.Richter@syntax-fehler.de>2011-05-29 15:48:47 +0200
committerFelix Richter <Felix.Richter@syntax-fehler.de>2011-05-29 15:48:47 +0200
commit30b44417f91eb100fa67a38e9c1c1f88682c92ef (patch)
treef0c6c97d76c9ac7cfe2c88bdffcaee53ff0bc3ae /retiolum/bin/update_tinc_hosts
parent427bdf4e2093217f967384f785e3907930a74a21 (diff)
parent12c77cdbfa4ec48d935af3ae7cf1118e38bec6e1 (diff)
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'retiolum/bin/update_tinc_hosts')
-rwxr-xr-xretiolum/bin/update_tinc_hosts33
1 files changed, 33 insertions, 0 deletions
diff --git a/retiolum/bin/update_tinc_hosts b/retiolum/bin/update_tinc_hosts
new file mode 100755
index 00000000..2d5cf957
--- /dev/null
+++ b/retiolum/bin/update_tinc_hosts
@@ -0,0 +1,33 @@
+#! /bin/sh
+set -euf
+
+if test "${nosudo-false}" != true -a `id -u` != 0; then
+ echo "we're going sudo..." >&2
+ exec sudo "$0" "$@"
+ exit 23 # go to hell
+fi
+
+DIRNAME=`dirname $0`
+export PATH="`readlink -f $DIRNAME`:$PATH"
+
+hosts="${hosts-/etc/hosts}"
+
+bs='# BEGIN OF RETIOLUM'
+es='# END OF RETIOLUM'
+
+case "${1-imstupid}" in
+ (start|restart)
+ if grep -q "^$bs$" $hosts && grep -q "^$es$" $hosts; then
+ $0 stop
+ echo "$bs" >> $hosts
+ hosts >> $hosts
+ echo "$es" >> $hosts
+ fi
+ ;;
+ (stop)
+ sed -ie "/^$bs$/,/^$es$/d" $hosts
+ ;;
+ (*)
+ echo 'Error 1: You are made of stupid!' >&2
+ exit 23
+esac