X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/be376b2fb361621c4152e8f100c53c4e5f0ccbf6..c55f55afc693f452bcfa2ddd2af50d3216a9c951:/tripe-init.in diff --git a/tripe-init.in b/tripe-init.in index 59d93d48..8c4730e5 100755 --- a/tripe-init.in +++ b/tripe-init.in @@ -3,21 +3,97 @@ # tripe init script # suitable for direct use in most SysV-style inits -prefix=@prefix@ -exec_prefix=@exec_prefix@ -bindir=@bindir@ -sbindir=@sbindir@ - set -e -[ -f /etc/tripe.conf ] && . /etc/tripe.conf -: ${TRIPEDIR=/var/lib/tripe} -export TRIPEDIR +# --- Setup --- -: ${tripe=$sbindir/tripe} -: ${tripectl=$bindir/tripectl} +[ -f @initconfig@ ] && . @initconfig@ +: ${prefix=@prefix@} ${exec_prefix=@exec_prefix@} +: ${bindir=@bindir@} ${sbindir=@sbindir@} +: ${TRIPEDIR=@configdir@} +: ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl} PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir -export PATH +export PATH TRIPEDIR + +# --- Check it will work, or at least stands a fighting chance --- +# +# Having loads of different tunnel types doesn't help any. + +test -x $tripe -a -x $tripectl || exit 0 + +case `$tripe --tunnel` in + linux) + case `uname -s` in + Linux) + if { test -f /proc/misc && grep -q net/tun /proc/misc; } || + modprobe -q tun; then + : good + else + echo >&2 "$tripe needs the Linux TUN/TAP driver to run." + exit 1 + fi + if test -c /dev/net/tun; then + : good + else + echo >&2 "$tripe needs /dev/net/tun, which is missing." + exit 1 + fi + ;; + *) + echo >&2 "CONFIGURATION ERROR" + echo >&2 " $tripe is compiled to use a Linux tunnel device, but" + echo >&2 " this system is `uname -s`" + exit 1 + ;; + esac + ;; + unet) + case `uname -s` in + Linux) + if { test -f /proc/devices && grep -q unet /proc/devices; } || + modprobe -q unet; then + : good + else + echo >&2 "$tripe needs the Linux UNET driver to run." + exit 1 + fi + if test -c /dev/unet; then + : good + else + echo >&2 "$tripe needs /dev/unet, which is missing." + exit 1 + fi + ;; + *) + echo >&2 "CONFIGURATION ERROR" + echo >&2 " $tripe is compiled to use a Linux tunnel device, but" + echo >&2 " this system is `uname -s`" + exit 1 + ;; + esac + ;; + bsd) + case `uname -s` in + *BSD) + # Don't know how to check the device is working. + if test -c /dev/tun0; then + : good + else + echo >&2 "$tripe needs /dev/tun0, which is missing." + exit 1 + fi + ;; + *) + echo >&2 "CONFIGURATION ERROR" + echo >&2 " $tripe is compiled to use a BSD tunnel device, but" + echo >&2 " this system is `uname -s`" + exit 1 + ;; + esac + ;; +esac + +# --- Do what was wanted --- case "$1" in start) @@ -26,7 +102,10 @@ case "$1" in echo " already running" exit 0 fi - $tripectl -D -f ${tripelog-tripe.log} -p $tripe -s \ + $tripectl -D -s -p$tripe \ + -f${logfile-@logfile@} \ + -P${pidfile-@pidfile@} \ + ${keytag+-S-t}$keytag \ ${addr+-S-b}$addr \ ${port+-S-p}${port} \ ${user+-S-u}${user} \ @@ -43,10 +122,14 @@ case "$1" in fi echo -n " tripe" for i in $TRIPEDIR/peers/*; do - case $i in *~|\#*) continue;; esac + [ -x $i ] || continue name=`basename $i` - $i - echo -n " $name" + case $name in *~|\#*) continue;; esac + if $i; then + echo -n " $name" + else + echo -n " ($name failed)" + fi done echo " done" ;; @@ -55,12 +138,18 @@ case "$1" in $tripectl quit echo " done" ;; + status) + for i in `$tripectl list`; do + echo "Peer \`$i':" + $tripectl stats $i | sed 's/^/ /' + done + ;; restart | force-reload) sh $0 stop sh $0 start ;; *) - echo >&2 "usage: $0 start|stop|restart|force-reload" + echo >&2 "usage: $0 start|stop|restart|status|force-reload" exit 1 ;; esac