diff options
author | Jason A. Donenfeld <zx2c4@gentoo.org> | 2017-03-17 15:37:57 +0100 |
---|---|---|
committer | Jason A. Donenfeld <zx2c4@gentoo.org> | 2017-03-17 15:38:28 +0100 |
commit | 9754f457cc6d0aeb90a1535a5228ef909e9584c9 (patch) | |
tree | ffbd77f41fb100837cc8f992f8dc863cd01c270d /net-vpn/nstx/files/nstxcd.init | |
parent | 6f9831941e9c3d2dc66d172b7acf7ecb1a5d709a (diff) | |
download | gentoo-9754f457cc6d0aeb90a1535a5228ef909e9584c9.tar.gz gentoo-9754f457cc6d0aeb90a1535a5228ef909e9584c9.tar.xz |
Second half of net-vpn/ move
Diffstat (limited to 'net-vpn/nstx/files/nstxcd.init')
-rw-r--r-- | net-vpn/nstx/files/nstxcd.init | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/net-vpn/nstx/files/nstxcd.init b/net-vpn/nstx/files/nstxcd.init new file mode 100644 index 00000000000..44435897073 --- /dev/null +++ b/net-vpn/nstx/files/nstxcd.init @@ -0,0 +1,103 @@ +#!/sbin/openrc-run +# Copyright 1999-2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# (Written by Phillip Berndt <phillip.berndt at gmail dot com>) +# (Modified by Steven Brudenell <steven dot brudenell at gmail>) + +depend() { + local iface + + for iface in ${NEED_INTERFACES} ; do + need net.${iface} + done + + # If the user set TUNTAP_INTERFACE, they probably have a net script + # configuring that interface. nstxcd is responsible for actually creating + # the stupid thing, so we need to run before the config. + if [ ! -z ${TUNTAP_INTERFACE} ] ; then + if [ -x /etc/init.d/net.${TUNTAP_INTERFACE} ] ; then + before net.${TUNTAP_INTERFACE} + fi + fi +} + +loadtun() { + if [ ! -e /dev/net/tun ] + then + ebegin "Loading TUN/TAP kernel module" + modprobe -q tun + eend $? + fi + + if [ ! -e /dev/net/tun ] + then + eend 1 "Failed to load TUN driver! (did you compile your kernel with TUN/TAP support?)" + return 1 + fi + + return 0 +} + +checkconfig() { + if [ -z "${DOMAIN}" ] ; then + eerror "DOMAIN must be set" + return 1 + fi + + [ -z "${TUNTAP_INTERFACE}" ] || NSTXCD_OPTS="${NSTXCD_OPTS} -I ${TUNTAP_INTERFACE}" + [ -z "${TUNTAP_DEVICE}" ] || NSTXCD_OPTS="${NSTXCD_OPTS} -d ${TUNTAP_DEVICE}" + + case "${MODE}" in + TUN) + NSTXCD_OPTS="${NSTXCD_OPTS} -t" + ;; + TAP) + NSTXCD_OPTS="${NSTXCD_OPTS} -T" + ;; + *) + eerror "MODE must be either TUN or TAP" + return 1 + ;; + esac + + if [ -z "${DNS_SERVER}" ] ; then + DNS_SERVER=`awk '/^nameserver/{ print $2; exit; }' /etc/resolv.conf` + + if [ -z "${DNS_SERVER}" ] ; then + eerror "DNS_SERVER not set, and couldn't determine a nameserver from /etc/resolv.conf" + return 1 + fi + export DNS_SERVER + fi + + return 0 +} + +start() { + checkconfig || return 1 + + loadtun || return 1 + + ebegin "Starting nstxcd" + + start-stop-daemon \ + --start \ + --background \ + --make-pidfile \ + --exec /usr/sbin/nstxcd \ + --pidfile "/var/run/nstxcd.pid" \ + -- ${NSTXCD_OPTS} ${DOMAIN} ${DNS_SERVER} + + eend $? +} + +stop() { + ebegin "Stopping nstxcd" + + start-stop-daemon \ + --stop \ + --exec /usr/sbin/nstxcd \ + --pidfile "/var/run/nstxcd.pid" + + eend $? +} |