Skip to content

Instantly share code, notes, and snippets.

@perenecabuto
Created June 26, 2015 04:04
Show Gist options
  • Save perenecabuto/78fd098f9bb5e868091e to your computer and use it in GitHub Desktop.
Save perenecabuto/78fd098f9bb5e868091e to your computer and use it in GitHub Desktop.
vpnc-connect.sh
#!/usr/bin/env bash
lastdata="$HOME/.$(basename $0).db"
lastgateway="$(sed '1q;d' $lastdata)"
lastgroup="$(sed '2q;d' $lastdata)"
lastsecret="$(sed '3q;d' $lastdata)"
lastusername="$(sed '4q;d' $lastdata)"
echo -ne "gateway ($lastgateway): "
read gateway
echo -ne "group ($lastgroup): "
read group
echo -ne "secret ($lastsecret): "
read secret
echo -ne "username ($lastusername): "
read username
echo -ne "password: "
read -s password
echo
if [ -z "$gateway" ]; then
gateway="$lastgateway"
fi
if [ -z "$group" ]; then
group="$lastgroup"
fi
if [ -z "$secret" ]; then
secret="$lastsecret"
fi
if [ -z "$username" ]; then
username="$lastusername"
fi
cat >$lastdata <<EOF
$gateway
$group
$secret
$username
EOF
credentials=$(cat <<EOF
IPSec gateway $gateway
IPSec ID $group
IPSec secret $secret
Xauth username $username
Xauth password $password
EOF
)
killall -9 vpnc
vpnc <(echo "$credentials")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment