|
| 1 | +# This script operates like postinstall + preinstall, but for local development |
| 2 | +# builds, where the helper is necessary. Instead of looking for |
| 3 | +# /Applications/Coder Desktop.app, it looks for |
| 4 | +# /Applications/Coder/Coder Desktop.app, which is where the local build is |
| 5 | +# installed. |
| 6 | + |
| 7 | +set -euox pipefail |
| 8 | + |
| 9 | +LAUNCH_DAEMON_PLIST_SRC="/Applications/Coder/Coder Desktop.app/Contents/Library/LaunchDaemons" |
| 10 | +LAUNCH_DAEMON_PLIST_DEST="/Library/LaunchDaemons" |
| 11 | +LAUNCH_DAEMON_NAME="com.coder.Coder-Desktop.Helper" |
| 12 | +LAUNCH_DAEMON_PLIST_NAME="$LAUNCH_DAEMON_NAME.plist" |
| 13 | +LAUNCH_DAEMON_BINARY_PATH="/Applications/Coder/Coder Desktop.app/Contents/MacOS/com.coder.Coder-Desktop.Helper" |
| 14 | + |
| 15 | +# Stop an existing launch daemon, if it exists |
| 16 | +sudo launchctl bootout"system/$LAUNCH_DAEMON_NAME"2>/dev/null||true |
| 17 | + |
| 18 | +# Install daemon |
| 19 | +# Copy plist into system dir, with the path corrected to the local build |
| 20 | +sed's|/Applications/Coder Desktop\.app|/Applications/Coder/Coder Desktop.app|g'"$LAUNCH_DAEMON_PLIST_SRC"/"$LAUNCH_DAEMON_PLIST_NAME"| sudo tee"$LAUNCH_DAEMON_PLIST_DEST"/"$LAUNCH_DAEMON_PLIST_NAME">/dev/null |
| 21 | +# Set necessary permissions |
| 22 | +sudo chmod -R 755"$LAUNCH_DAEMON_BINARY_PATH" |
| 23 | +sudo chmod 644"$LAUNCH_DAEMON_PLIST_DEST"/"$LAUNCH_DAEMON_PLIST_NAME" |
| 24 | +sudo chown root:wheel"$LAUNCH_DAEMON_PLIST_DEST"/"$LAUNCH_DAEMON_PLIST_NAME" |
| 25 | + |
| 26 | +# Load daemon |
| 27 | +sudo launchctlenable"system/$LAUNCH_DAEMON_NAME"||true# Might already be enabled |
| 28 | +sudo launchctl bootstrap system"$LAUNCH_DAEMON_PLIST_DEST/$LAUNCH_DAEMON_PLIST_NAME" |
| 29 | +sudo launchctl kickstart -k"system/$LAUNCH_DAEMON_NAME" |
| 30 | + |