Fix install.sh sourced-invocation and stale template alias#448
Fix install.sh sourced-invocation and stale template alias#448morfize wants to merge 1 commit intomath-inc:mainfrom
Conversation
Two install failures observed on fresh macOS + zsh setups: - Sourcing from zsh (. ./scripts/install.sh) silently misplaced the installer venv one directory above the repo root, because zsh leaves BASH_SOURCE unset and SCRIPT_DIR collapsed to cwd. Now refuse sourced or non-bash invocation with a clear error, using return when sourced and exit otherwise. - The shared opengauss template alias at morph.new has been observed to return 404, breaking --experimental-run-locally runs that fell through to the remote fetch. Prefer the checked-in .github/morph/opengauss-template.yaml when present, so local installs are self-contained and no longer depend on the remote alias. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens the scripts/install.sh bootstrapper by preventing sourced/non-bash invocation (to avoid incorrect path resolution) and by making local installs self-contained by defaulting to the checked-in Morph template YAML when present.
Changes:
- Add early guards to refuse non-bash execution and sourced invocation of
scripts/install.sh. - Default
INSTALL_TARGETto the tracked.github/morph/opengauss-template.yamlwhen available, falling back to theopengaussremote alias otherwise.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| set -euo pipefail | ||
|
|
||
| # Refuse sourced or non-bash invocation: zsh leaves BASH_SOURCE unset, misplacing the venv. | ||
| if [[ -z "${BASH_VERSION:-}" ]]; then | ||
| printf 'error: scripts/install.sh must be executed with bash, not sourced. Run: ./scripts/install.sh\n' >&2 |
There was a problem hiding this comment.
set -euo pipefail runs before the sourced/non-bash guards. If a user sources this file in an interactive shell, their shell options can be modified (e.g., enabling -e/-u/pipefail) before the script returns, which is an observable side effect even though the script is refusing to run. Consider moving set -euo pipefail to after the guards, or saving/restoring the caller's shell options when sourced so refusal leaves the environment unchanged.
|
|
||
| # Refuse sourced or non-bash invocation: zsh leaves BASH_SOURCE unset, misplacing the venv. | ||
| if [[ -z "${BASH_VERSION:-}" ]]; then | ||
| printf 'error: scripts/install.sh must be executed with bash, not sourced. Run: ./scripts/install.sh\n' >&2 |
There was a problem hiding this comment.
The error message in the non-bash guard says "must be executed with bash, not sourced", but this branch triggers for any non-bash execution as well (e.g., zsh scripts/install.sh, sh scripts/install.sh). Consider rewording to explicitly say it must be run under bash (e.g., ./scripts/install.sh), and separately mention not to source it.
| printf 'error: scripts/install.sh must be executed with bash, not sourced. Run: ./scripts/install.sh\n' >&2 | |
| printf 'error: scripts/install.sh must be run under bash (for example: ./scripts/install.sh), not under sh or zsh.\n' >&2 |
Summary
scripts/install.sh— sourcing from zsh (. ./scripts/install.sh) silently misplaced the installer venv one directory above the repo root because zsh leavesBASH_SOURCEunset, causingSCRIPT_DIRto collapse to cwd. Guard fires before any path resolution and usesreturnwhen sourced,exitotherwise, so it never kills the user's interactive shell..github/morph/opengauss-template.yamlas the default install target — the sharedopengaussalias atmorph.newhas been observed returning404 Not Found, breaking--experimental-run-locallyruns that fall through to the remote fetch. Since anyone whogit clones the repo always has the tracked YAML on disk, this makes local installs fully self-contained.OPEN_GAUSS_INSTALL_TARGET,OPEN_GAUSS_TEMPLATE_TARGET) are preserved; the change only swaps the default when nothing is set.Test plan
bash -n scripts/install.sh— syntax validzsh -c '. ./scripts/install.sh'— refused with clear error, no venv createdbash -c 'source ./scripts/install.sh'— refused with clear error./scripts/install.shcompleted end-to-end on macOS arm64 (Python 3.13, zsh host shell, no tmux) — all 9 template steps succeeded,gaussbinary landed at~/.local/bin/gauss,~/.gausspopulated, Lean workspace + mathlib4 cache downloaded.🤖 Generated with Claude Code