fix: run install.sh when piped via curl | bash (#36)#37
Merged
Conversation
The entrypoint guard referenced ${BASH_SOURCE[0]} directly while the
script runs under `set -euo pipefail`. When invoked as
`curl ... | bash`, bash reads from stdin and the BASH_SOURCE array is
empty, so `${BASH_SOURCE[0]}` aborts with "unbound variable" before
install() ever runs — the documented install path installed nothing.
Default BASH_SOURCE[0] to $0 so the guard is both safe under `set -u`
and still true when piped:
- piped (curl|bash): BASH_SOURCE[0] empty -> defaults to $0 -> install runs
- file (bash install.sh): BASH_SOURCE[0] == $0 -> install runs
- sourced (tests): BASH_SOURCE[0] != $0 -> install skipped
Note: the simpler `${BASH_SOURCE[0]:-}` == `${0:-}` only silences the
crash; when piped $0 is "bash" so the comparison is false and install
still never runs. Defaulting to $0 is required to actually fix it.
Fixes #36
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #36. The documented install path
curl -fsSL .../install.sh | bashfailed with:and installed nothing.
Root cause
The entrypoint guard referenced
${BASH_SOURCE[0]}directly while the script runs underset -euo pipefail. When piped, bash reads from stdin and theBASH_SOURCEarray is empty, so${BASH_SOURCE[0]}is an unbound-variable fatal error underset -u— aborting beforeinstall()runs.Fix
Defaulting
BASH_SOURCE[0]to$0makes the guard correct in all three modes:BASH_SOURCE[0]$0curl | bash)$0bashbash install.sh)install.shinstall.shinstall.shVerification
bash -n install.sh— syntax OKcat install.sh | bash) now entersinstall()and prints the banner (previously aborted at line 203)scripts/test-installer-checksum.sh(which sources the script) still passes —installdoes not auto-run when sourced