Skip to content

Commit

Permalink
Merge pull request #13 from ReidE96/viscosity
Browse files Browse the repository at this point in the history
Added support for Viscosity
  • Loading branch information
DanielThomas authored Dec 6, 2016
2 parents 8cb7929 + f44b963 commit f1e161b
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 8 deletions.
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"
File renamed without changes.
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

0 comments on commit f1e161b

Please sign in to comment.