chiark / gitweb /
Debianization.
[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       ${addr+-S-b}$addr \
109       ${port+-S-p}${port} \
110       ${user+-S-u}${user} \
111       ${group+-S-g}${group} \
112       ${trace+-S-T}${trace} \
113       ${miscopts}
114     for i in 1 2 3 4 give-up; do
115       $tripectl help >/dev/null 2>/dev/null && break
116       sleep 1
117     done
118     if [ $i = give-up ]; then
119       echo " wouldn't start"
120       exit 1
121     fi
122     echo -n " tripe"
123     for i in $TRIPEDIR/peers/*; do
124       [ -x $i ] || continue
125       name=`basename $i`
126       case $name in *~|\#*) continue;; esac
127       if $i; then 
128         echo -n " $name"
129       else
130         echo -n " ($name failed)"
131       fi
132     done
133     echo " done"
134     ;;
135   stop)
136     echo -n "Stopping TrIPE VPN daemon:"
137     $tripectl quit
138     echo " done"
139     ;;
140   status)
141     for i in `$tripectl list`; do
142       echo "Peer \`$i':"
143       $tripectl stats $i | sed 's/^/  /'
144     done
145     ;;
146   restart | force-reload)
147     sh $0 stop
148     sh $0 start
149     ;;
150   *)
151     echo >&2 "usage: $0 start|stop|restart|status|force-reload"
152     exit 1
153     ;;
154 esac