Init (wip)

This commit is contained in:
Julien VAUBOURG
2014-11-04 22:58:46 +01:00
parent 356018a4cc
commit de71fd2c81
5 changed files with 319 additions and 0 deletions

33
conf/client.conf.tpl Normal file
View File

@@ -0,0 +1,33 @@
remote <TPL:SERVER_NAME>
# proto [ udp6 | udp | tcp6-client | tcp-client ]
proto <TPL:PROTO>
pull
nobind
dev tun
tun-ipv6
keepalive 10 30
comp-lzo adaptive
# UDP only
<TPL:UDP_COMMENT>mssfix
<TPL:UDP_COMMENT>fragment 1300
<TPL:UDP_COMMENT>explicit-exit-notify
# TLS
tls-client
remote-cert-tls server
cert /etc/openvpn/keys/user.crt
key /etc/openvpn/keys/user.key
ca /etc/openvpn/keys/ca-server.crt
# Logs
verb 3
mute 5
status /var/log/openvpn-client.status
log-append /var/log/openvpn-client.log
# Routing
route-ipv6 2000::/3
redirect-gateway def1 bypass-dhcp

125
conf/ynh-vpnclient Normal file
View File

@@ -0,0 +1,125 @@
#!/bin/bash
### BEGIN INIT INFO
# Provides: ynh-vpnclient
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VPN client.
# Description: Start VPN client.
### END INIT INFO
has_nativeip6() {
ip -6 r | grep -q default\ via
}
is_ip6addr_set() {
yunohost app list -f hotspot --json | grep -q '"installed": true'\
|| ip a s dev tun0 | grep -q <TPL:IP6_ADDR>/128
}
is_ip6interco_set() {
ip -6 r | grep -q <TPL:IP6_INTERCO>/
}
is_openvpn_running() {
service openvpn status &> /dev/null
}
is_running() {
((has_nativeip6 && is_ip6interco_set) || ! has_nativeip6) && is_openvpn_running
}
gw6=$(ip -6 r | grep default\ via | awk '{ print $3 }')
case "$1" in
start)
if is_running; then
echo "Already correctly set"
else
if ! is_openvpn_running; then
echo "Run openvpn"
proto=udp
[ ! -z "${gw6}" ] && proto=udp6
sed "s|<TPL:PROTO>|${proto}|" /etc/openvpn/client.conf.tpl > /etc/openvpn/client.conf
sed 's|^<TPL:UDP_COMMENT>||' -i /etc/openvpn/client.conf
service openvpn start
false || while [ $? -ne 0 ]; do
sleep 1
ip l sh dev tun0 &> /dev/null
done
sleep 2
fi
if has_nativeip6 && ! is_ip6interco_set; then
echo "Set IPv6 interco route"
ip r a <TPL:IP6_INTERCO>/128 via ${gw6} dev <TPL:WIRED_DEVICE>
fi
if ! is_ip6addr_set; then
echo "Set IPv6 address"
ip a a <TPL:IP6_ADDR>/128 dev tun0
fi
fi
;;
stop)
if is_ip6addr_set; then
echo "Unset IPv6 address"
ip a d <TPL:IP6_ADDR>/128 dev tun0
fi
if is_ip6interco_set; then
echo "Unset IPv6 interco route"
ip r d <TPL:IP6_INTERCO>/128 via ${gw6} dev <TPL:WIRED_DEVICE>
fi
if is_openvpn_running; then
echo "Stop openvpn"
service openvpn stop
fi
;;
restart)
$0 stop
$0 start
;;
status)
exitcode=0
if is_ip6addr_set; then
echo "IPv6 address is correctly set"
else
echo "IPv6 address is NOT set"
exitcode=1
fi
if has_nativeip6; then
if is_ip6interco_set; then
echo "IPv6 interco route is correctly set"
else
echo "IPv6 interco route is NOT set"
exitcode=1
fi
else
echo "No native IPv6 detected"
fi
if is_openvpn_running; then
echo "Openvpn is running"
else
echo "Openvpn is NOT running"
exitcode=1
fi
exit ${exitcode}
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0