chiark / gitweb /
8c4730e5ae2f25cd8ed93837d1ed444b029e8050
[tripe] / tripe-init.in
1 #! /bin/sh
2 #
3 # tripe init script
4 #   suitable for direct use in most SysV-style inits
5
6 set -e
7
8 # --- Setup ---
9
10 [ -f @initconfig@ ] && . @initconfig@
11 : ${prefix=@prefix@} ${exec_prefix=@exec_prefix@}
12 : ${bindir=@bindir@} ${sbindir=@sbindir@}
13 : ${TRIPEDIR=@configdir@}
14 : ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
15 PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
16 export PATH TRIPEDIR
17
18 # --- Check it will work, or at least stands a fighting chance ---
19 #
20 # Having loads of different tunnel types doesn't help any.
21
22 test -x $tripe -a -x $tripectl || exit 0
23
24 case `$tripe --tunnel` in
25   linux)
26     case `uname -s` in
27       Linux)
28         if { test -f /proc/misc && grep -q net/tun /proc/misc; } ||
29            modprobe -q tun; then
30           : good
31         else
32           echo >&2 "$tripe needs the Linux TUN/TAP driver to run."
33           exit 1
34         fi
35         if test -c /dev/net/tun; then
36           : good
37         else
38           echo >&2 "$tripe needs /dev/net/tun, which is missing."
39           exit 1
40         fi
41         ;;
42       *)
43         echo >&2 "CONFIGURATION ERROR"
44         echo >&2 "  $tripe is compiled to use a Linux tunnel device, but"
45         echo >&2 "  this system is `uname -s`"
46         exit 1
47         ;;
48     esac
49     ;;
50   unet)
51     case `uname -s` in
52       Linux)
53         if { test -f /proc/devices && grep -q unet /proc/devices; } ||
54            modprobe -q unet; then
55           : good
56         else
57           echo >&2 "$tripe needs the Linux UNET driver to run."
58           exit 1
59         fi
60         if test -c /dev/unet; then
61           : good
62         else
63           echo >&2 "$tripe needs /dev/unet, which is missing."
64           exit 1
65         fi
66         ;;
67       *)
68         echo >&2 "CONFIGURATION ERROR"
69         echo >&2 "  $tripe is compiled to use a Linux tunnel device, but"
70         echo >&2 "  this system is `uname -s`"
71         exit 1
72         ;;
73     esac
74     ;;
75   bsd)
76     case `uname -s` in
77       *BSD)
78         # Don't know how to check the device is working.
79         if test -c /dev/tun0; then
80           : good
81         else
82           echo >&2 "$tripe needs /dev/tun0, which is missing."
83           exit 1
84         fi
85         ;;
86       *)
87         echo >&2 "CONFIGURATION ERROR"
88         echo >&2 "  $tripe is compiled to use a BSD tunnel device, but"
89         echo >&2 "  this system is `uname -s`"
90         exit 1
91         ;;
92     esac
93     ;;
94 esac
95   
96 # --- Do what was wanted ---
97
98 case "$1" in
99   start)
100     echo -n "Starting TrIPE VPN daemon:"
101     if $tripectl help >/dev/null 2>/dev/null; then
102       echo " already running"
103       exit 0
104     fi
105     $tripectl -D -s -p$tripe \
106       -f${logfile-@logfile@} \
107       -P${pidfile-@pidfile@} \
108       ${keytag+-S-t}$keytag \
109       ${addr+-S-b}$addr \
110       ${port+-S-p}${port} \
111       ${user+-S-u}${user} \
112       ${group+-S-g}${group} \
113       ${trace+-S-T}${trace} \
114       ${miscopts}
115     for i in 1 2 3 4 give-up; do
116       $tripectl help >/dev/null 2>/dev/null && break
117       sleep 1
118     done
119     if [ $i = give-up ]; then
120       echo " wouldn't start"
121       exit 1
122     fi
123     echo -n " tripe"
124     for i in $TRIPEDIR/peers/*; do
125       [ -x $i ] || continue
126       name=`basename $i`
127       case $name in *~|\#*) continue;; esac
128       if $i; then 
129         echo -n " $name"
130       else
131         echo -n " ($name failed)"
132       fi
133     done
134     echo " done"
135     ;;
136   stop)
137     echo -n "Stopping TrIPE VPN daemon:"
138     $tripectl quit
139     echo " done"
140     ;;
141   status)
142     for i in `$tripectl list`; do
143       echo "Peer \`$i':"
144       $tripectl stats $i | sed 's/^/  /'
145     done
146     ;;
147   restart | force-reload)
148     sh $0 stop
149     sh $0 start
150     ;;
151   *)
152     echo >&2 "usage: $0 start|stop|restart|status|force-reload"
153     exit 1
154     ;;
155 esac