Skip to content

Commit 2ef16a0

Browse files
Fix install script failing when piped in a login shell
1 parent c1c6ca1 commit 2ef16a0

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

scripts/install.sh

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,28 @@ checkGitDependency() {
4343
fi
4444
}
4545

46-
# Ensure that either 'shasum' or 'sha256sum' is installed and executable, exit and print help message if not
46+
# Ensure that either 'shasum' or 'sha256sum' is installed and executable, exit and print help message if not.
47+
# Sets SHA256_CMD to the resolved command name for use by sha256Verify.
4748
resolveShasumDependency() {
4849
if [ -x "$(command -v shasum)" ]; then
49-
sha256_verify="shasum --algorithm 256 --ignore-missing --check"
50+
SHA256_CMD="shasum"
5051
elif [ -x "$(command -v sha256sum)" ]; then
51-
sha256_verify="sha256sum --ignore-missing --check"
52+
SHA256_CMD="sha256sum"
5253
else
5354
printf "neither 'shasum' or 'sha256sum' could be found, this script depends on one of them, please install one of them and try again.\n"
5455
exit 1
5556
fi
5657
}
5758

59+
# Verify a checksums file using the resolved SHA256 command
60+
sha256Verify() {
61+
if [ "$SHA256_CMD" = "shasum" ]; then
62+
shasum --algorithm 256 --ignore-missing --check "$1"
63+
else
64+
sha256sum --ignore-missing --check "$1"
65+
fi
66+
}
67+
5868
# Download the binary and check the integrity using the SHA256 checksum
5969
downloadBinary() {
6070
CDN="cdn.rilldata.com"
@@ -66,20 +76,22 @@ downloadBinary() {
6676
BINARY_URL="https://${CDN}/rill/${VERSION}/rill_${PLATFORM}.zip"
6777
CHECKSUM_URL="https://${CDN}/rill/${VERSION}/checksums.txt"
6878

79+
printf "Downloading binary: %s\n" "$BINARY_URL"
6980
if [ "$NON_INTERACTIVE" = "true" ]; then
70-
set -- "--silent" "--show-error"
81+
curl --location --silent --show-error "${BINARY_URL}" --output rill_${PLATFORM}.zip
7182
else
72-
set -- "--progress-bar"
83+
curl --location --progress-bar "${BINARY_URL}" --output rill_${PLATFORM}.zip
7384
fi
7485

75-
printf "Downloading binary: %s\n" "$BINARY_URL"
76-
curl --location "$@" "${BINARY_URL}" --output rill_${PLATFORM}.zip
77-
7886
printf "\nDownloading checksum: %s\n" "$CHECKSUM_URL"
79-
curl --location "$@" "${CHECKSUM_URL}" --output checksums.txt
87+
if [ "$NON_INTERACTIVE" = "true" ]; then
88+
curl --location --silent --show-error "${CHECKSUM_URL}" --output checksums.txt
89+
else
90+
curl --location --progress-bar "${CHECKSUM_URL}" --output checksums.txt
91+
fi
8092

8193
printf "\nVerifying the SHA256 checksum of the downloaded binary:\n"
82-
${sha256_verify} checksums.txt
94+
sha256Verify checksums.txt
8395

8496
printf "\nUnpacking rill_%s.zip\n" "$PLATFORM"
8597
unzip -q rill_${PLATFORM}.zip
@@ -185,7 +197,7 @@ publishSyftEvent() {
185197
SYFT_URL=https://event.syftdata.com/log
186198
SYFT_ID=clp76quhs0006l908bux79l4v
187199
if [ -z "$RILL_INSTALL_DISABLE_TELEMETRY" ]; then
188-
curl --silent --show-error --header "Authorization: ${SYFT_ID}" --header "Content-Type: application/json" --data "{\"event_name\":\"$1\"}" $SYFT_URL > /dev/null || true >&2
200+
curl --silent --show-error --header "Authorization: ${SYFT_ID}" --header "Content-Type: application/json" --data "{\"event_name\":\"$1\"}" $SYFT_URL > /dev/null 2>&1 || true
189201
fi
190202
}
191203

@@ -328,23 +340,11 @@ set -e
328340
# Default values
329341
INSTALL_DIR_EXPLICIT=false
330342

331-
# Default to non-interactive if STDIN is not a terminal (usually indicates e.g. agent, CI, subprocess).
332-
# Backwards compatibility: Old versions of `rill upgrade` didn't pass STDIN through, so we stay interactive if the parent process is named `rill`.
333-
if ! [ -t 0 ]; then
334-
# Get parent process name
335-
PARENT_NAME=""
336-
if [ -n "$PPID" ]; then
337-
if [ -f "/proc/$PPID/comm" ]; then
338-
PARENT_NAME=$(basename "$(cat "/proc/$PPID/comm" 2>/dev/null)" 2>/dev/null)
339-
elif command -v ps >/dev/null 2>&1; then
340-
PARENT_NAME=$(basename "$(ps -o comm= -p "$PPID" 2>/dev/null)" 2>/dev/null)
341-
fi
342-
fi
343-
344-
# Apply the default
345-
if [ "$PARENT_NAME" != "rill" ]; then
346-
NON_INTERACTIVE=${NON_INTERACTIVE:-true}
347-
fi
343+
# Default to non-interactive if /dev/tty is not available (e.g. CI, Docker, headless environments).
344+
# We check /dev/tty rather than stdin because the script may be piped (curl | sh) while a
345+
# terminal is still available for user prompts (which read from /dev/tty).
346+
if ! [ -w /dev/tty ] 2>/dev/null; then
347+
NON_INTERACTIVE=${NON_INTERACTIVE:-true}
348348
fi
349349
NON_INTERACTIVE=${NON_INTERACTIVE:-false}
350350

0 commit comments

Comments
 (0)