From b0a176af2c688524f38a17ffbfbd925055620743 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 28 May 2011 12:38:14 +0200 Subject: update_tinc_hosts: only maybe update hosts --- modules/retiolum/bin/update_tinc_hosts | 40 +++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'modules/retiolum/bin/update_tinc_hosts') diff --git a/modules/retiolum/bin/update_tinc_hosts b/modules/retiolum/bin/update_tinc_hosts index 623ea315..31c8a398 100755 --- a/modules/retiolum/bin/update_tinc_hosts +++ b/modules/retiolum/bin/update_tinc_hosts @@ -1,29 +1,33 @@ -#!/bin/sh -DIRNAME=`dirname $0` -HERE=`readlink -f ${DIRNAME}` +#! /bin/sh +set -euf -if test `id -u` != 0; then +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 -case $1 in - start) - $0 stop - echo "# BEGIN OF RETIOLUM" >> /etc/hosts - $HERE/hosts >> /etc/hosts - echo "# END OF RETIOLUM" >> /etc/hosts +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 "/\# BEGIN OF RETIOLUM/,/\# END OF RETIOLUM/d" /etc/hosts - ;; - restart) - $0 stop - $0 start + (stop) + sed -ie "/^$bs$/,/^$es$/d" $hosts ;; - *) - echo "You are made of stupid!" + (*) + echo 'You are made of stupid!' >&2 exit 23 esac -- cgit v1.2.3