Skip to content

Revert "Support default pkg install script when cask lacks pkg artifact and URL override is used" - #46574

Merged
allenhouchins merged 1 commit into
mainfrom
revert-45893-allenhouchins-update-default-scripting
Jun 1, 2026
Merged

Revert "Support default pkg install script when cask lacks pkg artifact and URL override is used"#46574
allenhouchins merged 1 commit into
mainfrom
revert-45893-allenhouchins-update-default-scripting

Conversation

@allenhouchins

@allenhouchins allenhouchins commented Jun 1, 2026

Copy link
Copy Markdown
Member

Reverts #45893

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.

@allenhouchins
allenhouchins marked this pull request as ready for review June 1, 2026 17:25
Copilot AI review requested due to automatic review settings June 1, 2026 17:25
@allenhouchins
allenhouchins requested a review from a team as a code owner June 1, 2026 17:25

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 66.86%. Comparing base (aa90c87) to head (4906f02).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
ee/maintained-apps/ingesters/homebrew/scripts.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #46574      +/-   ##
==========================================
+ Coverage   66.83%   66.86%   +0.03%     
==========================================
  Files        2809     2809              
  Lines      223561   223740     +179     
  Branches    11313    11313              
==========================================
+ Hits       149417   149607     +190     
+ Misses      60599    60548      -51     
- Partials    13545    13585      +40     
Flag Coverage Δ
backend 68.59% <0.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reverts #45893, which had added support for generating a default pkg install script when a Homebrew cask lacks a pkg artifact but has a URL override pointing at a pkg. The revert removes the dynamic generation logic and instead reintroduces static per-app install scripts (for Slack, 1Password, and Zoom) referenced via install_script_path in each app's input JSON.

Changes:

  • Revert the caskHasPkgArtifact/InstallPkgFromInstallerPath/RelaunchAndPropagateInstallStatus logic in scripts.go and the corresponding tests in scripts_test.go.
  • Revert the quit_application/quit_and_track_application helpers to their pre-#45893 form (drop the launchctl asuser + sudo -u bootstrap when running as root).
  • Reintroduce static install scripts for Slack, 1Password, and Zoom and wire them up via install_script_path in the respective input JSONs.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
ee/maintained-apps/ingesters/homebrew/scripts.go Reverts dynamic pkg-without-pkg-artifact handling and rolls back the root-aware osascript bootstrap in the quit helpers.
ee/maintained-apps/ingesters/homebrew/scripts_test.go Removes tests that covered the reverted dynamic pkg-install behavior.
ee/maintained-apps/inputs/homebrew/slack.json Points Slack at a static install script.
ee/maintained-apps/inputs/homebrew/1password.json Points 1Password at a static install script.
ee/maintained-apps/inputs/homebrew/zoom.json Points Zoom at a static install script.
ee/maintained-apps/inputs/homebrew/scripts/slack_install.sh Restores Slack's static install script.
ee/maintained-apps/inputs/homebrew/scripts/1password_install.sh Restores 1Password's static install script.
ee/maintained-apps/inputs/homebrew/scripts/zoom_install.sh Restores Zoom's static install script (with restart-if-running behavior).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR refactors Homebrew pkg installation by removing centralized script-generation methods (RelaunchAndPropagateInstallStatus and InstallPkgFromInstallerPath) from the scripts.go generator and simplifying its embedded shell functions to use direct osascript calls without privilege-escalation branching. Associated pkg-format tests are deleted. Three apps (1Password, Slack, Zoom) now include their own shell scripts that implement quit-before-install logic and, for Zoom, conditional restart behavior. App manifests are updated to reference these new scripts via the install_script_path field.

Possibly related PRs

  • fleetdm/fleet#45893: Earlier PR that introduced the RelaunchAndPropagateInstallStatus and InstallPkgFromInstallerPath methods to scripts.go and added the corresponding pkg-format tests that this PR removes.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is minimal, only stating 'Reverts #45893' without following the template structure or providing context about testing, validation, or other required checklist items. Expand the description to follow the repository template, including relevant checklist items, testing information, and context for the revert decision.
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: reverting a previous commit that added default pkg install script support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch revert-45893-allenhouchins-update-default-scripting

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 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.

