diff --git a/ec2gaming.cfg b/ec2gaming.cfg index fdd2049..d6b39f9 100644 --- a/ec2gaming.cfg +++ b/ec2gaming.cfg @@ -1,2 +1,3 @@ INSTANCE_TYPE="g2.2xlarge" SPOT_PRICE_BUFFER="0.10" +VPN_CLIENT="tunnelblick" diff --git a/scripts/ec2gaming-vpndown.sh b/scripts/ec2gaming-vpndown.sh index fcb79f3..5053aff 100755 --- a/scripts/ec2gaming-vpndown.sh +++ b/scripts/ec2gaming-vpndown.sh @@ -2,4 +2,4 @@ source "$(dirname "$0")/ec2gaming.header" echo -n "Disconnecting VPN... " -osascript ec2gaming-vpndown.scpt +osascript "ec2gaming-vpndown.$VPN_CLIENT.scpt" diff --git a/scripts/ec2gaming-vpndown.scpt b/scripts/ec2gaming-vpndown.tunnelblick.scpt similarity index 100% rename from scripts/ec2gaming-vpndown.scpt rename to scripts/ec2gaming-vpndown.tunnelblick.scpt diff --git a/scripts/ec2gaming-vpndown.viscosity.scpt b/scripts/ec2gaming-vpndown.viscosity.scpt new file mode 100644 index 0000000..f240a79 --- /dev/null +++ b/scripts/ec2gaming-vpndown.viscosity.scpt @@ -0,0 +1,9 @@ +tell application "Viscosity" + disconnect (connections where name is "ec2gaming") + set currentState to state of connections where name is "ec2gaming" + repeat until currentState = "Disconnected" + delay 1 + set currentState to state of connections where name is "ec2gaming" + set currentState to currentState as string + end repeat +end tell diff --git a/scripts/ec2gaming-vpnup.sh b/scripts/ec2gaming-vpnup.sh index 341722d..2170a54 100755 --- a/scripts/ec2gaming-vpnup.sh +++ b/scripts/ec2gaming-vpnup.sh @@ -1,18 +1,32 @@ #!/usr/bin/env bash source "$(dirname "$0")/ec2gaming.header" -echo -n "Connecting VPN (you may see an authentication prompt)... " +echo "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.scpt +osascript "ec2gaming-vpnup.$VPN_CLIENT.scpt" diff --git a/scripts/ec2gaming-vpnup.scpt b/scripts/ec2gaming-vpnup.tunnelblick.scpt similarity index 100% rename from scripts/ec2gaming-vpnup.scpt rename to scripts/ec2gaming-vpnup.tunnelblick.scpt diff --git a/scripts/ec2gaming-vpnup.viscosity.scpt b/scripts/ec2gaming-vpnup.viscosity.scpt new file mode 100644 index 0000000..259da41 --- /dev/null +++ b/scripts/ec2gaming-vpnup.viscosity.scpt @@ -0,0 +1,11 @@ +tell application "Viscosity" + set currentState to "Unknown" + repeat until (currentState = "Connected") + if currentState = "Disconnected" then + connect (connections where name is "ec2gaming") + end if + set currentState to state of connections where name is "ec2gaming" + set currentState to currentState as string + delay 1 + end repeat +end tell