Created
June 26, 2015 04:04
-
-
Save perenecabuto/78fd098f9bb5e868091e to your computer and use it in GitHub Desktop.
vpnc-connect.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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