Inline comments:
In `@ee/maintained-apps/ingesters/homebrew/scripts.go`:
- Around line 72-73: The installer exit status is being masked by the subsequent
relaunch_application call; capture the exit code immediately after the installer
command emitted by scriptBuilder.InstallPkg (store it in a variable like
installer_exit via InstallPkg or by appending a capture right after the install
invocation), then call relaunch_application '%s' (app.UniqueIdentifier) as now,
and finally exit or return using that stored installer_exit (e.g. exit
$installer_exit or test and exit non-zero) so the original installer failure is
preserved.

In `@ee/maintained-apps/inputs/homebrew/scripts/1password_install.sh`:
- Around line 7-10: The osascript check uses exit status instead of stdout so a
returned "false" still exits 0; capture the output of the osascript call that
checks application id "$bundle_id" is running and test its stdout string (e.g.,
compare to "true") before deciding to return/continue; update the invocation
referenced around the bundle_id variable and the osascript check to assign the
command output to a variable and explicitly test for "true" (or use a string
match) instead of relying on the command's exit code.

In `@ee/maintained-apps/inputs/homebrew/scripts/zoom_install.sh`:
- Around line 51-54: The code currently tests osascript's exit status instead of
the AppleScript boolean; change the check to capture osascript output and test
for the literal "true". For example, run running=$(osascript -e 'application id
"us.zoom.xos" is running' 2>/dev/null) and then if [ "$running" = "true" ]; then
set ZOOM_WAS_RUNNING=true and call quit_application 'us.zoom.xos'
"$CONSOLE_USER"; otherwise leave ZOOM_WAS_RUNNING unset/false. Ensure the
comparison is exact (string equality) and output is properly quoted.
- Around line 37-39: restart_zoom() currently uses sudo -u "$console_user" open
-a "zoom.us" which can fail to target the logged-in GUI/Mach session; change it
to use the same pattern as relaunch_application() by invoking /bin/launchctl
asuser "$console_uid" sudo -u "$console_user" open -a "zoom.us" so the restart
happens in the console user's GUI session, referencing the existing console_uid
and console_user variables and matching relaunch_application() behavior.
- Around line 56-61: The installer exit status is lost when restart_zoom runs;
capture the exit code immediately after calling installer (reference the
installer invocation and variable INSTALLER_PATH), e.g., save "$?" into a local
variable like INSTALLER_EXIT, then perform the conditional restart based on
ZOOM_WAS_RUNNING and call restart_zoom "$CONSOLE_USER" || true, and finally exit
or return using the saved INSTALLER_EXIT so the script returns the install
result rather than the restart result.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9b8ebe57-c38b-447e-a274-26361e755f64

📥 Commits

Reviewing files that changed from the base of the PR and between b6b5b41 and 4906f02.

📒 Files selected for processing (8)
  • ee/maintained-apps/ingesters/homebrew/scripts.go
  • ee/maintained-apps/ingesters/homebrew/scripts_test.go
  • ee/maintained-apps/inputs/homebrew/1password.json
  • ee/maintained-apps/inputs/homebrew/scripts/1password_install.sh
  • ee/maintained-apps/inputs/homebrew/scripts/slack_install.sh
  • ee/maintained-apps/inputs/homebrew/scripts/zoom_install.sh
  • ee/maintained-apps/inputs/homebrew/slack.json
  • ee/maintained-apps/inputs/homebrew/zoom.json
💤 Files with no reviewable changes (1)
  • ee/maintained-apps/ingesters/homebrew/scripts_test.go

Comment on lines +72 to +73
// Relaunch the app if it was running before installation
sb.Writef("relaunch_application '%s'", app.UniqueIdentifier)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verifies the shell behavior this change relies on: the last command wins.
set -euo pipefail

bash -lc 'false; true'
echo "exit after false; true => $?"   # expected: 0

bash -lc 'false; status=$?; true; exit "$status"'
echo "exit after capturing status => $?"   # expected: 1

Repository: fleetdm/fleet

Length of output: 301


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Inspect the relevant code region in the repo
FILE="ee/maintained-apps/ingesters/homebrew/scripts.go"
if [ ! -f "$FILE" ]; then
  echo "Missing file: $FILE" >&2
  exit 2
fi

echo "---- $FILE (around lines 60-90) ----"
nl -ba "$FILE" | sed -n '60,90p'

# 2) Re-check exit-status behavior without set -e terminating the script early
echo "---- exit status experiments (no set -e) ----"
set +e
bash -lc 'false; true'
echo "exit after: false; true => $?"   # expect 0

bash -lc 'false; status=$?; true; exit "$status"'
echo "exit after: capture then exit $status => $?"   # expect 1

# 3) Minimal model: if installer fails but a later command succeeds, last command wins
bash -lc 'false; installer_status=$?; true; echo installer_status=$installer_status; exit 0'
echo "model: installer fails then last command succeeds => $?"  # expect 0

bash -lc 'false; installer_status=$?; true; exit "$installer_status"'
echo "model: installer fails but we exit with captured status => $?"  # expect 1

Repository: fleetdm/fleet

Length of output: 199


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="ee/maintained-apps/ingesters/homebrew/scripts.go"
test -f "$FILE" || { echo "Missing file: $FILE" >&2; exit 2; }

echo "---- $FILE (around lines 60-90) ----"
awk 'NR>=60 && NR<=90 { printf "%d\t%s\n", NR, $0 }' "$FILE"

echo "---- exit status experiments (no set -e) ----"
set +e
bash -lc 'false; true'
echo "exit after false; true => $?"   # expect 0

bash -lc 'false; status=$?; true; exit "$status"'
echo "exit after capture then exit $status => $?"   # expect 1

bash -lc 'false; installer_status=$?; true; echo installer_status=$installer_status; exit 0'
echo "model: installer fails then last command succeeds => $?"  # expect 0

bash -lc 'false; installer_status=$?; true; exit "$installer_status"'
echo "model: installer fails but we exit with captured status => $?"  # expect 1

Repository: fleetdm/fleet

Length of output: 1530


🏁 Script executed:

#!/bin/bash
set -euo pipefail
FILE="ee/maintained-apps/ingesters/homebrew/scripts.go"
test -f "$FILE"

echo "---- show more around InstallPkg call sites ----"
awk 'NR>=1 && NR<=140 {print}' "$FILE" | sed -n '90,140p'

echo "---- find InstallPkg implementation in repo ----"
rg -n "func \\(.*\\) InstallPkg\\(" -S . || true

echo "---- exit status experiments (clean) ----"
set +e
set +u
bash -lc 'false; true'
echo "exit after false; true => $?"   # expect 0

bash -lc 'false; status=$?; true; exit $status'
echo "exit after capture then exit $status => $?"  # expect 1

bash -lc 'false; installer_status=$?; true; exit 0'
echo "model: installer fails then last command succeeds => $?"  # expect 0

bash -lc 'false; installer_status=$?; true; exit $installer_status'
echo "model: installer fails but we exit with captured status => $?"  # expect 1

Repository: fleetdm/fleet

Length of output: 2592


🏁 Script executed:

#!/bin/bash
set -euo pipefail
FILE="ee/maintained-apps/ingesters/homebrew/scripts.go"

test -f "$FILE"

echo "---- scriptBuilder.InstallPkg implementation (around line 380-460) ----"
awk 'NR>=360 && NR<=460 { printf "%d\t%s\n", NR, $0 }' "$FILE"

echo "---- search for relaunch_application and installer generation ----"
rg -n "relaunch_application|InstallPkg\\(|installer " "$FILE"

echo "---- show helpers: Write / Writef / AddVariable / String() (if nearby) ----"
rg -n "func \\(s \\*scriptBuilder\\) (Write|Writef|AddVariable|String)\\(" "$FILE"

Repository: fleetdm/fleet

Length of output: 4779


🏁 Script executed:

#!/bin/bash
set -euo pipefail
FILE="ee/maintained-apps/ingesters/homebrew/scripts.go"

echo "---- search for set -e / pipefail in this file ----"
rg -n "set -e|set -o|pipefail" "$FILE" || true

echo "---- show top of String() where header is written ----"
awk 'NR>=430 && NR<=520 { printf "%d\t%s\n", NR, $0 }' "$FILE"

echo "---- show relaunchApplicationFunc definition ----"
awk 'NR>=600 && NR<=700 { printf "%d\t%s\n", NR, $0 }' "$FILE"

echo "---- show uninstall/install script builder ordering around 50-90 for pkg relaunch block ----"
awk 'NR>=1 && NR<=120 { if(NR>=50) { printf "%d\t%s\n", NR, $0 } }' "$FILE"

Repository: fleetdm/fleet

Length of output: 9842


Preserve installer exit status before relaunching.

scriptBuilder.InstallPkg writes sudo installer ... without any set -e/error propagation, and the script then immediately calls relaunch_application ..., which can return success—masking a failed installer.

Suggested fix
 			// Relaunch the app if it was running before installation
+			sb.Write("install_status=$?")
 			sb.Writef("relaunch_application '%s'", app.UniqueIdentifier)
+			sb.Write("exit $install_status")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 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
sb.Write("install_status=$?")
sb.Writef("relaunch_application '%s'", app.UniqueIdentifier)
sb.Write("exit $install_status")
🤖 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 72 - 73, The
installer exit status is being masked by the subsequent relaunch_application
call; capture the exit code immediately after the installer command emitted by
scriptBuilder.InstallPkg (store it in a variable like installer_exit via
InstallPkg or by appending a capture right after the install invocation), then
call relaunch_application '%s' (app.UniqueIdentifier) as now, and finally exit
or return using that stored installer_exit (e.g. exit $installer_exit or test
and exit non-zero) so the original installer failure is preserved.

Comment on lines +7 to +10
# check if the application is running
if ! osascript -e "application id \"$bundle_id\" is running" 2>/dev/null; then
return
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verifies the bash behavior involved here: `if ! cmd` inspects exit status, not stdout.
set -euo pipefail

if ! printf 'false\n' >/dev/null; then
  echo "returned"
else
  echo "continued"
fi
# expected: continued

Repository: fleetdm/fleet

Length of output: 67


🌐 Web query:

osascript exit status when AppleScript returns false (boolean) stdout "false" exit code 0

💡 Result:

When the AppleScript you run with osascript evaluates to the boolean false (and does not throw an error), osascript exits with status 0; the “false” shows up in stdout as the returned value, not as an exit code. [1][2] If you need a non-zero exit status based on that boolean, you must explicitly signal an error from AppleScript (e.g., using error number...), or have a wrapper shell script map stdout to an exit code. osascript’s exit status otherwise only reflects whether osascript itself hit an error, not the truthiness of the returned value. [1][2][3] Example patterns: 1) Treat returned false as a shell failure (wrapper approach): - osascript prints “false” to stdout when the script returns false; in bash you can do: osascript -e 'return false' | grep -qx false && exit 1 (or invert the logic). [1] 2) Convert failure into osascript error (error number approach): - Use AppleScript error number <N>; then osascript will exit non-zero, and you can capture the error message/number from stderr/stdout depending on your flags. By default osascript prints script errors to stderr. [3][4]

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail
sed -n '1,60p' ee/maintained-apps/inputs/homebrew/scripts/1password_install.sh

