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