curl | bash fails: BASH_SOURCE[0] unset when piped from stdin #5
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
When invoked as
curl -fsSL <url>/workspace/opencode/install.sh | bash,install.shfails immediately withbash: línea 24: BASH_SOURCE[0]: variable sin asignar. This breaks the documented one-line install UX entirely (the entireopenmillas installvalue proposition).Reproduction
(Confirmed on a public-read clone of the repo today; the URL resolves, the script downloads, but bash exits with the errors above before any install logic runs.)
Expected
curl ... | bashshould run the installer interactively (or non-interactively if--yes --no-interactionare appended), with a graceful fallback when the bundle files are not co-located with the install script (because stdin-installed scripts have no on-disk SCRIPT_DIR).Actual
Bash exits at line 24 with
BASH_SOURCE[0]: variable sin asignar, thesource "$SCRIPT_DIR/lib/jsonc.sh"on line 26 fails becauseSCRIPT_DIRresolved to the wrong path (the script's stderr ended up at the user's $HOME), and curl'sFailure writing output to destinationshows the pipe was closed prematurely. Three symptoms of one bug.Root cause
install.shline 24 (and line 28 inopenmillas) computeSCRIPT_DIRfromBASH_SOURCE[0]:When a script is read from stdin (the
curl | bashcase), bash does not populateBASH_SOURCEfor the script being executed.BASH_SOURCE[0]is unset,dirnameof an empty string returns., thecd ... && pwdresolves to$HOME(wherever the user's bash happens to start), and thensource "$SCRIPT_DIR/lib/jsonc.sh"tries/home/<user>/lib/jsonc.shwhich does not exist.The pattern works for
bash workspace/opencode/install.shbecause the script is a real file on disk andBASH_SOURCE[0]is the path to it. It fails forcurl | bashbecause there is no file.This affects
install.shandopenmillas(same pattern), and it is the onlycurl | bashUX we ship.Suggested fix
Make
SCRIPT_DIRresolution tolerant of stdin-sourced scripts. WhenBASH_SOURCE[0]is unset or empty, fall back to:$0(may bebashitself if the user's shell invoked it that way — not useful).BUNDLE_DIR=<tmpdir>. This is what the spec's §2.3 already calls for — but it requiresinstall.shto reach that point, which it currently cannot because of theSCRIPT_DIRcrash at line 24.Concretely, replace the line 24 pattern with something like:
And then early in
cmd_install, ifBUNDLE_DIRis empty, fetch the bundle from$REMOTE_RAW_BASEinto a temp dir and setBUNDLE_DIRto that. This makes thecurl | bashUX work.Apply the same pattern to
workspace/opencode/openmillas(line 28-ish) so the post-install CLI also doesn't crash if someone runs it from a piped context.Verification
After fix, the following must succeed on a Linux box:
The existing
bash workspace/opencode/install.sh(local checkout) UX must continue to work — the test harness atworkspace/opencode/tests/test_install.shcovers that.Severity
High. This is the only documented install UX for end users; the existing
deploy.sh --installflow is targeted at maintainers. Shipping without fixing this means everycurl | bashinstall fails on the first line.Related
workspace/opencode/install.shline 24:SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)".workspace/opencode/openmillasline ~28: same pattern.PLAN_installer.md§10 step 5 mentions "Backwards compatibility note:install.shworks on acurl | bashinvocation" — this was incorrect; the file does not currently handle the stdin case.