Skip to content

fix: Fixes issue with script not running correctly in zsh enviornment.#36

Open
dlabaj wants to merge 1 commit intopatternfly:mainfrom
dlabaj:pf-4005
Open

fix: Fixes issue with script not running correctly in zsh enviornment.#36
dlabaj wants to merge 1 commit intopatternfly:mainfrom
dlabaj:pf-4005

Conversation

@dlabaj
Copy link
Copy Markdown
Contributor

@dlabaj dlabaj commented Apr 22, 2026

This resolves jira issue #4005 . The install script was not working correctly on mac when zsh was being used. This fix resolves that issue.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed typo in installation guide text
    • Improved zsh shell compatibility by enforcing proper script execution and auto-configuring Node manager settings
    • Removed duplicated success message
  • Documentation

    • Clarified post-installation instructions to source shell configuration files if command is not immediately available

@dlabaj dlabaj requested a review from jpuzz0 April 22, 2026 18:26
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

Walkthrough

Enhanced the installation script to enforce Bash execution and improve zsh shell compatibility. Added automatic NVM configuration setup for zsh users and refined user-facing output messages with corrected text and post-installation sourcing instructions.

Changes

Cohort / File(s) Summary
Shell Script Installation Enhancement
scripts/install.sh
Enforced Bash execution via re-exec when invoked under other shells; added setup_nvm_for_zsh() function to conditionally append NVM configuration to ~/.zshrc; corrected help text typo and updated final output with sourcing instructions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly indicates the core problem being addressed: fixing the install script's compatibility with the zsh environment.
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 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.

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
scripts/install.sh (1)

5-8: The documented install pattern uses bash directly, so the guard will not break it—but improve error messaging for accidental non-bash invocation.

The README correctly documents curl -fsSL ... | bash, which means BASH_VERSION is set and the guard does not trigger. However, if a user accidentally runs curl ... | zsh or curl ... | sh, the guard would fail confusingly because $0 contains the shell name rather than a file path. Consider adding a check for stdin invocation to provide a clearer error message:

 # Ensure this script runs in bash, even if invoked with zsh
 if [ -z "${BASH_VERSION:-}" ]; then
+  if [ ! -f "$0" ]; then
+    printf '\nERROR: This installer must be run with bash. Download it first, then run: bash scripts/install.sh\n\n' >&2
+    exit 1
+  fi
   exec bash "$0" "$@"
 fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/install.sh` around lines 5 - 8, The current guard uses BASH_VERSION
and exec bash "$0" "$@" which can produce confusing behavior when the script is
piped into a non-bash shell because $0 is the shell name; update the check so
when BASH_VERSION is empty you detect piped/stdin invocation (e.g., $0 is "-" or
not a regular file or contains "sh"/"zsh") and, if so, print a clear error to
stderr instructing the user to run the installer with bash (for example: "This
installer must be run with bash. Use: curl ... | bash") and exit non‑zero;
otherwise, preserve the exec bash "$0" "$@" fallback so direct non‑bash
executions still re‑exec under bash.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/install.sh`:
- Around line 70-86: The zsh snippet in scripts/install.sh currently hardcodes
export NVM_DIR="$HOME/.nvm", which breaks custom installs; update the code that
appends to the zshrc (the block that writes to the variable zshrc) so it
persists the actual NVM_DIR value instead of hardcoding ~/.nvm—write the export
using parameter expansion to prefer an existing environment NVM_DIR and fall
back to $HOME/.nvm (mirror the behavior used by ensure_nvm_loaded), and keep the
subsequent checks that source nvm.sh and bash_completion unchanged.

---

