mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
Wrap $INSTALLER_PATH in quotes when calling realpath to compute TMPDIR to avoid word-splitting for paths containing spaces. Updated the homebrew script builder and multiple installer scripts (dbeaver variants, evernote, github-desktop, grammarly, logi-options-plus, microsoft-edge, omnigraffle, royal-tsx) and bumped the install script refs in firefox and firefox@esr darwin outputs to the updated script. <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #43712 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced Homebrew installation scripts for multiple applications to properly handle installer paths containing spaces and special characters. Affected applications include DBEaver Enterprise, DBEaver Lite, DBEaver Ultimate, Evernote, GitHub Desktop, Grammarly Desktop, Logi Options+, Microsoft Edge, OmniGraffle, Royal TSX, and Firefox. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
94 lines
2.8 KiB
Bash
94 lines
2.8 KiB
Bash
#!/bin/sh
|
|
|
|
# variables
|
|
APPDIR="/Applications/"
|
|
TMPDIR=$(dirname "$(realpath "$INSTALLER_PATH")")
|
|
|
|
# functions
|
|
|
|
quit_and_track_application() {
|
|
local bundle_id="$1"
|
|
local var_name="APP_WAS_RUNNING_$(echo "$bundle_id" | tr '.-' '__')"
|
|
local timeout_duration=10
|
|
|
|
# check if the application is running
|
|
if ! osascript -e "application id \"$bundle_id\" is running" 2>/dev/null; then
|
|
eval "export $var_name=0"
|
|
return
|
|
fi
|
|
|
|
local console_user
|
|
console_user=$(stat -f "%Su" /dev/console)
|
|
if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
|
|
echo "Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'."
|
|
eval "export $var_name=0"
|
|
return
|
|
fi
|
|
|
|
# App was running, mark it for relaunch
|
|
eval "export $var_name=1"
|
|
echo "Application '$bundle_id' was running; will relaunch after installation."
|
|
|
|
echo "Quitting application '$bundle_id'..."
|
|
|
|
# try to quit the application within the timeout period
|
|
local quit_success=false
|
|
SECONDS=0
|
|
while (( SECONDS < timeout_duration )); do
|
|
if osascript -e "tell application id \"$bundle_id\" to quit" >/dev/null 2>&1; then
|
|
if ! pgrep -f "$bundle_id" >/dev/null 2>&1; then
|
|
echo "Application '$bundle_id' quit successfully."
|
|
quit_success=true
|
|
break
|
|
fi
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
if [[ "$quit_success" = false ]]; then
|
|
echo "Application '$bundle_id' did not quit."
|
|
fi
|
|
}
|
|
|
|
relaunch_application() {
|
|
local bundle_id="$1"
|
|
local var_name="APP_WAS_RUNNING_$(echo "$bundle_id" | tr '.-' '__')"
|
|
local was_running
|
|
|
|
# Check if the app was running before installation
|
|
eval "was_running=\$$var_name"
|
|
if [[ "$was_running" != "1" ]]; then
|
|
return
|
|
fi
|
|
|
|
local console_user
|
|
console_user=$(stat -f "%Su" /dev/console)
|
|
if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
|
|
echo "Not logged into a non-root GUI; skipping relaunching application ID '$bundle_id'."
|
|
return
|
|
fi
|
|
|
|
echo "Relaunching application '$bundle_id'..."
|
|
|
|
# Try to launch the application
|
|
if osascript -e "tell application id \"$bundle_id\" to activate" >/dev/null 2>&1; then
|
|
echo "Application '$bundle_id' relaunched successfully."
|
|
else
|
|
echo "Failed to relaunch application '$bundle_id'."
|
|
fi
|
|
}
|
|
|
|
# Extract with ditto and --noqtn so extracted files do NOT get quarantine.
|
|
ditto -xk --noqtn "$INSTALLER_PATH" "$TMPDIR"
|
|
|
|
# copy to the applications folder (do not modify the app bundle after extraction)
|
|
quit_and_track_application 'com.github.GitHubClient'
|
|
if [ -d "$APPDIR/GitHub Desktop.app" ]; then
|
|
sudo mv "$APPDIR/GitHub Desktop.app" "$TMPDIR/GitHub Desktop.app.bkp"
|
|
fi
|
|
sudo cp -R "$TMPDIR/GitHub Desktop.app" "$APPDIR"
|
|
|
|
relaunch_application 'com.github.GitHubClient'
|
|
|
|
mkdir -p .
|
|
/bin/ln -h -f -s -- "$APPDIR/GitHub Desktop.app/Contents/Resources/app/static/github.sh" "github"
|