Skip to content

Commit e639431

Browse files
Various install script fixes
1 parent c1c6ca1 commit e639431

1 file changed

Lines changed: 51 additions & 49 deletions

File tree

scripts/install.sh

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,38 @@ initTmpDir() {
2525
cd "$TMP_DIR"
2626
}
2727

28-
# Ensure that dependency is installed and executable, exit and print help message if not
29-
checkDependency() {
30-
if ! [ -x "$(command -v "$1")" ]; then
31-
printf "'%s' could not be found, this script depends on it, please install and try again.\n" "$1"
32-
exit 1
28+
# Check all required dependencies, printing messages for each missing one before exiting
29+
checkDependencies() {
30+
MISSING=false
31+
if ! [ -x "$(command -v curl)" ]; then
32+
printf "'curl' could not be found, this script depends on it, please install and try again.\n"
33+
MISSING=true
34+
fi
35+
if ! [ -x "$(command -v unzip)" ]; then
36+
printf "'unzip' could not be found, this script depends on it, please install and try again.\n"
37+
MISSING=true
3338
fi
34-
}
35-
36-
# Ensure that 'git' is installed and executable, exit and print help message if not
37-
checkGitDependency() {
3839
if ! [ -x "$(command -v git)" ]; then
3940
publishSyftEvent git_missing
40-
printf "Git could not be found, Rill depends on it, please install and try again.\n\n"
41+
printf "Git could not be found, Rill depends on it, please install and try again.\n"
4142
printf "Helpful instructions: https://github.com/git-guides/install-git\n"
43+
MISSING=true
44+
fi
45+
if ! [ -x "$(command -v shasum)" ] && ! [ -x "$(command -v sha256sum)" ]; then
46+
printf "Neither 'shasum' nor 'sha256sum' could be found, this script depends on one of them, please install one of them and try again.\n"
47+
MISSING=true
48+
fi
49+
if [ "$MISSING" = "true" ]; then
4250
exit 1
4351
fi
4452
}
4553

46-
# Ensure that either 'shasum' or 'sha256sum' is installed and executable, exit and print help message if not
47-
resolveShasumDependency() {
54+
# Verify a checksums file using whichever SHA256 tool is available
55+
sha256Verify() {
4856
if [ -x "$(command -v shasum)" ]; then
49-
sha256_verify="shasum --algorithm 256 --ignore-missing --check"
50-
elif [ -x "$(command -v sha256sum)" ]; then
51-
sha256_verify="sha256sum --ignore-missing --check"
57+
shasum --algorithm 256 --ignore-missing --check "$1"
5258
else
53-
printf "neither 'shasum' or 'sha256sum' could be found, this script depends on one of them, please install one of them and try again.\n"
54-
exit 1
59+
sha256sum --ignore-missing --check "$1"
5560
fi
5661
}
5762

@@ -61,28 +66,30 @@ downloadBinary() {
6166

6267
LATEST_URL="https://${CDN}/rill/latest.txt"
6368
if [ "${VERSION}" = "latest" ]; then
64-
VERSION=$(curl --silent --show-error ${LATEST_URL})
69+
VERSION=$(curl --silent --show-error "${LATEST_URL}")
6570
fi
6671
BINARY_URL="https://${CDN}/rill/${VERSION}/rill_${PLATFORM}.zip"
6772
CHECKSUM_URL="https://${CDN}/rill/${VERSION}/checksums.txt"
6873

74+
printf "Downloading binary: %s\n" "$BINARY_URL"
6975
if [ "$NON_INTERACTIVE" = "true" ]; then
70-
set -- "--silent" "--show-error"
76+
curl --location --silent --show-error "${BINARY_URL}" --output "rill_${PLATFORM}.zip"
7177
else
72-
set -- "--progress-bar"
78+
curl --location --progress-bar "${BINARY_URL}" --output "rill_${PLATFORM}.zip"
7379
fi
7480

75-
printf "Downloading binary: %s\n" "$BINARY_URL"
76-
curl --location "$@" "${BINARY_URL}" --output rill_${PLATFORM}.zip
77-
7881
printf "\nDownloading checksum: %s\n" "$CHECKSUM_URL"
79-
curl --location "$@" "${CHECKSUM_URL}" --output checksums.txt
82+
if [ "$NON_INTERACTIVE" = "true" ]; then
83+
curl --location --silent --show-error "${CHECKSUM_URL}" --output checksums.txt
84+
else
85+
curl --location --progress-bar "${CHECKSUM_URL}" --output checksums.txt
86+
fi
8087

8188
printf "\nVerifying the SHA256 checksum of the downloaded binary:\n"
82-
${sha256_verify} checksums.txt
89+
sha256Verify checksums.txt
8390

8491
printf "\nUnpacking rill_%s.zip\n" "$PLATFORM"
85-
unzip -q rill_${PLATFORM}.zip
92+
unzip -q "rill_${PLATFORM}.zip"
8693
}
8794

8895
# Print install options
@@ -185,7 +192,7 @@ publishSyftEvent() {
185192
SYFT_URL=https://event.syftdata.com/log
186193
SYFT_ID=clp76quhs0006l908bux79l4v
187194
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
195+
curl --silent --show-error --header "Authorization: ${SYFT_ID}" --header "Content-Type: application/json" --data "{\"event_name\":\"$1\"}" "$SYFT_URL" > /dev/null 2>&1 || true
189196
fi
190197
}
191198

@@ -289,10 +296,7 @@ installRill() {
289296
if [ "$NON_INTERACTIVE" != "true" ]; then
290297
publishSyftEvent install
291298
fi
292-
checkDependency curl
293-
checkDependency unzip
294-
checkGitDependency
295-
resolveShasumDependency
299+
checkDependencies
296300
initPlatform
297301
resolveInstallDir
298302
initTmpDir
@@ -308,7 +312,10 @@ installRill() {
308312

309313
# Uninstall Rill from the system, this function is aware of both the privileged and unprivileged install methods
310314
uninstallRill() {
311-
checkDependency sed
315+
if ! [ -x "$(command -v sed)" ]; then
316+
printf "'sed' could not be found, this script depends on it, please install and try again.\n"
317+
exit 1
318+
fi
312319
initPlatform
313320

314321
if [ -f "/usr/local/bin/rill" ]
@@ -328,23 +335,18 @@ set -e
328335
# Default values
329336
INSTALL_DIR_EXPLICIT=false
330337

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
338+
# Detect non-interactive environments (CI, Docker, agents, subprocesses).
339+
# When the script is piped (e.g. "curl | sh"), stdin is not a terminal, but a human may still be present.
340+
# We check /dev/tty to distinguish: in a real terminal, /dev/tty is a terminal device; in CI/Docker/agents, it either doesn't exist or isn't a real terminal.
341+
if [ -t 0 ]; then
342+
# Stdin is a terminal; definitely interactive.
343+
NON_INTERACTIVE=${NON_INTERACTIVE:-false}
344+
elif [ -e /dev/tty ] && sh -c 'exec 3</dev/tty && test -t 3' 2>/dev/null; then
345+
# Stdin is piped but /dev/tty is a real terminal; likely "curl | sh" in an interactive session.
346+
NON_INTERACTIVE=${NON_INTERACTIVE:-false}
347+
else
348+
# Stdin is not a terminal and /dev/tty is not available; default to non-interactive.
349+
NON_INTERACTIVE=${NON_INTERACTIVE:-true}
348350
fi
349351
NON_INTERACTIVE=${NON_INTERACTIVE:-false}
350352

0 commit comments

Comments
 (0)