summaryrefslogtreecommitdiffstats
path: root/retiolum/bin
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
commitc14810cc9aa08c39645d794884465e5b740e30ac (patch)
treedfe7f259db5d9bbf1d384c60a9a86d74e7b8b436 /retiolum/bin
parent6fac52823412464009993e0539143e6ec200796c (diff)
retiolum//update_tinc_hosts: more magic
Diffstat (limited to 'retiolum/bin')
-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