Skip to content

Instantly share code, notes, and snippets.

@kacchan822
Created January 25, 2016 14:25
Show Gist options
  • Save kacchan822/98cfb045f2b6dede8ee1 to your computer and use it in GitHub Desktop.
Save kacchan822/98cfb045f2b6dede8ee1 to your computer and use it in GitHub Desktop.
SoftEther VPN Client for Ubuntu /etc/init.d/vpnclient
#!/bin/bash
### BEGIN INIT INFO
# Provides: vpnclient
# Required-Start: $all
# Required-Stop: $network $local_fs $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SoftEther VPN Client
# chkconfig: 2345 99 1
# description: SoftEther VPN Client
### END INIT INFO
DAEMON="/usr/local/vpnclient/vpnclient"
VPNUP=`ps -ef | grep vpnclient | grep -v grep | wc -l`
VPNNAME="vpn_vpn2"
DEFROUTE="192.0.2.1"
NEWDEFROUTE="198.51.100.254"
SERVER="203.0.113.55"
test -x $DAEMON || exit 0
case "$1" in
start)
if [ $VPNUP = 0 ]; then
$DAEMON start
VPNLINK=`ip -4 -o addr | grep -c vpn_`
while [ $VPNLINK = 0 ]
do
echo "Waiting for startup vlan up..."
sleep 1
VPNLINK=`ip -4 -o addr | grep -c vpn_`
done
ip route add $SERVER via $DEFROUTE dev eth0
ip route replace default via $NEWDEFROUTE dev $VPNNAME
else
echo "VPN Client has already started!"
exit 1
fi
;;
stop)
if [ $VPNUP = 0 ]; then
echo "VPN client has already stoped"
exit 1
else
ip route del $SERVER via $DEFROUTE dev eth0
ip route replace default via $DEFROUTE dev eth0
$DAEMON stop
fi
;;
restart)
$0 stop
sleep 3
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment