Support default pkg install script when cask lacks pkg artifact and URL override is used - #45893
Conversation
Support installer_format="pkg" even when the Homebrew cask describes no pkg artifact by installing the downloaded package at $INSTALLER_PATH. Adds caskHasPkgArtifact and InstallPkgFromInstallerPath, and updates installScriptForApp to use quit/track and relaunch helpers around a direct installer call when appropriate. Includes unit tests for both code paths. Removes per-app install script files and clears install_script_path from input JSONs; updates output refs for 1Password, Slack and Zoom to the new consolidated scripts.
Script Diff Resultsee/maintained-apps/outputs/1password/darwin.json=== Install // ef2a17ff -> c8c35fa0 ===
--- /tmp/old.VeacDZ 2026-05-20 15:59:10.675942609 +0000
+++ /tmp/new.MZLoIa 2026-05-20 15:59:10.675942609 +0000
@@ -1,21 +1,35 @@
#!/bin/bash
-quit_application() {
+# 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
+ local app_running
+ app_running=$(osascript -e "application id \"$bundle_id\" is running" 2>/dev/null)
+ if [[ "$app_running" != "true" ]]; 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
+ if [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; 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
@@ -37,5 +51,50 @@
fi
}
-quit_application 'com.1password.1password'
-installer -pkg "$INSTALLER_PATH" -target /
+
+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 [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; then
+ echo "Not logged into a non-root GUI; skipping relaunching application ID '$bundle_id'."
+ return
+ fi
+
+ echo "Relaunching application '$bundle_id'..."
+
+ # Launch the app in the logged-in user's GUI session. Apps launched by root
+ # won't register with the user's Dock/GUI, so run 'open' as the console user.
+ # Use 'launchctl asuser' to bootstrap into the console user's Mach namespace
+ # and GUI session — 'sudo -u' alone doesn't do this, which can cause
+ # LSOpenURLsWithRole() failures even when 'open' exits 0.
+ local open_status=0
+ if [[ $EUID -eq 0 ]]; then
+ local console_uid
+ console_uid=$(id -u "$console_user")
+ /bin/launchctl asuser "$console_uid" sudo -u "$console_user" open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ else
+ open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ fi
+
+ if [[ $open_status -eq 0 ]]; then
+ echo "Application '$bundle_id' relaunched successfully."
+ else
+ echo "Failed to relaunch application '$bundle_id'."
+ fi
+}
+
+
+# install pkg files
+quit_and_track_application 'com.1password.1password'
+sudo installer -pkg "$INSTALLER_PATH" -target /
+relaunch_application 'com.1password.1password'
=== Uninstall Script (no changes) ===ee/maintained-apps/outputs/slack/darwin.json=== Install // 6025885d -> 53397c19 ===
--- /tmp/old.NDMp2O 2026-05-20 15:59:10.735942581 +0000
+++ /tmp/new.OE5m6J 2026-05-20 15:59:10.735942581 +0000
@@ -1,21 +1,35 @@
#!/bin/bash
-quit_application() {
+# 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
+ local app_running
+ app_running=$(osascript -e "application id \"$bundle_id\" is running" 2>/dev/null)
+ if [[ "$app_running" != "true" ]]; 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
+ if [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; 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
@@ -37,5 +51,50 @@
fi
}
-quit_application 'com.tinyspeck.slackmacgap'
-installer -pkg "$INSTALLER_PATH" -target /
+
+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 [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; then
+ echo "Not logged into a non-root GUI; skipping relaunching application ID '$bundle_id'."
+ return
+ fi
+
+ echo "Relaunching application '$bundle_id'..."
+
+ # Launch the app in the logged-in user's GUI session. Apps launched by root
+ # won't register with the user's Dock/GUI, so run 'open' as the console user.
+ # Use 'launchctl asuser' to bootstrap into the console user's Mach namespace
+ # and GUI session — 'sudo -u' alone doesn't do this, which can cause
+ # LSOpenURLsWithRole() failures even when 'open' exits 0.
+ local open_status=0
+ if [[ $EUID -eq 0 ]]; then
+ local console_uid
+ console_uid=$(id -u "$console_user")
+ /bin/launchctl asuser "$console_uid" sudo -u "$console_user" open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ else
+ open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ fi
+
+ if [[ $open_status -eq 0 ]]; then
+ echo "Application '$bundle_id' relaunched successfully."
+ else
+ echo "Failed to relaunch application '$bundle_id'."
+ fi
+}
+
+
+# install pkg files
+quit_and_track_application 'com.tinyspeck.slackmacgap'
+sudo installer -pkg "$INSTALLER_PATH" -target /
+relaunch_application 'com.tinyspeck.slackmacgap'
=== Uninstall Script (no changes) ===ee/maintained-apps/outputs/zoom/darwin.json=== Install // 05e6a85c -> b67a020b ===
--- /tmp/old.h4H9QX 2026-05-20 15:59:10.787942557 +0000
+++ /tmp/new.uG3jZm 2026-05-20 15:59:10.787942557 +0000
@@ -1,15 +1,35 @@
#!/bin/bash
-quit_application() {
+# variables
+APPDIR="/Applications/"
+TMPDIR=$(dirname "$(realpath "$INSTALLER_PATH")")
+# functions
+
+quit_and_track_application() {
local bundle_id="$1"
- local console_user="$2"
+ local var_name="APP_WAS_RUNNING_$(echo "$bundle_id" | tr '.-' '__')"
local timeout_duration=10
- if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
+ # check if the application is running
+ local app_running
+ app_running=$(osascript -e "application id \"$bundle_id\" is running" 2>/dev/null)
+ if [[ "$app_running" != "true" ]]; then
+ eval "export $var_name=0"
+ return
+ fi
+
+ local console_user
+ console_user=$(stat -f "%Su" /dev/console)
+ if [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; 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
@@ -31,32 +51,50 @@
fi
}
-restart_zoom() {
- local console_user="$1"
-
- if [[ -n "$console_user" && "$console_user" != "root" ]]; then
- echo "Restarting Zoom for user: $console_user"
- sudo -u "$console_user" open -a "zoom.us"
+
+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 [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; then
+ echo "Not logged into a non-root GUI; skipping relaunching application ID '$bundle_id'."
+ return
+ fi
+
+ echo "Relaunching application '$bundle_id'..."
+
+ # Launch the app in the logged-in user's GUI session. Apps launched by root
+ # won't register with the user's Dock/GUI, so run 'open' as the console user.
+ # Use 'launchctl asuser' to bootstrap into the console user's Mach namespace
+ # and GUI session — 'sudo -u' alone doesn't do this, which can cause
+ # LSOpenURLsWithRole() failures even when 'open' exits 0.
+ local open_status=0
+ if [[ $EUID -eq 0 ]]; then
+ local console_uid
+ console_uid=$(id -u "$console_user")
+ /bin/launchctl asuser "$console_uid" sudo -u "$console_user" open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ else
+ open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ fi
+
+ if [[ $open_status -eq 0 ]]; then
+ echo "Application '$bundle_id' relaunched successfully."
else
- echo "No console user found, attempting direct Zoom start..."
- open -a "zoom.us"
+ echo "Failed to relaunch application '$bundle_id'."
fi
}
-# Get console user once (used by both quit and restart)
-CONSOLE_USER=$(stat -f "%Su" /dev/console 2>/dev/null || echo "")
-# Check if Zoom is running
-ZOOM_WAS_RUNNING=false
-if osascript -e "application id \"us.zoom.xos\" is running" 2>/dev/null; then
- ZOOM_WAS_RUNNING=true
- quit_application 'us.zoom.xos' "$CONSOLE_USER"
-fi
-
-installer -pkg "$INSTALLER_PATH" -target /
-
-# Restart Zoom if it was running before installation
-if [[ "$ZOOM_WAS_RUNNING" == "true" ]]; then
- sleep 2
- restart_zoom "$CONSOLE_USER" || true
-fi
+# install pkg files
+quit_and_track_application 'us.zoom.xos'
+sudo installer -pkg "$TMPDIR/ZoomInstallerIT.pkg" -target /
+relaunch_application 'us.zoom.xos'
=== Uninstall Script (no changes) === |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #45893 +/- ##
==========================================
+ Coverage 66.82% 66.83% +0.01%
==========================================
Files 2808 2808
Lines 223582 223620 +38
Branches 11346 11346
==========================================
+ Hits 149407 149467 +60
+ Misses 60619 60600 -19
+ Partials 13556 13553 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Script Diff Resultsee/maintained-apps/outputs/1password/darwin.json=== Install // ef2a17ff -> c8c35fa0 ===
--- /tmp/old.xgOWnI 2026-05-21 13:03:11.066095004 +0000
+++ /tmp/new.iTX6tf 2026-05-21 13:03:11.066095004 +0000
@@ -1,21 +1,35 @@
#!/bin/bash
-quit_application() {
+# 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
+ local app_running
+ app_running=$(osascript -e "application id \"$bundle_id\" is running" 2>/dev/null)
+ if [[ "$app_running" != "true" ]]; 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
+ if [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; 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
@@ -37,5 +51,50 @@
fi
}
-quit_application 'com.1password.1password'
-installer -pkg "$INSTALLER_PATH" -target /
+
+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 [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; then
+ echo "Not logged into a non-root GUI; skipping relaunching application ID '$bundle_id'."
+ return
+ fi
+
+ echo "Relaunching application '$bundle_id'..."
+
+ # Launch the app in the logged-in user's GUI session. Apps launched by root
+ # won't register with the user's Dock/GUI, so run 'open' as the console user.
+ # Use 'launchctl asuser' to bootstrap into the console user's Mach namespace
+ # and GUI session — 'sudo -u' alone doesn't do this, which can cause
+ # LSOpenURLsWithRole() failures even when 'open' exits 0.
+ local open_status=0
+ if [[ $EUID -eq 0 ]]; then
+ local console_uid
+ console_uid=$(id -u "$console_user")
+ /bin/launchctl asuser "$console_uid" sudo -u "$console_user" open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ else
+ open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ fi
+
+ if [[ $open_status -eq 0 ]]; then
+ echo "Application '$bundle_id' relaunched successfully."
+ else
+ echo "Failed to relaunch application '$bundle_id'."
+ fi
+}
+
+
+# install pkg files
+quit_and_track_application 'com.1password.1password'
+sudo installer -pkg "$INSTALLER_PATH" -target /
+relaunch_application 'com.1password.1password'
=== Uninstall Script (no changes) ===ee/maintained-apps/outputs/slack/darwin.json=== Install // 6025885d -> 53397c19 ===
--- /tmp/old.nQLOqk 2026-05-21 13:03:11.232098215 +0000
+++ /tmp/new.P6KL7j 2026-05-21 13:03:11.232098215 +0000
@@ -1,21 +1,35 @@
#!/bin/bash
-quit_application() {
+# 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
+ local app_running
+ app_running=$(osascript -e "application id \"$bundle_id\" is running" 2>/dev/null)
+ if [[ "$app_running" != "true" ]]; 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
+ if [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; 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
@@ -37,5 +51,50 @@
fi
}
-quit_application 'com.tinyspeck.slackmacgap'
-installer -pkg "$INSTALLER_PATH" -target /
+
+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 [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; then
+ echo "Not logged into a non-root GUI; skipping relaunching application ID '$bundle_id'."
+ return
+ fi
+
+ echo "Relaunching application '$bundle_id'..."
+
+ # Launch the app in the logged-in user's GUI session. Apps launched by root
+ # won't register with the user's Dock/GUI, so run 'open' as the console user.
+ # Use 'launchctl asuser' to bootstrap into the console user's Mach namespace
+ # and GUI session — 'sudo -u' alone doesn't do this, which can cause
+ # LSOpenURLsWithRole() failures even when 'open' exits 0.
+ local open_status=0
+ if [[ $EUID -eq 0 ]]; then
+ local console_uid
+ console_uid=$(id -u "$console_user")
+ /bin/launchctl asuser "$console_uid" sudo -u "$console_user" open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ else
+ open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ fi
+
+ if [[ $open_status -eq 0 ]]; then
+ echo "Application '$bundle_id' relaunched successfully."
+ else
+ echo "Failed to relaunch application '$bundle_id'."
+ fi
+}
+
+
+# install pkg files
+quit_and_track_application 'com.tinyspeck.slackmacgap'
+sudo installer -pkg "$INSTALLER_PATH" -target /
+relaunch_application 'com.tinyspeck.slackmacgap'
=== Uninstall Script (no changes) ===ee/maintained-apps/outputs/zoom/darwin.json=== Install // 05e6a85c -> b67a020b ===
--- /tmp/old.APjmWI 2026-05-21 13:03:11.271098969 +0000
+++ /tmp/new.AfCSE5 2026-05-21 13:03:11.271098969 +0000
@@ -1,15 +1,35 @@
#!/bin/bash
-quit_application() {
+# variables
+APPDIR="/Applications/"
+TMPDIR=$(dirname "$(realpath "$INSTALLER_PATH")")
+# functions
+
+quit_and_track_application() {
local bundle_id="$1"
- local console_user="$2"
+ local var_name="APP_WAS_RUNNING_$(echo "$bundle_id" | tr '.-' '__')"
local timeout_duration=10
- if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
+ # check if the application is running
+ local app_running
+ app_running=$(osascript -e "application id \"$bundle_id\" is running" 2>/dev/null)
+ if [[ "$app_running" != "true" ]]; then
+ eval "export $var_name=0"
+ return
+ fi
+
+ local console_user
+ console_user=$(stat -f "%Su" /dev/console)
+ if [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; 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
@@ -31,32 +51,50 @@
fi
}
-restart_zoom() {
- local console_user="$1"
-
- if [[ -n "$console_user" && "$console_user" != "root" ]]; then
- echo "Restarting Zoom for user: $console_user"
- sudo -u "$console_user" open -a "zoom.us"
+
+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 [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; then
+ echo "Not logged into a non-root GUI; skipping relaunching application ID '$bundle_id'."
+ return
+ fi
+
+ echo "Relaunching application '$bundle_id'..."
+
+ # Launch the app in the logged-in user's GUI session. Apps launched by root
+ # won't register with the user's Dock/GUI, so run 'open' as the console user.
+ # Use 'launchctl asuser' to bootstrap into the console user's Mach namespace
+ # and GUI session — 'sudo -u' alone doesn't do this, which can cause
+ # LSOpenURLsWithRole() failures even when 'open' exits 0.
+ local open_status=0
+ if [[ $EUID -eq 0 ]]; then
+ local console_uid
+ console_uid=$(id -u "$console_user")
+ /bin/launchctl asuser "$console_uid" sudo -u "$console_user" open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ else
+ open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ fi
+
+ if [[ $open_status -eq 0 ]]; then
+ echo "Application '$bundle_id' relaunched successfully."
else
- echo "No console user found, attempting direct Zoom start..."
- open -a "zoom.us"
+ echo "Failed to relaunch application '$bundle_id'."
fi
}
-# Get console user once (used by both quit and restart)
-CONSOLE_USER=$(stat -f "%Su" /dev/console 2>/dev/null || echo "")
-# Check if Zoom is running
-ZOOM_WAS_RUNNING=false
-if osascript -e "application id \"us.zoom.xos\" is running" 2>/dev/null; then
- ZOOM_WAS_RUNNING=true
- quit_application 'us.zoom.xos' "$CONSOLE_USER"
-fi
-
-installer -pkg "$INSTALLER_PATH" -target /
-
-# Restart Zoom if it was running before installation
-if [[ "$ZOOM_WAS_RUNNING" == "true" ]]; then
- sleep 2
- restart_zoom "$CONSOLE_USER" || true
-fi
+# install pkg files
+quit_and_track_application 'us.zoom.xos'
+sudo installer -pkg "$TMPDIR/ZoomInstallerIT.pkg" -target /
+relaunch_application 'us.zoom.xos'
=== Uninstall Script (no changes) === |
Bump 1Password mac version from 8.12.12 to 8.12.21 and update the corresponding patched query to match the new version. Update Slack mac version (bundle com.tinyspeck.slackmacgap) from 4.50.121 to 4.49.89 and adjust its patched query accordingly. Installer URLs and install_script_ref values are unchanged.
Script Diff Resultsee/maintained-apps/outputs/1password/darwin.json=== Install Script (no changes) ===
=== Uninstall Script (no changes) ===ee/maintained-apps/outputs/slack/darwin.json=== Install Script (no changes) ===
=== Uninstall Script (no changes) ===ee/maintained-apps/outputs/zoom/darwin.json=== Install // 05e6a85c -> b67a020b ===
--- /tmp/old.GiBLtH 2026-05-21 13:13:50.324596314 +0000
+++ /tmp/new.MacdWC 2026-05-21 13:13:50.325596344 +0000
@@ -1,15 +1,35 @@
#!/bin/bash
-quit_application() {
+# variables
+APPDIR="/Applications/"
+TMPDIR=$(dirname "$(realpath "$INSTALLER_PATH")")
+# functions
+
+quit_and_track_application() {
local bundle_id="$1"
- local console_user="$2"
+ local var_name="APP_WAS_RUNNING_$(echo "$bundle_id" | tr '.-' '__')"
local timeout_duration=10
- if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
+ # check if the application is running
+ local app_running
+ app_running=$(osascript -e "application id \"$bundle_id\" is running" 2>/dev/null)
+ if [[ "$app_running" != "true" ]]; then
+ eval "export $var_name=0"
+ return
+ fi
+
+ local console_user
+ console_user=$(stat -f "%Su" /dev/console)
+ if [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; 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
@@ -31,32 +51,50 @@
fi
}
-restart_zoom() {
- local console_user="$1"
-
- if [[ -n "$console_user" && "$console_user" != "root" ]]; then
- echo "Restarting Zoom for user: $console_user"
- sudo -u "$console_user" open -a "zoom.us"
+
+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 [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; then
+ echo "Not logged into a non-root GUI; skipping relaunching application ID '$bundle_id'."
+ return
+ fi
+
+ echo "Relaunching application '$bundle_id'..."
+
+ # Launch the app in the logged-in user's GUI session. Apps launched by root
+ # won't register with the user's Dock/GUI, so run 'open' as the console user.
+ # Use 'launchctl asuser' to bootstrap into the console user's Mach namespace
+ # and GUI session — 'sudo -u' alone doesn't do this, which can cause
+ # LSOpenURLsWithRole() failures even when 'open' exits 0.
+ local open_status=0
+ if [[ $EUID -eq 0 ]]; then
+ local console_uid
+ console_uid=$(id -u "$console_user")
+ /bin/launchctl asuser "$console_uid" sudo -u "$console_user" open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ else
+ open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ fi
+
+ if [[ $open_status -eq 0 ]]; then
+ echo "Application '$bundle_id' relaunched successfully."
else
- echo "No console user found, attempting direct Zoom start..."
- open -a "zoom.us"
+ echo "Failed to relaunch application '$bundle_id'."
fi
}
-# Get console user once (used by both quit and restart)
-CONSOLE_USER=$(stat -f "%Su" /dev/console 2>/dev/null || echo "")
-# Check if Zoom is running
-ZOOM_WAS_RUNNING=false
-if osascript -e "application id \"us.zoom.xos\" is running" 2>/dev/null; then
- ZOOM_WAS_RUNNING=true
- quit_application 'us.zoom.xos' "$CONSOLE_USER"
-fi
-
-installer -pkg "$INSTALLER_PATH" -target /
-
-# Restart Zoom if it was running before installation
-if [[ "$ZOOM_WAS_RUNNING" == "true" ]]; then
- sleep 2
- restart_zoom "$CONSOLE_USER" || true
-fi
+# install pkg files
+quit_and_track_application 'us.zoom.xos'
+sudo installer -pkg "$TMPDIR/ZoomInstallerIT.pkg" -target /
+relaunch_application 'us.zoom.xos'
=== Uninstall Script (no changes) === |
Script Diff Resultsee/maintained-apps/outputs/1password/darwin.json=== Install Script (no changes) ===
=== Uninstall Script (no changes) ===ee/maintained-apps/outputs/slack/darwin.json=== Install Script (no changes) ===
=== Uninstall Script (no changes) ===ee/maintained-apps/outputs/zoom/darwin.json=== Install // 05e6a85c -> b67a020b ===
--- /tmp/old.Vx2LQ4 2026-05-21 16:09:10.562921272 +0000
+++ /tmp/new.0Gzqru 2026-05-21 16:09:10.562921272 +0000
@@ -1,15 +1,35 @@
#!/bin/bash
-quit_application() {
+# variables
+APPDIR="/Applications/"
+TMPDIR=$(dirname "$(realpath "$INSTALLER_PATH")")
+# functions
+
+quit_and_track_application() {
local bundle_id="$1"
- local console_user="$2"
+ local var_name="APP_WAS_RUNNING_$(echo "$bundle_id" | tr '.-' '__')"
local timeout_duration=10
- if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
+ # check if the application is running
+ local app_running
+ app_running=$(osascript -e "application id \"$bundle_id\" is running" 2>/dev/null)
+ if [[ "$app_running" != "true" ]]; then
+ eval "export $var_name=0"
+ return
+ fi
+
+ local console_user
+ console_user=$(stat -f "%Su" /dev/console)
+ if [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; 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
@@ -31,32 +51,50 @@
fi
}
-restart_zoom() {
- local console_user="$1"
-
- if [[ -n "$console_user" && "$console_user" != "root" ]]; then
- echo "Restarting Zoom for user: $console_user"
- sudo -u "$console_user" open -a "zoom.us"
+
+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 [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; then
+ echo "Not logged into a non-root GUI; skipping relaunching application ID '$bundle_id'."
+ return
+ fi
+
+ echo "Relaunching application '$bundle_id'..."
+
+ # Launch the app in the logged-in user's GUI session. Apps launched by root
+ # won't register with the user's Dock/GUI, so run 'open' as the console user.
+ # Use 'launchctl asuser' to bootstrap into the console user's Mach namespace
+ # and GUI session — 'sudo -u' alone doesn't do this, which can cause
+ # LSOpenURLsWithRole() failures even when 'open' exits 0.
+ local open_status=0
+ if [[ $EUID -eq 0 ]]; then
+ local console_uid
+ console_uid=$(id -u "$console_user")
+ /bin/launchctl asuser "$console_uid" sudo -u "$console_user" open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ else
+ open -b "$bundle_id" >/dev/null 2>&1 || open_status=$?
+ fi
+
+ if [[ $open_status -eq 0 ]]; then
+ echo "Application '$bundle_id' relaunched successfully."
else
- echo "No console user found, attempting direct Zoom start..."
- open -a "zoom.us"
+ echo "Failed to relaunch application '$bundle_id'."
fi
}
-# Get console user once (used by both quit and restart)
-CONSOLE_USER=$(stat -f "%Su" /dev/console 2>/dev/null || echo "")
-# Check if Zoom is running
-ZOOM_WAS_RUNNING=false
-if osascript -e "application id \"us.zoom.xos\" is running" 2>/dev/null; then
- ZOOM_WAS_RUNNING=true
- quit_application 'us.zoom.xos' "$CONSOLE_USER"
-fi
-
-installer -pkg "$INSTALLER_PATH" -target /
-
-# Restart Zoom if it was running before installation
-if [[ "$ZOOM_WAS_RUNNING" == "true" ]]; then
- sleep 2
- restart_zoom "$CONSOLE_USER" || true
-fi
+# install pkg files
+quit_and_track_application 'us.zoom.xos'
+sudo installer -pkg "$TMPDIR/ZoomInstallerIT.pkg" -target /
+relaunch_application 'us.zoom.xos'
=== Uninstall Script (no changes) === |
Agent-Logs-Url: https://github.com/fleetdm/fleet/sessions/33d23e62-6f13-4aa7-93ea-fa1ab4045c60 Co-authored-by: allenhouchins <32207388+allenhouchins@users.noreply.github.com>
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
Script Diff Resultsee/maintained-apps/outputs/1password/darwin.json=== Install Script (no changes) ===
=== Uninstall // f58c31b3 -> dadf8c51 ===
--- /tmp/old.61KD46 2026-05-29 15:00:49.568918878 +0000
+++ /tmp/new.JV5sZl 2026-05-29 15:00:49.568918878 +0000
@@ -5,6 +5,46 @@
LOGGED_IN_USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }')
# functions
+quit_application() {
+ local bundle_id="$1"
+ local timeout_duration=10
+
+ # check if the application is running
+ local app_running
+ app_running=$(osascript -e "application id \"$bundle_id\" is running" 2>/dev/null)
+ if [[ "$app_running" != "true" ]]; then
+ return
+ fi
+
+ local console_user
+ console_user=$(stat -f "%Su" /dev/console)
+ if [[ -z "$console_user" || "$console_user" == "root" || "$console_user" == "loginwindow" ]]; then
+ echo "Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'."
+ return
+ fi
+
+ 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
+}
+
+
trash() {
local logged_in_user="$1"
local target_file="$2"
@@ -27,6 +67,7 @@
fi
}
+quit_application 'com.1password.1password'
sudo rm -rf "$APPDIR/1Password.app"
trash $LOGGED_IN_USER '~/Library/Application Scripts/2BUA8C4S2C.com.1password*'
trash $LOGGED_IN_USER '~/Library/Application Scripts/2BUA8C4S2C.com.agilebits'ee/maintained-apps/outputs/slack/darwin.json=== Install Script (no changes) ===
=== Uninstall Script (no changes) ===ee/maintained-apps/outputs/zoom/darwin.json=== Install // b67a020b -> e9a9b924 ===
--- /tmp/old.bUQmmF 2026-05-29 15:00:49.638920407 +0000
+++ /tmp/new.7TT8Hl 2026-05-29 15:00:49.638920407 +0000
@@ -97,4 +97,8 @@
# install pkg files
quit_and_track_application 'us.zoom.xos'
sudo installer -pkg "$TMPDIR/ZoomInstallerIT.pkg" -target /
+INSTALL_EXIT_CODE=$?
relaunch_application 'us.zoom.xos'
+if [ "$INSTALL_EXIT_CODE" -ne 0 ]; then
+ exit "$INSTALL_EXIT_CODE"
+fi
=== Uninstall Script (no changes) === |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ee/maintained-apps/ingesters/homebrew/scripts.go (1)
60-76: ⚡ Quick winConsider propagating copy failures on the App path too.
The Pkg path now captures the installer exit code and exits non-zero on failure via
RelaunchAndPropagateInstallStatus, but the App-copy path still ends with a barerelaunch_application. Since the generated script has noset -e, a failedsudo cp -Ris followed byrelaunch_application(which exits 0), so the script returns success and a failed install is reported as installed — the same class of bug this PR fixes for pkg.Note: with multiple `App` items only the last `cp`'s status is captured, but that still beats unconditionally reporting success.♻️ Reuse the propagation helper for consistency
- // Relaunch the app if it was running before installation - sb.Writef("relaunch_application '%s'", app.UniqueIdentifier) + // Relaunch the app if it was running before installation, then + // propagate a failed copy so it isn't reported as successful. + sb.RelaunchAndPropagateInstallStatus(app.UniqueIdentifier)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ee/maintained-apps/ingesters/homebrew/scripts.go` around lines 60 - 76, The App-copy path currently always calls relaunch_application and can mask copy failures; modify the block that calls sb.Copy (inside the loop over artifact.App) to capture the cp/mv exit status and propagate it the same way the Pkg path does by invoking the existing RelaunchAndPropagateInstallStatus helper instead of an unconditional relaunch_application; specifically, after each sb.Copy(appPath, "$APPDIR") (or at least after the loop) record the last command's exit code and call RelaunchAndPropagateInstallStatus with app.UniqueIdentifier so a failed sudo cp causes the script to exit non-zero and still relaunch the app if appropriate.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@ee/maintained-apps/ingesters/homebrew/scripts.go`:
- Around line 60-76: The App-copy path currently always calls
relaunch_application and can mask copy failures; modify the block that calls
sb.Copy (inside the loop over artifact.App) to capture the cp/mv exit status and
propagate it the same way the Pkg path does by invoking the existing
RelaunchAndPropagateInstallStatus helper instead of an unconditional
relaunch_application; specifically, after each sb.Copy(appPath, "$APPDIR") (or
at least after the loop) record the last command's exit code and call
RelaunchAndPropagateInstallStatus with app.UniqueIdentifier so a failed sudo cp
causes the script to exit non-zero and still relaunch the app if appropriate.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fda72519-20db-4578-9bfb-1ba221d816ea
📒 Files selected for processing (1)
ee/maintained-apps/ingesters/homebrew/scripts.go
|
@copilot resolve the merge conflicts in this pull request |
…default-scripting
Resolved the merge conflict in |
…ct and URL override is used" (#46574) Reverts #45893 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved application installation for 1Password, Slack, and Zoom by implementing graceful application shutdown before installation and automatic restart after completion. * Enhanced installation reliability by simplifying application lifecycle management during package updates, reducing potential conflicts from running applications during installation processes. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Support installer_format="pkg" even when the Homebrew cask describes no pkg artifact by installing the downloaded package at $INSTALLER_PATH. Adds caskHasPkgArtifact and InstallPkgFromInstallerPath, and updates installScriptForApp to use quit/track and relaunch helpers around a direct installer call when appropriate. Includes unit tests for both code paths. Removes per-app install script files and clears install_script_path from input JSONs; updates output refs for 1Password, Slack and Zoom to the new consolidated scripts.
Related issue: Resolves #
Checklist for submitter
If some of the following don't apply, delete the relevant line.
Changes file added for user-visible changes in
changes/,orbit/changes/oree/fleetd-chrome/changes.See Changes files for more information.
Input data is properly validated,
SELECT *is avoided, SQL injection is prevented (using placeholders for values in statements), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters.Timeouts are implemented and retries are limited to avoid infinite loops
If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes
Testing
Added/updated automated tests
Where appropriate, automated tests simulate multiple hosts and test for host isolation (updates to one hosts's records do not affect another)
QA'd all new/changed functionality manually
For unreleased bug fixes in a release candidate, one of:
Database migrations
COLLATE utf8mb4_unicode_ci).New Fleet configuration settings
If you didn't check the box above, follow this checklist for GitOps-enabled settings:
fleetctl generate-gitopsfleetd/orbit/Fleet Desktop
runtime.GOOSis used as needed to isolate changesSummary by CodeRabbit