Permalink
Browse files

restoring init.d vpzone script

  • Loading branch information...
1 parent 22baece commit 37fa66eda62d652f1cfb8b5528c65091c1cff54d @bignaux committed Mar 14, 2012
Showing with 141 additions and 1 deletion.
  1. +2 −1 net-misc/vpzone/Manifest
  2. +117 −0 net-misc/vpzone/files/vpzone.init
  3. +22 −0 net-misc/vpzone/vpzone-0.1.3.ebuild
@@ -1,7 +1,8 @@
AUX dns-overflow.patch 418 RMD160 4e90d9299b9e975acb0c0f0c2b0abf3de0a18987 SHA1 e4c3fb4d2a336456f9d1c5a25183cd9015880761 SHA256 08cd6c6f80c5bc02a5122bb642a25bd27f2cafe78abf18344516ce56d3177357
+AUX vpzone.init 3063 RMD160 af9afebb29e974faa335e22e6789b34d8f13d9eb SHA1 9b717978507f7964f252e2e3f0ed7522a960d38a SHA256 3cba733c9b51a9bc350a2f81e1ea61f6c636fa4fb033deeea869a05ea1b70cee
DIST vpzone-0.1.2.tar.bz2 298590 RMD160 a4da67165c696efdc787543c8e66141671a5727c SHA1 110e3ab79fc4f35f0a30474dd5febd2f682d5cd3 SHA256 d884b5c07f0e620c05f49681639f08ace6c93a7f990fd8e960d55c629f55ff5b
DIST vpzone-0.1.3.tar.bz2 88609 RMD160 4ec14ef5586fa81da5fb969b3cbe5a2212e6d17b SHA1 b3f0ef1929986d81e0029bc8a0b816031470b256 SHA256 bdc2089dc50ba462eb9f8392b4cf67ff3fa71fbb924fff57baffba6df2918c66
EBUILD vpzone-0.1.2.ebuild 1122 RMD160 64e056fa695d7fdda945458e5f18caa1a0eb638d SHA1 a68709f77a442a75fbcf73dd5d0e4953ce7e5def SHA256 26209cca5f1cc44267678972ad84da628cf67fd742cfb20e8a3e3c9c8b38d864
-EBUILD vpzone-0.1.3.ebuild 1341 RMD160 83675f384745647f270c9c1b667d04640af6f3ed SHA1 906dbb6aa1b86fc741eeeb2b5306264efc4bf4f6 SHA256 820cf00246daffcfd0c7fb0bb8746795bcc7595a7b996991ed3c6bd8ba936fb9
+EBUILD vpzone-0.1.3.ebuild 2129 RMD160 2b680ccf0c42a72549b97353e791e0594ea9f98f SHA1 a32fe7ce0bf75d9991b4c3eeb516615d7d4ba897 SHA256 6bda89c5473449c366e6844b4a967e3a109bf1e80042501f45b0a956ee30b0e7
EBUILD vpzone-9999.ebuild 1310 RMD160 a8a621e8fff04c1d8dc1ca54ae1be6ddf66adb99 SHA1 b88373624335a0824fba1bdd4db697e43d8a32f4 SHA256 3a0847457768f0fc93a5a168ae9634dd90b95396778f05b89065c398b2b2d0f8
MISC metadata.xml 252 RMD160 0937d5b04d31b5a05084cba49fd5b49fff4583f4 SHA1 639588e0928fb07bb922503f8c7e44173649f4c4 SHA256 221dfcfc677a1f295a732a457dc65f5ad30d8a74ab1430152878b13bfbdbd007
@@ -0,0 +1,117 @@
+#!/sbin/runscript
+# Copyright 1999-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# Hacked from openvpn initscript by Ronan Bignaux
+# TODO : manage up/down scripts
+
+VPNDIR=${VPNDIR:-/etc/vpzone}
+VPN=${SVCNAME#*.}
+VPNPID=${VPNPID:-/var/run/vpzone/${VPN}.pid}
+VPNCONF="${VPNDIR}/${VPN}.conf"
+
+USER=$(grep --word-regexp user "${VPNCONF}" | cut -d' ' -f 2)
+GROUP=$(grep --word-regexp group "${VPNCONF}" | cut -d' ' -f 2)
+
+# Check for OpenRC/Baselayout 2 - see bug #270646
+is_openrc() {
+ [ -f /lib/librc.so -o -f /etc/init.d/sysfs -o -f /lib/rc/version ]
+}
+
+#need_babeld() {
+# babel=$(grep --word-regex 'load babeld' "${VPNCONF}")
+# [ x"${babel}" = "xload babeld" ]
+#}
+
+depend() {
+ need localmount net
+ use dns
+ after bootmisc
+}
+
+# will be in net.interface later
+checkconfig() {
+ # Linux has good dynamic tun/tap creation
+ if [ $(uname -s) = "Linux" ] ; then
+ if [ ! -e /dev/net/tun ]; then
+ if ! modprobe tun ; then
+ eerror "TUN/TAP support is not available" \
+ "in this kernel"
+ return 1
+ fi
+ fi
+ if [ -h /dev/net/tun ] && [ -c /dev/misc/net/tun ]; then
+ ebegin "Detected broken /dev/net/tun symlink, fixing..."
+ rm -f /dev/net/tun
+ ln -s /dev/misc/net/tun /dev/net/tun
+ eend $?
+ fi
+ return 0
+ fi
+
+ # Other OS's don't, so we rely on a pre-configured interface
+ # per vpn instance
+ local ifname=$(sed -n -e 's/[[:space:]]*device[[:space:]][[:space:]]*\([^[:space:]]*\).*/\1/p' "${VPNCONF}")
+ if [ -z ${ifname} ] ; then
+ eerror "You need to specify the interface that this vpzone" \
+ "instance should use" \
+ "by using the device option in ${VPNCONF}"
+ return 1
+ fi
+
+ if ! ifconfig "${ifname}" >/dev/null 2>/dev/null ; then
+ # Try and create it
+ echo > /dev/"${ifname}" >/dev/null
+ fi
+ if ! ifconfig "${ifname}" >/dev/null 2>/dev/null ; then
+ eerror "${VPNCONF} requires interface ${ifname}" \
+ "but that does not exist"
+ return 1
+ fi
+}
+
+start() {
+
+ if is_openrc; then
+ logfile=${logfile:-/var/log/vpzone/${VPN}.log}
+ logfile_opt=""
+ if [ -n "${logfile}" ]; then
+ logfile_opt="--stdout ${logfile} --stderr ${logfile}"
+ fi
+ if [ ! -f ${logfile} ]; then
+ einfo "No ${logfile} around. Creating new..."
+ touch ${logfile}
+ chown ${USER}:${GROUP} ${logfile}
+ fi
+ fi
+
+
+ ebegin "Starting ${SVCNAME}"
+
+ checkconfig || return 1
+
+ # /!\ we use --background still vpzone -d option make it fork() so pidfile is wrong, and vpzone verbose on console.
+ start-stop-daemon --start --pidfile "${VPNPID}" ${logfile_opt} \
+ --make-pidfile --background --exec /usr/bin/vpzone -- -f "${VPNCONF}"
+
+ #if need_babeld; then
+ # /etc/init.d/babeld.${VPN} restart
+ #fi
+
+ eend $? "Check your logs to see why startup failed"
+}
+
+
+stop() {
+ ebegin "Stopping ${SVCNAME}"
+ start-stop-daemon --stop --quiet --pidfile "${VPNPID}"
+ if [ -f /var/run/vpzone/babeld.${VPN}.pid ]; then
+ einfo "Stopping ${VPN} babeld instance."
+ start-stop-daemon --stop --quiet --pidfile /var/run/vpzone/babeld.${VPN}.pid
+ fi
+ #if need_babeld; then
+ # /etc/init.d/babeld.${VPN} stop
+ #fi
+ eend $?
+}
+
+# vim: set ts=4 :
@@ -65,6 +65,9 @@ src_install() {
dodir /etc/vpzone
keepdir /etc/vpzone
+ # Install the init script
+ newinitd "${FILESDIR}/${PN}.init" vpzone
+
keepdir /var/run/vpzone/
fperms 0750 /var/run/vpzone/
fowners root:vpzone /var/run/vpzone/
@@ -73,3 +76,22 @@ src_install() {
fperms 0750 /var/log/vpzone/
fowners root:vpzone /var/log/vpzone/
}
+
+pkg_postinst() {
+
+ einfo "The vpzone init script expects to find the configuration file"
+ einfo "vpzone.conf in /etc/vpzone along with any extra files it may need."
+ einfo ""
+ einfo "To create more VPNs, simply create a new .conf file for it and"
+ einfo "then create a symlink to the vpzone init script from a link called"
+ einfo "vpzone.newconfname - like so"
+ einfo " cd /etc/vpzone"
+ einfo " ${EDITOR##*/} foo.conf"
+ einfo " cd /etc/init.d"
+ einfo " ln -s vpzone vpzone.foo"
+ einfo ""
+ einfo "You can then treat vpzone.foo as any other service, so you can"
+ einfo "stop one vpn and start another if you need to."
+ einfo "To run as non-root, add yourself to the vpzone group:"
+ einfo " gpasswd -a <user> vpzone"
+}

0 comments on commit 37fa66e

Please sign in to comment.