Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Viscosity #13

Merged
merged 14 commits into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ec2gaming.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
INSTANCE_TYPE="g2.2xlarge"
SPOT_PRICE_BUFFER="0.10"
VPN_CLIENT="tunnelblick"
2 changes: 1 addition & 1 deletion scripts/ec2gaming-vpndown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source "$(dirname "$0")/ec2gaming.header"

echo -n "Disconnecting VPN... "
osascript ec2gaming-vpndown.scpt
osascript "ec2gaming-vpndown.$VPN_CLIENT.scpt"
9 changes: 9 additions & 0 deletions scripts/ec2gaming-vpndown.viscosity.scpt
Original file line number Diff line number Diff line change
@@ -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
28 changes: 21 additions & 7 deletions scripts/ec2gaming-vpnup.sh
Original file line number Diff line number Diff line change
@@ -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"
File renamed without changes.
11 changes: 11 additions & 0 deletions scripts/ec2gaming-vpnup.viscosity.scpt
Original file line number Diff line number Diff line change
@@ -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