Nitpick comments:
In `@scripts/install.sh`:
- Around line 5-8: The current guard uses BASH_VERSION and exec bash "$0" "$@"
which can produce confusing behavior when the script is piped into a non-bash
shell because $0 is the shell name; update the check so when BASH_VERSION is
empty you detect piped/stdin invocation (e.g., $0 is "-" or not a regular file
or contains "sh"/"zsh") and, if so, print a clear error to stderr instructing
the user to run the installer with bash (for example: "This installer must be
run with bash. Use: curl ... | bash") and exit non‑zero; otherwise, preserve the
exec bash "$0" "$@" fallback so direct non‑bash executions still re‑exec under
bash.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 118992b3-5e83-4299-9a57-40f133ba4423

📥 Commits

Reviewing files that changed from the base of the PR and between 3d0a15c and 168a7cc.

📒 Files selected for processing (1)
  • scripts/install.sh

Comment thread scripts/install.sh
Comment on lines +70 to +86
local zshrc="${HOME}/.zshrc"
if [ ! -f "$zshrc" ]; then
touch "$zshrc"
fi

if grep -q 'NVM_DIR' "$zshrc" 2>/dev/null; then
info "nvm is already configured in ${zshrc}"
return 0
fi

info "Adding nvm to ${zshrc} for zsh compatibility."
cat >> "$zshrc" << 'EOF'

# Load nvm (Node Version Manager)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Persist the actual NVM_DIR instead of hardcoding ~/.nvm.

ensure_nvm_loaded supports custom NVM_DIR, but the zsh snippet always writes export NVM_DIR="$HOME/.nvm". Users installing nvm into a custom location will get a broken future zsh session.

Proposed fix
-  local zshrc="${HOME}/.zshrc"
+  local zshrc="${HOME}/.zshrc"
+  local nvm_dir="${NVM_DIR:-$HOME/.nvm}"
@@
-  cat >> "$zshrc" << 'EOF'
+  cat >> "$zshrc" << EOF
 
 # Load nvm (Node Version Manager)
-export NVM_DIR="$HOME/.nvm"
-[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
-[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
+export NVM_DIR="${nvm_dir}"
+[ -s "\$NVM_DIR/nvm.sh" ] && \. "\$NVM_DIR/nvm.sh"
+[ -s "\$NVM_DIR/bash_completion" ] && \. "\$NVM_DIR/bash_completion"
 EOF
📝 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
local zshrc="${HOME}/.zshrc"
if [ ! -f "$zshrc" ]; then
touch "$zshrc"
fi
if grep -q 'NVM_DIR' "$zshrc" 2>/dev/null; then
info "nvm is already configured in ${zshrc}"
return 0
fi
info "Adding nvm to ${zshrc} for zsh compatibility."
cat >> "$zshrc" << 'EOF'
# Load nvm (Node Version Manager)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
local zshrc="${HOME}/.zshrc"
local nvm_dir="${NVM_DIR:-$HOME/.nvm}"
if [ ! -f "$zshrc" ]; then
touch "$zshrc"
fi
if grep -q 'NVM_DIR' "$zshrc" 2>/dev/null; then
info "nvm is already configured in ${zshrc}"
return 0
fi
info "Adding nvm to ${zshrc} for zsh compatibility."
cat >> "$zshrc" << EOF
# Load nvm (Node Version Manager)
export NVM_DIR="${nvm_dir}"
[ -s "\$NVM_DIR/nvm.sh" ] && \. "\$NVM_DIR/nvm.sh"
[ -s "\$NVM_DIR/bash_completion" ] && \. "\$NVM_DIR/bash_completion"
EOF
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/install.sh` around lines 70 - 86, The zsh snippet in
scripts/install.sh currently hardcodes export NVM_DIR="$HOME/.nvm", which breaks
custom installs; update the code that appends to the zshrc (the block that
writes to the variable zshrc) so it persists the actual NVM_DIR value instead of
hardcoding ~/.nvm—write the export using parameter expansion to prefer an
existing environment NVM_DIR and fall back to $HOME/.nvm (mirror the behavior
used by ensure_nvm_loaded), and keep the subsequent checks that source nvm.sh
and bash_completion unchanged.

@dlabaj dlabaj linked an issue Apr 22, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Collaborator

@jpuzz0 jpuzz0 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Install script does not work on mac os with zsh

2 participants