Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
#!/usr/bin/env bash
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
Comment on lines 2 to +6
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.
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.
return 1 2>/dev/null || exit 1
fi
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
printf 'error: scripts/install.sh must be executed, not sourced. Run: ./scripts/install.sh\n' >&2
return 1 2>/dev/null || exit 1
fi

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
RUNNER_VENV="$REPO_ROOT/.opengauss-installer-venv"
DEFAULT_INSTALL_TARGET="opengauss"
# Prefer the checked-in template: the shared `opengauss` alias at morph.new has been observed to 404.
LOCAL_TEMPLATE_YAML="$REPO_ROOT/.github/morph/opengauss-template.yaml"
if [ -f "$LOCAL_TEMPLATE_YAML" ]; then
DEFAULT_INSTALL_TARGET="$LOCAL_TEMPLATE_YAML"
else
DEFAULT_INSTALL_TARGET="opengauss"
fi
INSTALL_TARGET="${OPEN_GAUSS_INSTALL_TARGET:-${OPEN_GAUSS_TEMPLATE_TARGET:-$DEFAULT_INSTALL_TARGET}}"
DEFAULT_SESSION_NAME="gauss"
SESSION_NAME="${OPEN_GAUSS_SESSION_NAME:-$DEFAULT_SESSION_NAME}"
Expand Down
Loading