Skip to content

Commit 3ab48cd

Browse files
authored
Fix interactive prompt handling
Fix interactive prompt failures in non-interactive environments, add /dev/tty fallback
1 parent ede8541 commit 3ab48cd

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/linux/Packaging.Linux/install-from-source.sh

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,26 @@ if [ -z $is_ci ]; then
4040
4141
Git Credential Manager is licensed under the MIT License: https://aka.ms/gcm/license"
4242

43-
while true; do
44-
read -p "Do you want to continue? [Y/n] " yn
45-
case $yn in
46-
[Yy]*|"")
47-
break
48-
;;
49-
[Nn]*)
50-
exit
51-
;;
52-
*)
53-
echo "Please answer yes or no."
54-
;;
43+
while true; do
44+
# Display prompt once before reading input
45+
printf "Do you want to continue? [Y/n] "
46+
47+
# Prefer reading from the controlling terminal (TTY) when available,
48+
# so that input works even if the script is piped (e.g. curl URL | sh)
49+
if [ -r /dev/tty ]; then
50+
read yn < /dev/tty
51+
# If no TTY is available, attempt to read from standard input (stdin)
52+
elif ! read yn; then
53+
# If input is not possible via TTY or stdin, assume a non-interactive environment
54+
# and abort with guidance for automated usage
55+
echo "Interactive prompt unavailable in this environment. Use 'sh -s -- -y' for automated install."
56+
exit 1
57+
fi
58+
59+
case "$yn" in
60+
[Yy]*|"") break ;;
61+
[Nn]*) exit ;;
62+
*) echo "Please answer yes or no." ;;
5563
esac
5664
done
5765
fi

0 commit comments

Comments
 (0)