Repository: fleetdm/fleet

Length of output: 1164


Fix app running-state check to evaluate osascript stdout (true/false), not exit status.

if ! osascript ... is running only returns when osascript itself errors; when the app isn’t running AppleScript returns false, which still exits 0—so the quit flow continues.

Suggested fix
-  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
     return
   fi
🤖 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/inputs/homebrew/scripts/1password_install.sh` around lines
7 - 10, The osascript check uses exit status instead of stdout so a returned
"false" still exits 0; capture the output of the osascript call that checks
application id "$bundle_id" is running and test its stdout string (e.g., compare
to "true") before deciding to return/continue; update the invocation referenced
around the bundle_id variable and the osascript check to assign the command
output to a variable and explicitly test for "true" (or use a string match)
instead of relying on the command's exit code.

Comment on lines +37 to +39
if [[ -n "$console_user" && "$console_user" != "root" ]]; then
echo "Restarting Zoom for user: $console_user"
sudo -u "$console_user" open -a "zoom.us"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verifies the mismatch against the shared relaunch helper in this PR.
set -euo pipefail

sed -n '631,663p' ee/maintained-apps/ingesters/homebrew/scripts.go
echo '---'
sed -n '34,43p' ee/maintained-apps/inputs/homebrew/scripts/zoom_install.sh

Repository: fleetdm/fleet

Length of output: 1684


Use launchctl asuser for Zoom restarts to relaunch in the logged-in GUI session.

restart_zoom() currently does only sudo -u "$console_user" open -a "zoom.us", but the shared relaunch_application() helper explicitly uses /bin/launchctl asuser "$console_uid" sudo -u "$console_user" open ... because sudo -u ... open alone can miss the console user’s GUI/Mach session.

Suggested fix
   if [[ -n "$console_user" && "$console_user" != "root" ]]; then
     echo "Restarting Zoom for user: $console_user"
-    sudo -u "$console_user" open -a "zoom.us"
+    local console_uid
+    console_uid=$(id -u "$console_user")
+    /bin/launchctl asuser "$console_uid" sudo -u "$console_user" open -a "zoom.us"
   else
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ -n "$console_user" && "$console_user" != "root" ]]; then
echo "Restarting Zoom for user: $console_user"
sudo -u "$console_user" open -a "zoom.us"
if [[ -n "$console_user" && "$console_user" != "root" ]]; then
echo "Restarting Zoom for user: $console_user"
local console_uid
console_uid=$(id -u "$console_user")
/bin/launchctl asuser "$console_uid" sudo -u "$console_user" open -a "zoom.us"
🤖 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/inputs/homebrew/scripts/zoom_install.sh` around lines 37 -
39, restart_zoom() currently uses sudo -u "$console_user" open -a "zoom.us"
which can fail to target the logged-in GUI/Mach session; change it to use the
same pattern as relaunch_application() by invoking /bin/launchctl asuser
"$console_uid" sudo -u "$console_user" open -a "zoom.us" so the restart happens
in the console user's GUI session, referencing the existing console_uid and
console_user variables and matching relaunch_application() behavior.

