--- /dev/null
+#! /bin/sh
+#
+# tripe init script
+# suitable for direct use in most SysV-style inits
+
+set -e
+
+# --- Setup ---
+
+[ -f @initconfig@ ] && . @initconfig@
+: ${prefix=@prefix@} ${exec_prefix=@exec_prefix@}
+: ${bindir=@bindir@} ${sbindir=@sbindir@}
+: ${TRIPEDIR=@configdir@} ${tripesock=@socketdir@/tripesock}
+: ${pidfile=@pidfile@}
+: ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
+PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
+export PATH TRIPEDIR
+
+# --- Give up if there's no key ---
+
+if test ! -f $TRIPEDIR/keyring || test ! -f $TRIPEDIR/keyring.pub; then
+ echo >&2 "Not starting/stopping TrIPE: keyring files missing"
+ exit 0
+fi
+
+# --- 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 ${tunnel-`$tripe --tunnels | head -1`} 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
+ ;;
+ slip)
+ if test "$TRIPE_SLIPIF" = ""; then
+ echo >&2 "$tripe needs SLIP interfaces set up!"
+ exit 1
+ fi
+ ;;
+esac
+
+# --- Do what was wanted ---
+
+case "$1" in
+ start)
+ echo -n "Starting TrIPE VPN daemon:"
+ if $tripectl version >/dev/null 2>/dev/null; then
+ echo " already running"
+ exit 0
+ fi
+ $tripectl -D -s -p$tripe \
+ -f${logfile-@logfile@} \
+ -P$pidfile \
+ ${keytag+-S-t}$keytag \
+ ${addr+-S-b}$addr \
+ ${port+-S-p}${port} \
+ ${user+-S-u}${user} \
+ ${group+-S-g}${group} \
+ ${trace+-S-T}${trace} \
+ ${tunnel+-S-n}${tunnel} \
+ ${miscopts}
+ for i in 1 2 3 4 give-up; do
+ $tripectl help >/dev/null 2>/dev/null && break
+ sleep 1
+ done
+ if [ $i = give-up ]; then
+ echo " wouldn't start"
+ exit 1
+ fi
+ echo -n " tripe"
+ for i in $TRIPEDIR/peers/*; do
+ [ -x $i ] || continue
+ name=`basename $i`
+ case $name in *~|\#*) continue;; esac
+ if $i; then
+ echo -n " $name"
+ else
+ echo -n " ($name failed)"
+ fi
+ done
+ echo " done"
+ ;;
+ stop)
+ echo -n "Stopping TrIPE VPN daemon:"
+ if test ! -S $tripesock; then
+ echo " not running"
+ elif $tripectl quit >/dev/null 2>&1; then
+ echo " done"
+ elif test ! -f $pidfile; then
+ echo " stale socket found: removing"
+ rm -f $tripesock
+ elif kill `cat $pidfile`; then
+ echo " done (killed violently)"
+ else
+ echo " it doesn't want do die!"
+ exit 1
+ fi
+ ;;
+ status)
+ for i in `$tripectl list`; do
+ echo "Peer \`$i':"
+ $tripectl stats $i | sed 's/^/ /'
+ done
+ ;;
+ reload)
+ $tripectl reload
+ echo "Keyrings reloaded OK."
+ ;;
+ restart | force-reload)
+ sh $0 stop
+ sh $0 start
+ ;;
+ *)
+ echo >&2 "usage: $0 start|stop|restart|status|reload|force-reload"
+ exit 1
+ ;;
+esac