Skip to content

Commit 4654041

Browse files
Fix interactive input for curl ... | bash style installation (#51)
1 parent 4d718c0 commit 4654041

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

install/swiftly-install.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ has_command () {
2525

2626
read_input_with_default () {
2727
echo -n "> "
28-
read READ_INPUT_RETURN
28+
# The installer script is usually run by "curl ... | bash", which means that
29+
# stdin is not a tty but the script content itself. In that case, "read" builtin
30+
# command receives EOF immediately. To avoid that, we use /dev/tty as stdin explicitly.
31+
# SWIFTLY_READ_FROM_STDIN is used for testing interactive input
32+
if [[ -t 0 ]] || [[ ${SWIFTLY_READ_FROM_STDIN+set} == "set" ]]; then
33+
read READ_INPUT_RETURN
34+
else
35+
read READ_INPUT_RETURN < /dev/tty
36+
fi
2937

3038
if [ -z "$READ_INPUT_RETURN" ]; then
3139
READ_INPUT_RETURN="$1"

install/test-util.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# Common utility functionality used in the various bash tests for swiftly-install.sh.
44

5+
export SWIFTLY_READ_FROM_STDIN=1
6+
57
has_command () {
68
command -v "$1" > /dev/null
79
}

install/tests/overwrite.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ echo "$DUMMY_CONFIG_CONTENTS" > "$SWIFTLY_HOME_DIR/config.json"
2727
mkdir "$SWIFTLY_HOME_DIR/toolchains/5.7.3"
2828

2929
# Attempt the same installation, but decline to overwrite.
30-
printf "1\nn\n" | ./swiftly-install.sh
30+
printf "1\nn\n" | ./swiftly-install.sh
3131

3232
if ! has_command "swiftly" ; then
3333
test_fail "Can't find swiftly on the PATH"
@@ -43,7 +43,7 @@ if [[ ! -d "$SWIFTLY_HOME_DIR/toolchains/5.7.3" ]]; then
4343
fi
4444

4545
# Attempt the same installation, but overwrite this time.
46-
printf "1\ny\n" | ./swiftly-install.sh
46+
printf "1\ny\n" | ./swiftly-install.sh
4747

4848
if ! has_command "swiftly" ; then
4949
test_fail "Can't find swiftly on the PATH"

0 commit comments

Comments
 (0)