Use bash shebang in generated scripts - #44836
Conversation
Change the shebang written by scriptBuilder.String() from "#!/bin/sh" to "#!/bin/bash" so generated scripts explicitly use bash instead of sh. This ensures the scripts run under bash semantics.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #44836 +/- ##
=======================================
Coverage 66.68% 66.69%
=======================================
Files 2664 2664
Lines 214781 214855 +74
Branches 9882 9882
=======================================
+ Hits 143224 143287 +63
- Misses 58521 58526 +5
- Partials 13036 13042 +6
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:
|
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.
WalkthroughThe shebang line in the 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ee/maintained-apps/ingesters/homebrew/scripts.go (1)
575-619: ⚡ Quick winOptional: replace
evalwithprintf -vfor safer variable indirection.
var_nameis constructed viatr '.-' '__', which only replaces.and-. If a bundle ID ever contains characters like$or backticks, theeval "export $var_name=..."/eval "was_running=\$$var_name"calls could have unintended effects. Since the script now explicitly targets Bash,printf -vordeclareare idiomatic,eval-free alternatives:♻️ Safer variable indirection using
printf -v- eval "export $var_name=0" + printf -v "$var_name" '%s' '0'; export "$var_name"- eval "export $var_name=1" + printf -v "$var_name" '%s' '1'; export "$var_name"- eval "was_running=\$$var_name" + was_running="${!var_name}"The
${!var_name}indirect expansion is a Bash built-in and avoidsevalentirely.🤖 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 575 - 619, The quit_and_track_application() function uses eval "export $var_name=..." and eval "was_running=\$$var_name" which is unsafe; replace these eval uses with Bash-safe indirection: when setting the flag, use declare -x "$var_name"=0 or declare -x "$var_name"=1 (or printf -v to assign then export) instead of eval, and when reading the flag use the indirect expansion ${!var_name} (e.g., was_running="${!var_name}") rather than eval. Update all occurrences in quit_and_track_application() that set or read var_name accordingly.
🤖 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 575-619: The quit_and_track_application() function uses eval
"export $var_name=..." and eval "was_running=\$$var_name" which is unsafe;
replace these eval uses with Bash-safe indirection: when setting the flag, use
declare -x "$var_name"=0 or declare -x "$var_name"=1 (or printf -v to assign
then export) instead of eval, and when reading the flag use the indirect
expansion ${!var_name} (e.g., was_running="${!var_name}") rather than eval.
Update all occurrences in quit_and_track_application() that set or read var_name
accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9eff748d-73db-43f4-a9a1-a62013f2d702
📒 Files selected for processing (1)
ee/maintained-apps/ingesters/homebrew/scripts.go
Summary
Switches the maintained-apps homebrew script generator from #!/bin/sh to #!/bin/bash so the declared interpreter matches what the scripts actually use.
Why
The generated install/uninstall scripts use bash-only constructs throughout — [[ ... ]], (( ... )), local, eval, indexed/associative arrays, ${var:1} substring expansion, $EUID, SECONDS — but declared #!/bin/sh. They've worked in production because macOS's /bin/sh is bash in POSIX mode, but the shebang was technically inaccurate.
These functions are direct ports of Homebrew's own implementation (referenced in scripts.go), and Homebrew itself uses bash. Declaring #!/bin/bash makes the generated scripts match the source they were ported from and removes a portability lie.
This change is safe because:
Summary by CodeRabbit