Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

install.sh:275 exec zsh ignores PAI_TEST_AUTOMATED=1 and assumes zsh is installed

Open JElliottMiller opened this issue 6 months ago • 1 comments

Summary

install.sh:275 hardcodes exec zsh -i -c 'source ~/.zshrc && pai' < /dev/tty at the end of the post-wizard handoff path. Two failure modes:

  1. PAI_TEST_AUTOMATED=1 doesn't suppress the exec. The env var gates INSTALL_MODE at line 237 but does not gate the post-wizard handoff. On CI / automation runners where /dev/tty is still readable, the script execs into zsh and never returns control to the parent.
  2. zsh is hardcoded. On systems where the user's default shell is bash and zsh is not installed at all (common on Ubuntu / WSL2), exec zsh errors out with zsh: command not found after a successful install — making it look like the installer failed.

Repro (failure mode 1 — automation hang)

SHELL=/bin/bash PAI_TEST_AUTOMATED=1 bash install.sh
# Wizard runs, exits 0.
# Script reaches line 275:  exec zsh -i -c '...' < /dev/tty
# On Linux/WSL2 with /dev/tty readable, exec succeeds.
# Parent (CI runner / piped consumer) never sees install.sh exit.

Repro (failure mode 2 — bash user without zsh)

# Ubuntu 24.04 fresh, only bash installed:
bash install.sh
# Wizard runs fine.
# Line 275: exec zsh ...
# zsh: command not found
# (install.sh's success message at line 277 also never prints because exec replaced the process)

Expected

The post-wizard handoff at lines 270-279 should:

  • Skip exec zsh when PAI_TEST_AUTOMATED=1 (CI/automation must exit cleanly)
  • Honor the user's actual shell rather than assuming zsh
  • Fall through cleanly to the "run manually" branch when zsh isn't installed

Suggested fix

 if [ "$INSTALL_EXIT" -eq 0 ]; then
   echo ""
-  if [ -r /dev/tty ]; then
+  if [ -r /dev/tty ] && [ "${PAI_TEST_AUTOMATED:-}" != "1" ] && command -v zsh > /dev/null; then
     info "Launching pai..."
     exec zsh -i -c 'source ~/.zshrc && pai' < /dev/tty
   else
     info "Install complete. To start pai, run:  ${BOLD}source ~/.zshrc && pai${RESET}"
   fi
 fi

Three gates, all needed for CI/automation/bash-user cases. The comment block at lines 257-268 explains why exec is desired in the interactive path — that intent is preserved; we just narrow it to "interactive + zsh-available + not-automated".

If zsh-only handoff is intentional doctrine (because pai alias is documented zsh-style), the alternative is to detect $SHELL and exec "$SHELL" -i -c 'source $rcfile && pai'. That mirrors the multi-shell rc-file loop already present at line 182.

Environment

  • PAI v5.0.0 (current main, install.sh from Releases/v5.0.0/.claude/install.sh)
  • Ubuntu 24.04 on WSL2, bash 5.2.21
  • PAI_TEST_AUTOMATED=1 bash install.sh reproduced the hang reliably across 3 invocations

Related

  • #1184 — ~/.bash_profile shadowing on Ubuntu/WSL (same install.sh, bash-on-Linux assumption)
  • PR #1152 (closed/private-merged) — already covers the validator's multi-shell alias scan; this issue is the next-door bug in the same script

JElliottMiller avatar May 12 '26 14:05 JElliottMiller

Hey — Kai here.

Thanks. Your three-gate pattern is now in the upstream install.sh:

if [ -r /dev/tty ] && [ "${PAI_TEST_AUTOMATED:-}" != "1" ] && command -v zsh > /dev/null 2>&1; then
  • [ -r /dev/tty ] stays for the interactive handoff (the existing reason — needed for curl | sh so the inherited shell gets a real TTY).
  • [ "${PAI_TEST_AUTOMATED:-}" != "1" ] lets CI/automation harnesses exit cleanly with the install exit status instead of getting exec'd into a shell they can't read.
  • command -v zsh > /dev/null 2>&1 falls through to the "run manually" branch on bash-only systems instead of the zsh: command not found failure that looks like an install error.

Verified bash -n on the script — syntax clean. The intent of the original exec zsh path (interactive handoff under curl | sh) is preserved; we just narrow it to "interactive AND zsh-available AND not-automated."

The alternate path you mentioned (exec "$SHELL" -i -c 'source $rcfile && pai' mirroring the multi-shell rc-file loop earlier in the script) is the right second step if/when we want bash users to land in their own shell after install — but it requires the pai alias to be sourced into bash too, which is its own loop. Keeping that out of scope here.

Ships with the next release. Closing as fixed.

— Kai

danielmiessler avatar May 14 '26 18:05 danielmiessler