2015-07-31 00:55:23 +00:00
|
|
|
#!/sbin/openrc-run
|
|
|
|
# Copyright 1999-2015 Gentoo Foundation
|
2015-02-27 00:58:55 +00:00
|
|
|
# Distributed under the terms of the GNU General Public License v2
|
2015-07-31 00:55:23 +00:00
|
|
|
# $Header: /var/cvsroot/gentoo-x86/net-misc/openconnect/files/openconnect.init.in-r4,v 1.2 2015/05/19 01:36:39 floppym Exp $
|
2015-02-27 00:58:55 +00:00
|
|
|
|
|
|
|
VPN="${RC_SVCNAME#*.}"
|
2015-07-31 00:55:23 +00:00
|
|
|
VPNDIR="/etc/openconnect/${VPN}"
|
2015-02-27 00:58:55 +00:00
|
|
|
VPNLOG="/var/log/openconnect/${VPN}"
|
|
|
|
VPNLOGFILE="${VPNLOG}/openconnect.log"
|
|
|
|
VPNERRFILE="${VPNLOG}/openconnect.err"
|
2015-07-31 00:55:23 +00:00
|
|
|
|
|
|
|
command="/usr/sbin/openconnect"
|
|
|
|
name="OpenConnect: ${VPN}"
|
|
|
|
pidfile="/run/openconnect/${VPN}.pid"
|
|
|
|
stopsig="SIGINT"
|
2015-02-27 00:58:55 +00:00
|
|
|
|
|
|
|
depend() {
|
|
|
|
before netmount
|
|
|
|
}
|
|
|
|
|
|
|
|
checkconfig() {
|
|
|
|
if [ $VPN = "openconnect" ]; then
|
|
|
|
eerror "You cannot call openconnect directly. You must create a symbolic link to it with the vpn name:"
|
2015-07-31 00:55:23 +00:00
|
|
|
eerror
|
2015-02-27 00:58:55 +00:00
|
|
|
eerror "ln -s /etc/init.d/openconnect /etc/init.d/openconnect.vpn0"
|
2015-07-31 00:55:23 +00:00
|
|
|
eerror
|
2015-02-27 00:58:55 +00:00
|
|
|
eerror "And then call it instead:"
|
2015-07-31 00:55:23 +00:00
|
|
|
eerror
|
2015-02-27 00:58:55 +00:00
|
|
|
eerror "/etc/init.d/openconnect.vpn0 start"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
checktuntap() {
|
2015-07-31 00:55:23 +00:00
|
|
|
if [ "$RC_UNAME" = "Linux" -a ! -e /dev/net/tun ] ; then
|
|
|
|
if ! modprobe tun ; then
|
|
|
|
eerror "TUN/TAP support is not available in this kernel"
|
|
|
|
return 1
|
2015-02-27 00:58:55 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:55:23 +00:00
|
|
|
run_hook() {
|
|
|
|
if [ -x "$1" ]; then
|
|
|
|
"$@"
|
2015-02-27 00:58:55 +00:00
|
|
|
fi
|
2015-07-31 00:55:23 +00:00
|
|
|
}
|
2015-02-27 00:58:55 +00:00
|
|
|
|
2015-07-31 00:55:23 +00:00
|
|
|
start_pre() {
|
|
|
|
checkconfig || return
|
|
|
|
checktuntap || return
|
|
|
|
checkpath -d "${VPNLOG}" || return
|
|
|
|
checkpath -d /run/openconnect || return
|
|
|
|
run_hook "${VPNDIR}/preup.sh"
|
|
|
|
}
|
2015-02-27 00:58:55 +00:00
|
|
|
|
2015-07-31 00:55:23 +00:00
|
|
|
start() {
|
|
|
|
local server vpnopts password
|
|
|
|
eval server=\$server_${VPN}
|
|
|
|
eval vpnopts=\$vpnopts_${VPN}
|
|
|
|
eval password=\$password_${VPN}
|
2015-02-27 00:58:55 +00:00
|
|
|
|
2015-07-31 00:55:23 +00:00
|
|
|
ebegin "Starting ${name}"
|
|
|
|
start-stop-daemon --start --exec "${command}" -- \
|
2015-02-27 00:58:55 +00:00
|
|
|
--background \
|
2015-07-31 00:55:23 +00:00
|
|
|
--interface="${VPN}" \
|
|
|
|
--pid-file="${pidfile}" \
|
|
|
|
${vpnopts} \
|
|
|
|
"${server}" \
|
|
|
|
>> "${VPNLOGFILE}" \
|
|
|
|
2>> "${VPNERRFILE}" \
|
|
|
|
<<EOF
|
|
|
|
${password}
|
|
|
|
EOF
|
2015-02-27 00:58:55 +00:00
|
|
|
eend $?
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:55:23 +00:00
|
|
|
start_post() {
|
|
|
|
run_hook "${VPNDIR}/postup.sh"
|
|
|
|
}
|
2015-02-27 00:58:55 +00:00
|
|
|
|
2015-07-31 00:55:23 +00:00
|
|
|
stop_pre() {
|
|
|
|
checkconfig || return
|
|
|
|
run_hook "${VPNDIR}/predown.sh"
|
|
|
|
}
|
2015-02-27 00:58:55 +00:00
|
|
|
|
2015-07-31 00:55:23 +00:00
|
|
|
stop_post() {
|
|
|
|
run_hook "${VPNDIR}/postdown.sh"
|
2015-02-27 00:58:55 +00:00
|
|
|
}
|