Comment on lines +51 to +54
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verifies the bash behavior involved here: the `if cmd` condition uses exit status.
set -euo pipefail

if printf 'false\n' >/dev/null; then
  echo "branch taken"
else
  echo "branch skipped"
fi
# expected: branch taken

Repository: fleetdm/fleet

Length of output: 70


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and print the relevant section
FILE="ee/maintained-apps/inputs/homebrew/scripts/zoom_install.sh"
echo "== File = $FILE =="
nl -ba "$FILE" | sed -n '35,90p'

# Find all uses of ZOOM_WAS_RUNNING in the repo
echo
echo "== Uses of ZOOM_WAS_RUNNING =="
rg -n "ZOOM_WAS_RUNNING" -S .

Repository: fleetdm/fleet

Length of output: 190


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="ee/maintained-apps/inputs/homebrew/scripts/zoom_install.sh"
echo "== File = $FILE =="
awk 'NR>=35 && NR<=90 {printf "%d\t%s\n", NR, $0}' "$FILE"

echo
echo "== Uses of ZOOM_WAS_RUNNING =="
rg -n "ZOOM_WAS_RUNNING" -S .

Repository: fleetdm/fleet

Length of output: 3221


🌐 Web query:

osascript exit status when AppleScript expression returns true/false

💡 Result:

