-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpreinstall
executable file
·47 lines (38 loc) · 1.21 KB
/
preinstall
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
#!/usr/bin/env bash
RUNNING_MARKER_FILE="/tmp/coder_desktop_running"
VPN_MARKER_FILE="/tmp/coder_vpn_was_running"
rm $VPN_MARKER_FILE $RUNNING_MARKER_FILE || true
if pgrep 'Coder Desktop'; then
touch $RUNNING_MARKER_FILE
fi
vpn_name=$(scutil --nc list | grep "com.coder.Coder-Desktop" | awk -F'"' '{print $2}')
echo "Turning off VPN"
if [[ -n "$vpn_name" ]]; then
echo "CoderVPN found. Stopping..."
if scutil --nc status "$vpn_name" | grep -q "^Connected$"; then
touch $VPN_MARKER_FILE
fi
scutil --nc stop "$vpn_name"
# Wait for VPN to be disconnected
while scutil --nc status "$vpn_name" | grep -q "^Connected$"; do
echo "Waiting for VPN to disconnect..."
sleep 1
done
while scutil --nc status "$vpn_name" | grep -q "^Disconnecting$"; do
echo "Waiting for VPN to complete disconnect..."
sleep 1
done
else
echo "CoderVPN not found. Nothing to stop."
fi
echo "Done."
echo "Asking com.coder.Coder-Desktop to quit..."
osascript -e 'if app id "com.coder.Coder-Desktop" is running then' -e 'quit app id "com.coder.Coder-Desktop"' -e 'end if'
echo "Done."
APP="/Applications/Coder Desktop.app"
if [ -d "$APP" ]; then
echo "Deleting Coder Desktop..."
rm -rf "$APP"
echo "Done."
fi
exit 0