summaryrefslogtreecommitdiffstats
path: root/modules/retiolum/bin/update_tinc_hosts
blob: 2d5cf957c83e008a6e8d9d483694f6cbc796f228 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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