Skip to content

Commit 33da515

Browse files
fix: support old VPN config names in post & pre install scripts (#134)
One thing I noticed as part of my work on #121 is that our attempted fix introduced in #92 wasn't working as expected if the user had a VPN configuration installed before #86. This PR fetches the unique name of the VPN service dynamically, as part of the script, such that the service is started and stopped regardless of whether the service is called "Coder" or the older "CoderVPN". This also ensures we don't break it again if we ever change that name, such as to "Coder Connect" (I don't totally recall why it was set to "Coder", but I don't mind it)
1 parent afd9634 commit 33da515

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

pkgbuild/scripts/postinstall

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ VPN_MARKER_FILE="/tmp/coder_vpn_was_running"
66
# Before this script, or the user, opens the app, make sure
77
# Gatekeeper has ingested the notarization ticket.
88
spctl -avvv "/Applications/Coder Desktop.app"
9-
# spctl can't assess non-apps, so this will always return a non-zero exit code,
10-
# but the error message implies at minimum the signature of the extension was
11-
# checked.
9+
# spctl can't assess non-apps, so this will always return a non-zero exit code,
10+
# but the error message implies at minimum the signature of the extension was
11+
# checked.
1212
spctl -avvv "/Applications/Coder Desktop.app/Contents/Library/SystemExtensions/com.coder.Coder-Desktop.VPN.systemextension" || true
1313

1414
# Restart Coder Desktop if it was running before
@@ -24,7 +24,7 @@ if [ -f "$VPN_MARKER_FILE" ]; then
2424
echo "Restarting CoderVPN..."
2525
echo "Sleeping for 3..."
2626
sleep 3
27-
scutil --nc start "Coder"
27+
scutil --nc start "$(scutil --nc list | grep "com.coder.Coder-Desktop" | awk -F'"' '{print $2}')"
2828
rm "$VPN_MARKER_FILE"
2929
echo "CoderVPN started."
3030
fi

pkgbuild/scripts/preinstall

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@ if pgrep 'Coder Desktop'; then
99
touch $RUNNING_MARKER_FILE
1010
fi
1111

12+
vpn_name=$(scutil --nc list | grep "com.coder.Coder-Desktop" | awk -F'"' '{print $2}')
13+
1214
echo "Turning off VPN"
13-
if scutil --nc list | grep -q "Coder"; then
15+
if [[ -n "$vpn_name" ]]; then
1416
echo "CoderVPN found. Stopping..."
15-
if scutil --nc status "Coder" | grep -q "^Connected$"; then
17+
if scutil --nc status "$vpn_name" | grep -q "^Connected$"; then
1618
touch $VPN_MARKER_FILE
1719
fi
18-
scutil --nc stop "Coder"
20+
scutil --nc stop "$vpn_name"
1921

2022
# Wait for VPN to be disconnected
21-
while scutil --nc status "Coder" | grep -q "^Connected$"; do
23+
while scutil --nc status "$vpn_name" | grep -q "^Connected$"; do
2224
echo "Waiting for VPN to disconnect..."
2325
sleep 1
2426
done
25-
while scutil --nc status "Coder" | grep -q "^Disconnecting$"; do
27+
while scutil --nc status "$vpn_name" | grep -q "^Disconnecting$"; do
2628
echo "Waiting for VPN to complete disconnect..."
2729
sleep 1
2830
done

0 commit comments

Comments
 (0)