-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(install): check permissions before npm link #517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,11 +222,26 @@ install_or_upgrade_ollama() { | |
| install_nemoclaw() { | ||
| if [[ -f "./package.json" ]] && grep -q '"name": "nemoclaw"' ./package.json 2>/dev/null; then | ||
| info "NemoClaw package.json found in current directory — installing from source…" | ||
| npm install && npm link | ||
| npm install | ||
|
|
||
| # Check if we have write access to the npm prefix to avoid EACCES errors | ||
| local prefix | ||
| prefix="$(npm config get prefix 2>/dev/null || echo "/usr/local")" | ||
| if [[ -w "$prefix/lib/node_modules" ]]; then | ||
| npm link | ||
| else | ||
| warn "Insufficient permissions to link NemoClaw globally. Retrying with sudo…" | ||
| sudo npm link | ||
|
Comment on lines
+233
to
+234
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard Line 234 and Line 243 call Suggested fix- warn "Insufficient permissions to link NemoClaw globally. Retrying with sudo…"
- sudo npm link
+ warn "Insufficient permissions to link NemoClaw globally. Retrying with sudo…"
+ command_exists sudo || error "sudo is required for global link but is not installed."
+ if [[ "${NON_INTERACTIVE:-}" == "1" ]]; then
+ sudo -n npm link || error "sudo requires a password in non-interactive mode. Re-run interactively or configure npm prefix to a user-writable path."
+ else
+ sudo npm link
+ fi
@@
- warn "Insufficient permissions for global install. Retrying with sudo…"
- sudo npm install -g git+https://github.com/NVIDIA/NemoClaw.git
+ warn "Insufficient permissions for global install. Retrying with sudo…"
+ command_exists sudo || error "sudo is required for global install but is not installed."
+ if [[ "${NON_INTERACTIVE:-}" == "1" ]]; then
+ sudo -n npm install -g git+https://github.com/NVIDIA/NemoClaw.git || error "sudo requires a password in non-interactive mode. Re-run interactively or configure npm prefix to a user-writable path."
+ else
+ sudo npm install -g git+https://github.com/NVIDIA/NemoClaw.git
+ fiAlso applies to: 242-243 🤖 Prompt for AI Agents |
||
| fi | ||
| else | ||
| info "Installing NemoClaw from GitHub…" | ||
| # Revert once https://github.com/NVIDIA/NemoClaw/issues/71 is complete and the package is published | ||
| npm install -g git+https://github.com/NVIDIA/NemoClaw.git | ||
| if [[ -w "$(npm config get prefix 2>/dev/null || echo "/usr/local")/lib/node_modules" ]]; then | ||
| npm install -g git+https://github.com/NVIDIA/NemoClaw.git | ||
| else | ||
| warn "Insufficient permissions for global install. Retrying with sudo…" | ||
| sudo npm install -g git+https://github.com/NVIDIA/NemoClaw.git | ||
| fi | ||
| fi | ||
|
|
||
| refresh_path | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retry should be driven by command failure, not only by pre-check.
Line 230 and Line 239 only check one path up front. With
set -e, if the npm command still fails (including permission failures outside this pre-check), the script exits without retrying. Wrap the command and retry when it actually fails withEACCES.Suggested fix
install_nemoclaw() { + run_npm_with_eacces_retry() { + local tmp + tmp="$(mktemp)" + if "$@" 2> >(tee "$tmp" >&2); then + rm -f "$tmp" + return 0 + fi + if grep -q "EACCES" "$tmp"; then + warn "Permission denied for npm global operation. Retrying with sudo…" + rm -f "$tmp" + sudo "$@" + return $? + fi + rm -f "$tmp" + return 1 + } + if [[ -f "./package.json" ]] && grep -q '"name": "nemoclaw"' ./package.json 2>/dev/null; then info "NemoClaw package.json found in current directory — installing from source…" npm install - local prefix - prefix="$(npm config get prefix 2>/dev/null || echo "/usr/local")" - if [[ -w "$prefix/lib/node_modules" ]]; then - npm link - else - warn "Insufficient permissions to link NemoClaw globally. Retrying with sudo…" - sudo npm link - fi + run_npm_with_eacces_retry npm link else info "Installing NemoClaw from GitHub…" - if [[ -w "$(npm config get prefix 2>/dev/null || echo "/usr/local")/lib/node_modules" ]]; then - npm install -g git+https://github.com/NVIDIA/NemoClaw.git - else - warn "Insufficient permissions for global install. Retrying with sudo…" - sudo npm install -g git+https://github.com/NVIDIA/NemoClaw.git - fi + run_npm_with_eacces_retry npm install -g git+https://github.com/NVIDIA/NemoClaw.git fiAlso applies to: 239-240
🤖 Prompt for AI Agents