diff options
| author | tv <tv@also> | 2011-05-28 12:38:14 +0200 | 
|---|---|---|
| committer | tv <tv@also> | 2011-05-28 12:38:14 +0200 | 
| commit | b0a176af2c688524f38a17ffbfbd925055620743 (patch) | |
| tree | 572048f4ce99e7eb49689541083f80560142e1bb /modules | |
| parent | 358b8914cd2568e6314ed9b051bfeedbea41b732 (diff) | |
update_tinc_hosts: only maybe update hosts
Diffstat (limited to 'modules')
| -rwxr-xr-x | modules/retiolum/bin/update_tinc_hosts | 40 | 
1 files changed, 22 insertions, 18 deletions
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  | 
