From 6bed50f44da6ede7e7c365ccb7a9fd9d06461224 Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 18:02:28 -0800 Subject: [PATCH] Updated vpnup check for existing config to account for viscosity --- scripts/ec2gaming-vpnup.sh | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/scripts/ec2gaming-vpnup.sh b/scripts/ec2gaming-vpnup.sh index fa86998..0ca1909 100755 --- a/scripts/ec2gaming-vpnup.sh +++ b/scripts/ec2gaming-vpnup.sh @@ -4,15 +4,29 @@ source "$(dirname "$0")/ec2gaming.header" echo -n "Connecting VPN (you may see an authentication prompt)... " IP=$(./ec2gaming-ip.sh) AUTH=$(realpath "$(pwd)/../ec2gaming.auth") -BACKING_CONFIG=~/Library/Application\ Support/Tunnelblick/Configurations/ec2gaming.tblk/Contents/Resources/config.ovpn -if [ ! -f "$BACKING_CONFIG" ]; then +CONFIG_EXISTS=0 + +# Find if config exists +if [ "$VPN_CLIENT" = "tunnelblick" ]; then + BACKING_CONFIG=~/Library/Application\ Support/Tunnelblick/Configurations/ec2gaming.tblk/Contents/Resources/config.ovpn + if [ -f "$BACKING_CONFIG" ]; then + CONFIG_EXISTS=1 + # the authentication prompt on copy will block, avoids the messy sleep + sed "s#IP#$IP#g;s#AUTH#$AUTH#g" ec2gaming.ovpn.template > "$BACKING_CONFIG" + fi +elif [ "$VPN_CLIENT" = "viscosity" ]; then + grep -R ec2gaming ~/Library/Application\ Support/Viscosity/OpenVPN > /dev/null + if [ $? -eq 0 ]; then + CONFIG_EXISTS=1 + fi +fi + +# Create config if needed +if [ $CONFIG_EXISTS -eq 0 ]; then sed "s#IP#$IP#g;s#AUTH#$AUTH#g" ec2gaming.ovpn.template > ec2gaming.ovpn open ec2gaming.ovpn echo "Waiting 10 seconds for import..." sleep 10 -else - # the authentication prompt on copy will block, avoids the messy sleep - sed "s#IP#$IP#g;s#AUTH#$AUTH#g" ec2gaming.ovpn.template > "$BACKING_CONFIG" fi osascript "ec2gaming-vpnup.$VPN_CLIENT.scpt"