From a157ba6a1e5e7b53ca025c3bce10919d8f0cbde9 Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 15:58:51 -0800 Subject: [PATCH 01/13] Added VPN_CLIENT to cfg defaulting to tunnelblick --- ec2gaming.cfg | 1 + 1 file changed, 1 insertion(+) 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" From d41f78005f9474857fd0a9c350f2d4cb845e42ef Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 16:14:14 -0800 Subject: [PATCH 02/13] Moved default scripts to include tunnelblick in path --- ...{ec2gaming-vpndown.scpt => ec2gaming-vpndown.tunnelblick.scpt} | 0 .../{ec2gaming-vpnup.scpt => ec2gaming-vpnup.tunnelblick.scpt} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename scripts/{ec2gaming-vpndown.scpt => ec2gaming-vpndown.tunnelblick.scpt} (100%) rename scripts/{ec2gaming-vpnup.scpt => ec2gaming-vpnup.tunnelblick.scpt} (100%) 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-vpnup.scpt b/scripts/ec2gaming-vpnup.tunnelblick.scpt similarity index 100% rename from scripts/ec2gaming-vpnup.scpt rename to scripts/ec2gaming-vpnup.tunnelblick.scpt From 3d569d02547f264186a52d36ba1b26a95ed4044e Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 16:14:38 -0800 Subject: [PATCH 03/13] Updated vpn up/down shell scripts to include VPN_CLIENT --- scripts/ec2gaming-vpndown.sh | 2 +- scripts/ec2gaming-vpnup.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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-vpnup.sh b/scripts/ec2gaming-vpnup.sh index 341722d..fa86998 100755 --- a/scripts/ec2gaming-vpnup.sh +++ b/scripts/ec2gaming-vpnup.sh @@ -15,4 +15,4 @@ else 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" From 3a28ae033b63d64e3ed2a4acb25a16b493725e05 Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 16:14:52 -0800 Subject: [PATCH 04/13] Initial commit of viscosity applescript --- scripts/ec2gaming-vpnup.viscosity.scpt | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 scripts/ec2gaming-vpnup.viscosity.scpt diff --git a/scripts/ec2gaming-vpnup.viscosity.scpt b/scripts/ec2gaming-vpnup.viscosity.scpt new file mode 100644 index 0000000..77bfa9b --- /dev/null +++ b/scripts/ec2gaming-vpnup.viscosity.scpt @@ -0,0 +1,8 @@ +tell application "Viscosity" + connect (connections where name is "ec2gaming") + set currentState to state of connections where name is "ec2gaming" + repeat until currentState = "Connected" + delay 1 + set currentState to state of connections where name is "ec2gaming" + end repeat +end tell From 81844e30a6af40642d1fc12b89d08bb4ec2ea36b Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 16:17:39 -0800 Subject: [PATCH 05/13] Initial commit of viscosity applescript vpndown --- scripts/ec2gaming-vpndown.viscosity.scpt | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 scripts/ec2gaming-vpndown.viscosity.scpt diff --git a/scripts/ec2gaming-vpndown.viscosity.scpt b/scripts/ec2gaming-vpndown.viscosity.scpt new file mode 100644 index 0000000..b01e013 --- /dev/null +++ b/scripts/ec2gaming-vpndown.viscosity.scpt @@ -0,0 +1,8 @@ +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" + end repeat +end tell From f7b895470a68f9e411b26ee297ca9cf0e419f522 Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 16:21:31 -0800 Subject: [PATCH 06/13] Cleaner connection attempt with viscosity --- ec2gaming.cfg | 2 +- scripts/ec2gaming-vpnup.viscosity.scpt | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ec2gaming.cfg b/ec2gaming.cfg index d6b39f9..267a88a 100644 --- a/ec2gaming.cfg +++ b/ec2gaming.cfg @@ -1,3 +1,3 @@ INSTANCE_TYPE="g2.2xlarge" SPOT_PRICE_BUFFER="0.10" -VPN_CLIENT="tunnelblick" +VPN_CLIENT="viscosity" diff --git a/scripts/ec2gaming-vpnup.viscosity.scpt b/scripts/ec2gaming-vpnup.viscosity.scpt index 77bfa9b..259da41 100644 --- a/scripts/ec2gaming-vpnup.viscosity.scpt +++ b/scripts/ec2gaming-vpnup.viscosity.scpt @@ -1,8 +1,11 @@ tell application "Viscosity" - connect (connections where name is "ec2gaming") - set currentState to state of connections where name is "ec2gaming" - repeat until currentState = "Connected" - delay 1 + 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 From 2761d541a2b1268d80f63f9358cb52af3df74198 Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 16:22:20 -0800 Subject: [PATCH 07/13] Added same state type doublecheck to viscosity disconnect --- scripts/ec2gaming-vpndown.viscosity.scpt | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/ec2gaming-vpndown.viscosity.scpt b/scripts/ec2gaming-vpndown.viscosity.scpt index b01e013..f240a79 100644 --- a/scripts/ec2gaming-vpndown.viscosity.scpt +++ b/scripts/ec2gaming-vpndown.viscosity.scpt @@ -4,5 +4,6 @@ tell application "Viscosity" 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 From 6bed50f44da6ede7e7c365ccb7a9fd9d06461224 Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 18:02:28 -0800 Subject: [PATCH 08/13] 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" From c4dcdf5415aaa35daf48b48fe6386175df677661 Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 18:04:12 -0800 Subject: [PATCH 09/13] Added \n where there ought be one --- scripts/ec2gaming-vpnup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ec2gaming-vpnup.sh b/scripts/ec2gaming-vpnup.sh index 0ca1909..4122bcf 100755 --- a/scripts/ec2gaming-vpnup.sh +++ b/scripts/ec2gaming-vpnup.sh @@ -25,7 +25,7 @@ fi 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..." + echo "Waiting 10 seconds for import...\n" sleep 10 fi From bd9819ed6e0eb10486c71ad6544f69d5e1fd0e22 Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 18:06:37 -0800 Subject: [PATCH 10/13] Removed \n as lack of newline was caused by something else --- scripts/ec2gaming-vpnup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ec2gaming-vpnup.sh b/scripts/ec2gaming-vpnup.sh index 0ca1909..4122bcf 100755 --- a/scripts/ec2gaming-vpnup.sh +++ b/scripts/ec2gaming-vpnup.sh @@ -25,7 +25,7 @@ fi 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..." + echo "Waiting 10 seconds for import...\n" sleep 10 fi From a480176763a6925763bf03a6f347c0aeb2bd1863 Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 18:07:04 -0800 Subject: [PATCH 11/13] Removed \n as lack of newline was caused by something else --- scripts/ec2gaming-vpnup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ec2gaming-vpnup.sh b/scripts/ec2gaming-vpnup.sh index 4122bcf..0ca1909 100755 --- a/scripts/ec2gaming-vpnup.sh +++ b/scripts/ec2gaming-vpnup.sh @@ -25,7 +25,7 @@ fi 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...\n" + echo "Waiting 10 seconds for import..." sleep 10 fi From 64f0285ad0cfd4fb9410676b9808a5a717ccd43c Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 18:10:05 -0800 Subject: [PATCH 12/13] Removed -n to provide appropriate newline --- scripts/ec2gaming-vpnup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ec2gaming-vpnup.sh b/scripts/ec2gaming-vpnup.sh index 0ca1909..2170a54 100755 --- a/scripts/ec2gaming-vpnup.sh +++ b/scripts/ec2gaming-vpnup.sh @@ -1,7 +1,7 @@ #!/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") CONFIG_EXISTS=0 From f44b963005c8445373d8c9b0725072a4e7d6347f Mon Sep 17 00:00:00 2001 From: Euan Reid Date: Sat, 26 Nov 2016 18:12:37 -0800 Subject: [PATCH 13/13] Set default VPN client to Tunnelblick for backwards compatibility --- ec2gaming.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ec2gaming.cfg b/ec2gaming.cfg index 267a88a..d6b39f9 100644 --- a/ec2gaming.cfg +++ b/ec2gaming.cfg @@ -1,3 +1,3 @@ INSTANCE_TYPE="g2.2xlarge" SPOT_PRICE_BUFFER="0.10" -VPN_CLIENT="viscosity" +VPN_CLIENT="tunnelblick"