From 3ab48cd52e06310eb33a5b4bc5580a95719b839e Mon Sep 17 00:00:00 2001 From: Ridvan Gundogmus Date: Tue, 11 Nov 2025 12:55:33 +0100 Subject: [PATCH] Fix interactive prompt handling Fix interactive prompt failures in non-interactive environments, add /dev/tty fallback --- .../Packaging.Linux/install-from-source.sh | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/linux/Packaging.Linux/install-from-source.sh b/src/linux/Packaging.Linux/install-from-source.sh index 19ccb6b61..4e640aa07 100755 --- a/src/linux/Packaging.Linux/install-from-source.sh +++ b/src/linux/Packaging.Linux/install-from-source.sh @@ -40,18 +40,26 @@ if [ -z $is_ci ]; then Git Credential Manager is licensed under the MIT License: https://aka.ms/gcm/license" - while true; do - read -p "Do you want to continue? [Y/n] " yn - case $yn in - [Yy]*|"") - break - ;; - [Nn]*) - exit - ;; - *) - echo "Please answer yes or no." - ;; + while true; do + # Display prompt once before reading input + printf "Do you want to continue? [Y/n] " + + # Prefer reading from the controlling terminal (TTY) when available, + # so that input works even if the script is piped (e.g. curl URL | sh) + if [ -r /dev/tty ]; then + read yn < /dev/tty + # If no TTY is available, attempt to read from standard input (stdin) + elif ! read yn; then + # If input is not possible via TTY or stdin, assume a non-interactive environment + # and abort with guidance for automated usage + echo "Interactive prompt unavailable in this environment. Use 'sh -s -- -y' for automated install." + exit 1 + fi + + case "$yn" in + [Yy]*|"") break ;; + [Nn]*) exit ;; + *) echo "Please answer yes or no." ;; esac done fi