-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpostinstall
More file actions
executable file
·43 lines (36 loc) · 1.94 KB
/
postinstall
File metadata and controls
executable file
·43 lines (36 loc) · 1.94 KB
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
#!/usr/bin/env bash
RUNNING_MARKER_FILE="/tmp/coder_desktop_running"
LAUNCH_DAEMON_PLIST_SRC="/Applications/Coder Desktop.app/Contents/Library/LaunchDaemons"
LAUNCH_DAEMON_PLIST_DEST="/Library/LaunchDaemons"
LAUNCH_DAEMON_NAME="com.coder.Coder-Desktop.Helper"
LAUNCH_DAEMON_PLIST_NAME="$LAUNCH_DAEMON_NAME.plist"
LAUNCH_DAEMON_BINARY_PATH="/Applications/Coder Desktop.app/Contents/MacOS/com.coder.Coder-Desktop.Helper"
# Install daemon
# Copy plist into system dir
sudo cp "$LAUNCH_DAEMON_PLIST_SRC"/"$LAUNCH_DAEMON_PLIST_NAME" "$LAUNCH_DAEMON_PLIST_DEST"/"$LAUNCH_DAEMON_PLIST_NAME"
# Set necessary permissions
sudo chmod 755 "$LAUNCH_DAEMON_BINARY_PATH"
sudo chmod 644 "$LAUNCH_DAEMON_PLIST_DEST"/"$LAUNCH_DAEMON_PLIST_NAME"
sudo chown root:wheel "$LAUNCH_DAEMON_PLIST_DEST"/"$LAUNCH_DAEMON_PLIST_NAME"
# Load daemon
sudo launchctl enable "system/$LAUNCH_DAEMON_NAME" || true # Might already be enabled
sudo launchctl bootstrap system "$LAUNCH_DAEMON_PLIST_DEST/$LAUNCH_DAEMON_PLIST_NAME"
sudo launchctl kickstart -k "system/$LAUNCH_DAEMON_NAME"
# Before this script, or the user, opens the app, make sure
# Gatekeeper has ingested the notarization ticket.
spctl -avvv "/Applications/Coder Desktop.app"
# spctl can't assess non-apps, so this will always return a non-zero exit code,
# but the error message implies at minimum the signature of the extension was
# checked.
spctl -avvv "/Applications/Coder Desktop.app/Contents/Library/SystemExtensions/com.coder.Coder-Desktop.VPN.systemextension" || true
# Restart Coder Desktop if it was running before
if [ -f "$RUNNING_MARKER_FILE" ]; then
echo "Starting Coder Desktop..."
# When deploying the app via MDM, this script runs as root. The app cannot
# function properly when launched as root.
currentUser=$(/usr/bin/stat -f "%Su" /dev/console)
/bin/launchctl asuser "$( /usr/bin/id -u "$currentUser")" /usr/bin/open "/Applications/Coder Desktop.app"
rm "$RUNNING_MARKER_FILE"
echo "Coder Desktop started."
fi
exit 0