Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ main() {
trap - EXIT INT TERM
}

if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
# BASH_SOURCE is unset for curl ... | bash. Keep sourced helpers inert,
# while allowing both file execution and the documented stdin entry point.
if [[ "${BASH_SOURCE[0]:-$0}" == "$0" ]]; then
main "$@"
fi
22 changes: 22 additions & 0 deletions scripts/install_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ set -euo pipefail
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
# Exercise the documented pipe-to-bash entry point, not just sourced helpers.
# Help must work both as a file and through stdin without network or installation.
bash "$script_dir/install.sh" --help > "$work/file-help"
# The pipeline is the entry point under test.
# shellcheck disable=SC2002
cat "$script_dir/install.sh" | bash -s -- --help > "$work/pipe-help"
cmp "$work/file-help" "$work/pipe-help"
grep -q 'Usage: install.sh' "$work/pipe-help"

# No-argument piping must enter main too. Stop at platform detection so this
# regression test cannot install into the host's /usr/local/bin.
mkdir -p "$work/unsupported-platform"
printf '#!/bin/sh\nprintf "UnsupportedTestOS\\n"\n' > "$work/unsupported-platform/uname"
chmod 755 "$work/unsupported-platform/uname"
# Match curl ... | bash with no script arguments.
# shellcheck disable=SC2002
if cat "$script_dir/install.sh" | PATH="$work/unsupported-platform:$PATH" bash > "$work/piped-error" 2>&1; then
echo 'Piped installer unexpectedly accepted an unsupported platform' >&2
exit 1
fi
grep -q 'supported operating systems are Linux and macOS' "$work/piped-error"

mkdir -p "$work/fixture"
printf '#!/bin/sh\nprintf "envctl v9.0.0\\n"\n' > "$work/fixture/envctl"
chmod 755 "$work/fixture/envctl"
Expand Down