summaryrefslogtreecommitdiff
path: root/gentoo-linux/net-misc/uanytun/files/uanytun-0.3.3.init
diff options
context:
space:
mode:
Diffstat (limited to 'gentoo-linux/net-misc/uanytun/files/uanytun-0.3.3.init')
-rwxr-xr-xgentoo-linux/net-misc/uanytun/files/uanytun-0.3.3.init88
1 files changed, 88 insertions, 0 deletions
diff --git a/gentoo-linux/net-misc/uanytun/files/uanytun-0.3.3.init b/gentoo-linux/net-misc/uanytun/files/uanytun-0.3.3.init
new file mode 100755
index 0000000..31d9dc1
--- /dev/null
+++ b/gentoo-linux/net-misc/uanytun/files/uanytun-0.3.3.init
@@ -0,0 +1,88 @@
+#!/sbin/runscript
+# Distributed under the terms of the GNU General Public License v3
+# Written by Bernhard Tittelbach based on examples from Gentoo, openvpn and uanytun debian initrd script
+
+depend() {
+ need net
+ use dns
+ after bootmisc
+}
+
+DAEMON=/usr/sbin/uanytun
+CONFIG_DIR=/etc/uanytun
+NAME=uanytun
+DESC=uanytun
+VARRUN_PREFIX=/var/run/$NAME
+
+VPN=${SVCNAME#*.}
+[ "$VPN" = "$SVCNAME" ] && VPN=""
+
+test -x $DAEMON || exit 1
+
+# Include uanytun defaults if available
+if [ -f /etc/conf.d/uanytun ] ; then
+ . /etc/conf.d/uanytun
+fi
+
+start_vpn () {
+ if [ -f $CONFIG_DIR/$VPNNAME/config ] ; then
+ POSTUP=''
+ test -f $CONFIG_DIR/$VPNNAME/post-up.sh && POSTUP="-x $CONFIG_DIR/$VPNNAME/post-up.sh"
+ CHROOTDIR=`grep '^chroot' < $CONFIG_DIR/$VPNNAME/config | sed 's/chroot\s*//'`
+ if [ -n "$CHROOTDIR" ] ; then
+ test -d $CHROOTDIR || mkdir -p $CHROOTDIR
+ fi
+ DAEMONARG=`sed 's/#.*//' < $CONFIG_DIR/$VPNNAME/config | grep -e '\w' | sed 's/^/--/' | tr '\n' ' '`
+ start-stop-daemon --start --pidfile $VARRUN_PREFIX.${VPNNAME}.pid --exec \
+ $DAEMON -- --write-pid $VARRUN_PREFIX.${VPNNAME}.pid $POSTUP $DAEMONOPTS $DAEMONARG || return 1
+ else
+ eerror "no config found"
+ return 1
+ fi
+ return 0
+}
+stop_vpn () {
+ start-stop-daemon --stop --pidfile $PIDFILE --exec $DAEMON --oknodo
+ rm -f $PIDFILE
+}
+
+start () {
+ if test -z "$VPN" ; then
+ if [ -f $CONFIG_DIR/autostart ] ; then
+ for VPNNAME in `sed 's/#.*//' < $CONFIG_DIR/autostart | grep -e '\w'`; do
+ ebegin "Starting ${DESC} VPN: ${VPNNAME}"
+ start_vpn
+ eend $?
+ done
+ else
+ eerror "no config found"
+ return 1
+ fi
+ else
+ VPNNAME="$VPN"
+ ebegin "Starting ${DESC} VPN: ${VPNNAME}"
+ start_vpn
+ eend $?
+ fi
+}
+
+stop () {
+ if test -z "$VPN" ; then
+ for PIDFILE in `ls $VARRUN_PREFIX.*.pid 2> /dev/null`; do
+ VPNNAME=`basename $PIDFILE .pid`
+ ebegin "Stopping ${NAME} VPN: ${VPNNAME}"
+ stop_vpn
+ eend $?
+ done
+ else
+ if test -e $VARRUN_PREFIX.${VPN}.pid ; then
+ PIDFILE=`ls $VARRUN_PREFIX.${VPN}.pid 2> /dev/null`
+ VPNNAME=`basename $PIDFILE .pid`
+ ebegin "Stopping ${NAME} VPN: ${VPNNAME}"
+ stop_vpn
+ eend $?
+ else
+ eerror " failure: No such tunnel is running: $VPN"
+ fi
+ fi
+}