summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@also>2011-05-31 13:53:28 +0200
committertv <tv@also>2011-05-31 13:53:28 +0200
commitc75b30737e5b96e7cda1d1ae727cae58a49677e2 (patch)
tree7c591232f4152fa1afd3cf926dc190dc8b06073a
parentfa4204369e2d75b06d8b007a751aed06327fd315 (diff)
retiolum//update_tinc_hosts: more magic
-rwxr-xr-xretiolum/bin/update_tinc_hosts31
1 files changed, 23 insertions, 8 deletions
diff --git a/retiolum/bin/update_tinc_hosts b/retiolum/bin/update_tinc_hosts
index 2d5cf957..fe0785e3 100755
--- a/retiolum/bin/update_tinc_hosts
+++ b/retiolum/bin/update_tinc_hosts
@@ -15,17 +15,32 @@ hosts="${hosts-/etc/hosts}"
bs='# BEGIN OF RETIOLUM'
es='# END OF RETIOLUM'
-case "${1-imstupid}" in
+case "${*-I am made of stupid}" in
(start|restart)
- if grep -q "^$bs$" $hosts && grep -q "^$es$" $hosts; then
- $0 stop
- echo "$bs" >> $hosts
- hosts >> $hosts
- echo "$es" >> $hosts
- fi
+ hosts | $0 replace magic
;;
(stop)
- sed -ie "/^$bs$/,/^$es$/d" $hosts
+ $0 clear magic
+ ;;
+ ('print magic')
+ echo "$bs"
+ cat
+ echo "$es"
+ ;;
+ ('create magic')
+ $0 has magic || $0 print magic >> $hosts < /dev/null
+ ;;
+ ('destroy magic')
+ $0 has magic && sed -ie "/^$bs$/,/^$es$/d" $hosts
+ ;;
+ ('has magic')
+ grep -q "^$bs$" $hosts && grep -q "^$es$" $hosts
+ ;;
+ ('replace magic')
+ $0 destroy magic && $0 print magic >> $hosts
+ ;;
+ ('clear magic')
+ $0 replace magic < /dev/null
;;
(*)
echo 'Error 1: You are made of stupid!' >&2