Skip to content

fix(binary-installer): correct grep -q usage to avoid duplicate PATH / duplicate PATH entries#13410

Merged
czubocha merged 3 commits intoserverless:mainfrom
gaurav0909-max:fix-binary-installer-path-check
Apr 15, 2026
Merged

fix(binary-installer): correct grep -q usage to avoid duplicate PATH / duplicate PATH entries#13410
czubocha merged 3 commits intoserverless:mainfrom
gaurav0909-max:fix-binary-installer-path-check

Conversation

@gaurav0909-max
Copy link
Copy Markdown
Contributor

@gaurav0909-max gaurav0909-max commented Mar 14, 2026

Problem

The installer script incorrectly checks for .serverless/bin
in shell configuration files using command substitution with grep -q.

grep -q returns an exit status but produces no output, so using
command substitution ($() or backticks) always results in an empty
string. This causes the condition to always evaluate true and results
in duplicate PATH entries being appended on repeated installs.

Solution

Check the exit status of grep -q directly instead of using command
substitution. Also added proper quoting for $SHELL_CONFIG.

Result

The installer now correctly avoids adding duplicate .serverless/bin
entries to shell configuration files.

Fixes #13394

Summary by CodeRabbit

  • Refactor
    • Improved shell installer script: tightened quoting and conditional checks to prevent word-splitting/globbing and ensure consistent behavior across zsh and bash variants.
    • Normalized PATH-append logic and removed a redundant nested check, simplifying installer flow while preserving existing behavior; trimmed an extraneous blank line.

@Mmarzex
Copy link
Copy Markdown
Contributor

Mmarzex commented Mar 14, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 14, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: abfeb57a-f8b8-437b-a623-b7be8fbefab2

📥 Commits

Reviewing files that changed from the base of the PR and between 031225c and 109788a.

📒 Files selected for processing (1)
  • binary-installer/install.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • binary-installer/install.sh

📝 Walkthrough

Walkthrough

Replaces command-substitution grep checks with direct exit-status tests, adds quoting around "$SHELL_CONFIG" in grep calls, and unifies PATH-append conditionals across shell init files in binary-installer/install.sh to prevent duplicate PATH entries.

Changes

Cohort / File(s) Summary
Shell installer script
binary-installer/install.sh
Replaced $(grep -q ...) command-substitution checks with ! grep -q "..." "$SHELL_CONFIG" exit-status tests; quoted "$SHELL_CONFIG" in all grep invocations; simplified redundant nested if [[ -r ... ]] branches; adjusted PATH-append checks for zsh/bash/profile files to run only when the target string is absent; removed trailing blank/whitespace line associated with an fi.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇 I hopped through scripts at break of dawn,
Replaced the backticks that kept growing on.
I quoted the paths and checked with grep true,
Now PATHs stay tidy — one hop, not two. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: fixing grep -q usage in the binary installer to prevent duplicate PATH entries, which aligns with the core problem solved in this PR.
Linked Issues check ✅ Passed The PR implements all key requirements from issue #13394: replaces command substitution with direct grep exit status checks, adds proper quoting for $SHELL_CONFIG, and makes the installer idempotent to prevent duplicate PATH entries.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the grep -q usage and PATH duplication issue in binary-installer/install.sh as specified in the linked issue; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@gaurav0909-max
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
binary-installer/install.sh (1)

72-90: ⚠️ Potential issue | 🟠 Major

Remove the duplicated if on line 72; it breaks fallback control flow.

The double condition (if [[ -r $SHELL_CONFIG ]]; then if [[ -r $SHELL_CONFIG ]]; then) causes the else on line 77 to bind to the inner if instead of the outer one. When .bash_profile is unreadable, the entire else block (lines 78–88) that handles fallback to .bash_login and .profile is skipped, breaking the intended cascade through shell startup files.

Proposed fix
  SHELL_CONFIG=$HOME/.bash_profile
- if [[ -r $SHELL_CONFIG ]]; then  if [[ -r $SHELL_CONFIG ]]; then
+ if [[ -r $SHELL_CONFIG ]]; then
 
     if ! grep -q '.serverless/bin' "$SHELL_CONFIG"; then
       add_to_path $SHELL_CONFIG
     fi
   else
     SHELL_CONFIG=$HOME/.bash_login
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@binary-installer/install.sh` around lines 72 - 90, Remove the duplicated
nested "if [[ -r $SHELL_CONFIG ]]" so the fallback else branch correctly pairs
with the outer test; locate the block using the SHELL_CONFIG variable and
add_to_path function references, delete the inner redundant if that starts the
duplicate check, and ensure the remaining if/else cascade checks
$HOME/.bash_profile then falls back to $HOME/.bash_login and $HOME/.profile
while calling add_to_path when a target file does not already contain
'.serverless/bin'.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@binary-installer/install.sh`:
- Around line 63-69: The script uses unquoted SHELL_CONFIG in assignments,
conditional tests and when calling add_to_path which can break on spaces or glob
chars; update all occurrences to quote the variable (e.g., use "SHELL_CONFIG" in
assignments, "[ ! -r "$SHELL_CONFIG" ]" and "grep -q '.serverless/bin'
"$SHELL_CONFIG"" tests, and call add_to_path "$SHELL_CONFIG") so every reference
to SHELL_CONFIG is wrapped in double quotes; ensure you update every use in the
if/else blocks and any other occurrences in the file (references: SHELL_CONFIG,
add_to_path, grep -q).

---

Outside diff comments:
In `@binary-installer/install.sh`:
- Around line 72-90: Remove the duplicated nested "if [[ -r $SHELL_CONFIG ]]" so
the fallback else branch correctly pairs with the outer test; locate the block
using the SHELL_CONFIG variable and add_to_path function references, delete the
inner redundant if that starts the duplicate check, and ensure the remaining
if/else cascade checks $HOME/.bash_profile then falls back to $HOME/.bash_login
and $HOME/.profile while calling add_to_path when a target file does not already
contain '.serverless/bin'.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 892ffadd-d22e-48b4-8c0e-572ca6c0453d

📥 Commits

Reviewing files that changed from the base of the PR and between f022a9b and 218c280.

📒 Files selected for processing (1)
  • binary-installer/install.sh

Comment thread binary-installer/install.sh Outdated
gaurav0909-max and others added 3 commits April 15, 2026 19:50
…ofile fallback

The doubled `if [[ -r "$SHELL_CONFIG" ]]; then` on the same line caused
the else branch to bind to the inner if, making the fallback cascade to
.bash_login and .profile unreachable when .bash_profile does not exist.
@czubocha czubocha force-pushed the fix-binary-installer-path-check branch from d122c20 to 109788a Compare April 15, 2026 18:50
@czubocha
Copy link
Copy Markdown
Contributor

@cursor review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 15, 2026

Bugbot couldn't run

Bugbot is not enabled for your user on this team.

Ask your team administrator to increase your team's hard limit for Bugbot seats or add you to the allowlist in the Cursor dashboard.

@czubocha czubocha merged commit ae48f27 into serverless:main Apr 15, 2026
8 of 9 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

binary-installer/install.sh appends duplicate PATH entries due to grep -q command substitution

3 participants