The exit status of the osascript command is not determined by the boolean value (true or false) returned by your AppleScript expression [1][2][3]. When you run a script using osascript, the exit status of the command reflects whether osascript itself executed successfully [1]. If the script runs without encountering an AppleScript-level error (via an error statement), osascript will exit with a status of 0, regardless of the logical result of the script [1][2]. Even if your script ends with return true or return false, the calling shell will receive an exit status of 0 [1][2]. To pass a custom exit code from AppleScript to your shell, you must explicitly use the AppleScript error statement [1][2][3]: error "An error occurred" number 123 When this statement is executed, osascript will terminate with an exit status of 1 (a general error) by default, because it treats any unhandled script error as a failure [1][2][3]. It does not natively forward the custom error number (e.g., 123) as the process exit status [1][3]. To handle this in your shell script: 1. Use the -s o option with osascript to redirect script errors to standard output (stdout) instead of standard error (stderr) [4][5][6]. 2. Parse the output or error number from the command output in your shell script [2][3][5]. Example pattern: # Run the script and capture both output and errors result=$(osascript -s o -e 'return true' 2>&1) # You can then check the script's output or the exit code of the osascript command itself [3][5] For production workflows, a common approach is to have the AppleScript output a specific string or numeric value to stdout upon success or failure, which the shell script then captures and evaluates to set its own exit status [2][3].

