Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sangyye
Created October 21, 2011 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sangyye/1304114 to your computer and use it in GitHub Desktop.
Save sangyye/1304114 to your computer and use it in GitHub Desktop.
A fast and simple multi VPN-Client for the cli
#!/bin/bash
confdir='/home/abakus/.openvpn'
function start_vpn()
{
if [ ! -e /var/run/openvpn.pid ] ; then
openvpn --daemon --writepid /var/run/openvpn.pid --cd $2/$1 --script-security 2 --config $2/$1/*.conf
else
return 1
fi
}
function stop_vpn()
{
if [ -e /var/run/openvpn.pid ] ; then
kill -SIGTERM `cat /var/run/openvpn.pid`
rm -f /var/run/openvpn.pid
else
return 1
fi
}
function toggle()
{
if [ -e /var/run/openvpn.pid ] ; then
stop_vpn
else
start_vpn $1 $2
fi
}
[ -d $confdir/$1 ] || echo "Profile doesn't exist"
if [ $2 ]; then
choice=$2
else
choice='toggle'
fi
case $choice in
start)
start_vpn $1 $confdir || echo "Already up"
;;
stop)
stop_vpn || echo "Not up"
;;
*)
toggle $1 $confdir
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment