From 549693ffcb44fc32a963061d9d7b05e272998f1e Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 10 May 2026 05:39:42 +0100 Subject: [PATCH] fix(installer): promote persisted PATH entries --- scripts/install.sh | 27 +++++---------------------- test/scripts/install-sh.test.ts | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index dcd412172ee..3d348e380c5 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1372,15 +1372,16 @@ persist_shell_path_prepend() { return 1 fi - local path_line="export PATH=\"${dir}:\$PATH\"" + local path_expr="${2:-$dir}" + local path_line="export PATH=\"${path_expr}:\$PATH\"" local wrote_rc=0 for rc in "$HOME/.bashrc" "$HOME/.zshrc"; do if [[ -f "$rc" ]]; then - if ! grep -Fq "$dir" "$rc"; then + if [[ "$(sed -n '1p' "$rc")" != "$path_line" ]]; then local tmp_rc="${rc}.openclaw-tmp" { printf '%s\n' "$path_line" - cat "$rc" + grep -Fvx "$path_line" "$rc" || true } > "$tmp_rc" mv "$tmp_rc" "$rc" fi @@ -1761,25 +1762,7 @@ fix_npm_permissions() { npm config set prefix "$HOME/.npm-global" ui_warn "Avoid sudo npm i -g for future OpenClaw updates; use npm i -g openclaw@latest so npm keeps using this user prefix instead of a different global prefix." - # shellcheck disable=SC2016 - local path_line='export PATH="$HOME/.npm-global/bin:$PATH"' - local wrote_rc=0 - for rc in "$HOME/.bashrc" "$HOME/.zshrc"; do - if [[ -f "$rc" ]]; then - if ! grep -q ".npm-global" "$rc"; then - local tmp_rc="${rc}.openclaw-tmp" - { - printf '%s\n' "$path_line" - cat "$rc" - } > "$tmp_rc" - mv "$tmp_rc" "$rc" - fi - wrote_rc=1 - fi - done - if [[ "$wrote_rc" -eq 0 ]]; then - printf '%s\n' "$path_line" >> "$HOME/.bashrc" - fi + persist_shell_path_prepend "$HOME/.npm-global/bin" '$HOME/.npm-global/bin' || true export PATH="$HOME/.npm-global/bin:$PATH" ui_success "npm configured for user installs" diff --git a/test/scripts/install-sh.test.ts b/test/scripts/install-sh.test.ts index 4c4aee8868b..30df2dcabf2 100644 --- a/test/scripts/install-sh.test.ts +++ b/test/scripts/install-sh.test.ts @@ -168,7 +168,14 @@ describe("install.sh", () => { const installedNode = join(installedBin, "node"); writeFileSync( join(home, ".bashrc"), - ["case $- in", " *i*) ;;", " *) return ;;", "esac", ""].join("\n"), + [ + "case $- in", + " *i*) ;;", + " *) return ;;", + "esac", + `export PATH="${installedBin}:$PATH"`, + "", + ].join("\n"), ); writeFileSync( oldNode, @@ -272,7 +279,14 @@ describe("install.sh", () => { mkdirSync(home, { recursive: true }); writeFileSync( join(home, ".bashrc"), - ["case $- in", " *i*) ;;", " *) return ;;", "esac", ""].join("\n"), + [ + "case $- in", + " *i*) ;;", + " *) return ;;", + "esac", + 'export PATH="$HOME/.npm-global/bin:$PATH"', + "", + ].join("\n"), ); let result: ReturnType | undefined;