From 2ad288c091a8dbb230597653d478bcc1972fe9a2 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Sun, 12 Apr 2026 22:30:58 +0100 Subject: [PATCH] Fix streamed installer entrypoint --- install.sh | 13 ++++++++++-- scripts/tests/test-server-install.sh | 31 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index c30c2c4e6..91c8c7786 100755 --- a/install.sh +++ b/install.sh @@ -379,6 +379,15 @@ check_root() { fi } +installer_command_name() { + if [[ "$0" == "bash" ]] || [[ ! -f "$0" ]]; then + printf 'install.sh\n' + return 0 + fi + + basename "$0" +} + # V3 is deprecated - no longer checking for it detect_os() { @@ -4150,7 +4159,7 @@ parse_args() { fi ;; -h|--help) - echo "Usage: $0 [OPTIONS]" + echo "Usage: $(installer_command_name) [OPTIONS]" echo "" echo "Installation options:" echo " --rc, --pre Install latest RC/pre-release version" @@ -4181,7 +4190,7 @@ parse_args() { fi } -if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then +if [[ "${BASH_SOURCE[0]:-$0}" == "$0" ]]; then parse_args "$@" auto_detect_container_environment diff --git a/scripts/tests/test-server-install.sh b/scripts/tests/test-server-install.sh index c382c98cd..7984bc581 100755 --- a/scripts/tests/test-server-install.sh +++ b/scripts/tests/test-server-install.sh @@ -175,12 +175,43 @@ test_parse_args_rejects_archive_with_source() { return 0 } +test_installer_runs_when_streamed_over_stdin() { + local tmpdir output_file + tmpdir="$(mktemp -d)" + output_file="${tmpdir}/output.txt" + + if ! cat "${INSTALL_SCRIPT}" | bash -s -- --help >"${output_file}" 2>&1; then + echo "installer failed when streamed to bash" >&2 + cat "${output_file}" >&2 + rm -rf "${tmpdir}" + return 1 + fi + + if grep -q "BASH_SOURCE\\[0\\]: unbound variable" "${output_file}"; then + echo "installer still hit BASH_SOURCE unbound variable when streamed to bash" >&2 + cat "${output_file}" >&2 + rm -rf "${tmpdir}" + return 1 + fi + + if ! grep -q "Usage: install.sh \\[OPTIONS\\]" "${output_file}"; then + echo "expected streamed installer help to show install.sh usage" >&2 + cat "${output_file}" >&2 + rm -rf "${tmpdir}" + return 1 + fi + + rm -rf "${tmpdir}" + return 0 +} + main() { assert_success "infer_release_from_archive_name parses prerelease tarballs" test_infer_release_from_archive_name_supports_prerelease assert_success "download_pulse installs from local archive without network" test_download_pulse_installs_from_local_archive_without_network assert_success "prefetch helper writes archive path via output variable" test_prefetch_pulse_archive_for_container_sets_output_var assert_success "wrong-arch archives fail before replacing the installed binary" test_install_pulse_archive_rejects_mismatched_arch_without_replacing_existing_binary assert_success "parse_args rejects archive with source builds" test_parse_args_rejects_archive_with_source + assert_success "installer supports curl-pipe execution via bash stdin" test_installer_runs_when_streamed_over_stdin if (( failures > 0 )); then echo "Total failures: ${failures}" >&2