forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpn-start.sh
executable file
·47 lines (36 loc) · 1.04 KB
/
vpn-start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Connect
# @raycast.mode compact
# Optional parameters:
# @raycast.icon 📡
# @Documentation:
# @raycast.packageName VPN
# @raycast.description Start VPN connection.
# @raycast.author Alexandru Turcanu
# @raycast.authorURL https://github.com/Pondorasti
source vpn-config.sh
VPN=$VPN_NAME
# Source: https://superuser.com/a/736859
function isnt_connected () {
scutil --nc status "$VPN" | sed -n 1p | grep -qv Connected
}
function poll_until_connected () {
let loops=0 || true
let max_loops=200 # 200 * 0.1 is 20 seconds. Bash doesn't support floats
while isnt_connected "$VPN"; do
sleep 0.1 # can't use a variable here, bash doesn't have floats
let loops=$loops+1
[ $loops -gt $max_loops ] && break
done
[ $loops -le $max_loops ]
}
networksetup -connectpppoeservice "$VPN"
if poll_until_connected "$VPN"; then
echo "Connected to $VPN!"
else
echo "Couldn't connect to $VPN"
scutil --nc stop "$VPN"
exit 1;
fi