Citations:


Fix ZOOM_WAS_RUNNING detection: use the AppleScript boolean result, not osascript exit status (ee/maintained-apps/inputs/homebrew/scripts/zoom_install.sh ~51-54)

if osascript ...; then tests the exit code of osascript (success is exit 0 even when the AppleScript expression evaluates to false), so ZOOM_WAS_RUNNING can be set to true and Zoom restarted even when it was closed.

Suggested fix
 # Check if Zoom is running
 ZOOM_WAS_RUNNING=false
-if osascript -e "application id \"us.zoom.xos\" is running" 2>/dev/null; then
+if [[ "$(osascript -e "application id \"us.zoom.xos\" is running" 2>/dev/null)" == "true" ]]; then
   ZOOM_WAS_RUNNING=true
   quit_application 'us.zoom.xos' "$CONSOLE_USER"
 fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
# Check if Zoom is running
ZOOM_WAS_RUNNING=false
if [[ "$(osascript -e "application id \"us.zoom.xos\" is running" 2>/dev/null)" == "true" ]]; then
ZOOM_WAS_RUNNING=true
quit_application 'us.zoom.xos' "$CONSOLE_USER"
fi
🤖 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/inputs/homebrew/scripts/zoom_install.sh` around lines 51 -
54, The code currently tests osascript's exit status instead of the AppleScript
boolean; change the check to capture osascript output and test for the literal
"true". For example, run running=$(osascript -e 'application id "us.zoom.xos" is
running' 2>/dev/null) and then if [ "$running" = "true" ]; then set
ZOOM_WAS_RUNNING=true and call quit_application 'us.zoom.xos' "$CONSOLE_USER";
otherwise leave ZOOM_WAS_RUNNING unset/false. Ensure the comparison is exact
(string equality) and output is properly quoted.

Comment on lines +56 to +61
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verifies the shell behavior this change relies on: the last command wins.
set -euo pipefail

bash -lc 'false; true'
echo "exit after false; true => $?"   # expected: 0

bash -lc 'false; status=$?; true; exit "$status"'
echo "exit after capturing status => $?"   # expected: 1

Repository: fleetdm/fleet

Length of output: 301


Preserve installer exit status before restarting Zoom

If installer fails and ZOOM_WAS_RUNNING is true, the last command becomes restart_zoom "$CONSOLE_USER" || true (forces success), so the script’s exit code reflects the restart result instead of the install failure.

Suggested fix
 installer -pkg "$INSTALLER_PATH" -target /
+INSTALL_STATUS=$?
 
 # Restart Zoom if it was running before installation
 if [[ "$ZOOM_WAS_RUNNING" == "true" ]]; then
   sleep 2
   restart_zoom "$CONSOLE_USER" || true
 fi
+
+exit "$INSTALL_STATUS"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
installer -pkg "$INSTALLER_PATH" -target /
INSTALL_STATUS=$?
# Restart Zoom if it was running before installation
if [[ "$ZOOM_WAS_RUNNING" == "true" ]]; then
sleep 2
restart_zoom "$CONSOLE_USER" || true
fi
exit "$INSTALL_STATUS"
🤖 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/inputs/homebrew/scripts/zoom_install.sh` around lines 56 -
61, The installer exit status is lost when restart_zoom runs; capture the exit
code immediately after calling installer (reference the installer invocation and
variable INSTALLER_PATH), e.g., save "$?" into a local variable like
INSTALLER_EXIT, then perform the conditional restart based on ZOOM_WAS_RUNNING
and call restart_zoom "$CONSOLE_USER" || true, and finally exit or return using
the saved INSTALLER_EXIT so the script returns the install result rather than
the restart result.

@allenhouchins
allenhouchins merged commit f96004c into main Jun 1, 2026
47 checks passed
@allenhouchins
allenhouchins deleted the revert-45893-allenhouchins-update-default-scripting branch June 1, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants