Skip to content

Commit 49db5a0

Browse files
fix(install): protect piped stdin from consumption by child commands
When remote-install.sh is piped to bash, child commands (git clone/fetch, install.sh) could consume stdin and swallow the rest of the script. Fixes: - Add </dev/null to git clone/fetch/checkout commands - Redirect install.sh stdin from /dev/null when not running in a TTY Co-authored-by: Venkat SF <venkatesh.sakamuri@stayflexi.com>
1 parent 8bac4eb commit 49db5a0

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎scripts/self-host/remote-install.sh‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,19 +272,20 @@ get_latest_release_tag_git() {
272272
clone_or_update() {
273273
local target_ref="$1"
274274

275+
# When piped, git commands can consume stdin. Redirect from /dev/null.
275276
if [[ -d "$DEEPSQL_HOME/.git" ]]; then
276277
info "Updating existing checkout at $DEEPSQL_HOME..."
277278
cd "$DEEPSQL_HOME"
278279

279280
# Fetch latest (include tags)
280-
if ! git fetch --tags origin 2>/dev/null; then
281+
if ! git fetch --tags origin </dev/null 2>/dev/null; then
281282
warn "Failed to fetch updates. Continuing with existing checkout."
282283
fi
283284

284285
if [[ -n "$target_ref" ]]; then
285286
info "Checking out $target_ref..."
286-
git checkout "$target_ref" 2>/dev/null || git checkout -b "$target_ref" "origin/$target_ref" 2>/dev/null || {
287-
git checkout "$target_ref" 2>/dev/null || {
287+
git checkout "$target_ref" </dev/null 2>/dev/null || git checkout -b "$target_ref" "origin/$target_ref" </dev/null 2>/dev/null || {
288+
git checkout "$target_ref" </dev/null 2>/dev/null || {
288289
warn "Could not checkout $target_ref. Staying on current branch."
289290
}
290291
}
@@ -302,7 +303,7 @@ clone_or_update() {
302303
clone_args+=(--branch "$target_ref")
303304
fi
304305

305-
if ! git clone "${clone_args[@]}" "https://github.com/${DEEPSQL_REPO}.git" "$DEEPSQL_HOME"; then
306+
if ! git clone "${clone_args[@]}" "https://github.com/${DEEPSQL_REPO}.git" "$DEEPSQL_HOME" </dev/null; then
306307
error "Failed to clone repository."
307308
exit 1
308309
fi
@@ -367,8 +368,15 @@ run_install() {
367368
info "Running install.sh..."
368369
echo
369370

370-
# Pass through any remaining arguments to install.sh
371-
exec ./scripts/self-host/install.sh "$@"
371+
# Pass through any remaining arguments to install.sh.
372+
# When the script is piped (no TTY), redirect stdin from /dev/null so
373+
# install.sh and its children (docker, git, read, etc.) don't consume
374+
# the rest of the piped script.
375+
if [[ -t 0 ]]; then
376+
exec ./scripts/self-host/install.sh "$@"
377+
else
378+
exec ./scripts/self-host/install.sh "$@" </dev/null
379+
fi
372380
}
373381

374382
# ── Main ──────────────────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)