Skip to content

Fix install.sh sourced-invocation and stale template alias#448

Open
morfize wants to merge 1 commit intomath-inc:mainfrom
morfize:fix/install-sh-sourced-and-local-template
Open

Fix install.sh sourced-invocation and stale template alias#448
morfize wants to merge 1 commit intomath-inc:mainfrom
morfize:fix/install-sh-sourced-and-local-template

Conversation

@morfize
Copy link
Copy Markdown

@morfize morfize commented Apr 14, 2026

Summary

  • Refuse sourced or non-bash invocation of scripts/install.sh — sourcing from zsh (. ./scripts/install.sh) silently misplaced the installer venv one directory above the repo root because zsh leaves BASH_SOURCE unset, causing SCRIPT_DIR to collapse to cwd. Guard fires before any path resolution and uses return when sourced, exit otherwise, so it never kills the user's interactive shell.
  • Prefer the checked-in .github/morph/opengauss-template.yaml as the default install target — the shared opengauss alias at morph.new has been observed returning 404 Not Found, breaking --experimental-run-locally runs that fall through to the remote fetch. Since anyone who git clones the repo always has the tracked YAML on disk, this makes local installs fully self-contained.
  • All existing env-var overrides (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 valid
  • zsh -c '. ./scripts/install.sh' — refused with clear error, no venv created
  • bash -c 'source ./scripts/install.sh' — refused with clear error
  • Full fresh install via ./scripts/install.sh completed end-to-end on macOS arm64 (Python 3.13, zsh host shell, no tmux) — all 9 template steps succeeded, gauss binary landed at ~/.local/bin/gauss, ~/.gauss populated, Lean workspace + mathlib4 cache downloaded.
  • CI / contributor review on Linux and Windows (WSL2)

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings April 14, 2026 19:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_TARGET to the tracked .github/morph/opengauss-template.yaml when available, falling back to the opengauss remote alias otherwise.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/install.sh
Comment on lines 2 to +6
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
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread scripts/install.sh

# 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
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
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.

3 participants