summary refs log tree commit diff
path: root/etc
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>2022-10-05 21:48:25 -0400
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>2022-10-07 01:23:05 -0400
commit6a2e303d3a49baf7c222a70b91f453e9efd456c6 (patch)
tree4497a5d11cd686e93973b89bb55d2be39a400849 /etc
parent8319be779f0d780aa801c9fa1be853781c680dda (diff)
downloadguix-6a2e303d3a49baf7c222a70b91f453e9efd456c6.tar.gz
guix-install.sh: Improve prompt_yes_no procedure.
* etc/guix-install.sh (_flush): New function.
(prompt_yes_no): Clear input, then only read the first character, silently.
Add the [Yes/no] string to the message.  When a newline is entered by the
user, treat it as the default value, which is "yes".
(chk_gpg_keyring): Remove "(yes/no)" from the prompt message.
(configure_substitute_discovery): Likewise.
(sys_authorize_build_farms): Likewise.
Diffstat (limited to 'etc')
-rwxr-xr-xetc/guix-install.sh28
1 files changed, 19 insertions, 9 deletions
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 300681e111..8c05d19657 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -9,7 +9,7 @@
 # Copyright © 2020 Daniel Brooks <db48x@db48x.net>
 # Copyright © 2021 Jakub Kądziołka <kuba@kadziolka.net>
 # Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
-# Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+# Copyright © 2021, 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 #
 # This file is part of GNU Guix.
 #
@@ -92,15 +92,25 @@ _debug()
     fi
 }
 
-# Return true if user answered yes, false otherwise.
+_flush()
+{
+    while read -t0; do
+        read -N1
+    done
+}
+
+# Return true if user answered yes, false otherwise.  It defaults to "yes"
+# when a single newline character is input.
 # $1: The prompt question.
 prompt_yes_no() {
     while true; do
-        read -rp "$1 " yn
+        _flush
+        read -N1 -rsp "$1 [Y/n]" yn
         case $yn in
-            [Yy]*) return 0;;
-            [Nn]*) return 1;;
-            *) _msg "Please answer yes or no."
+            $'\n') echo && return 0;;
+            [Yy]*) echo && return 0;;
+            [Nn]*) echo && return 1;;
+            *) echo && _msg "Please answer yes or no."
         esac
     done
 }
@@ -137,7 +147,7 @@ chk_gpg_keyring()
         if ! gpg --dry-run --list-keys "$gpg_key_id" >/dev/null 2>&1; then
             if prompt_yes_no "${INF}The following OpenPGP public key is \
 required to verify the Guix binary signature: $gpg_key_id.
-Would you like me to fetch it for you? (yes/no)"; then
+Would you like me to fetch it for you?"; then
                 wget "https://sv.gnu.org/people/viewgpg.php?user_id=$user_id" \
                      --no-verbose -O- | gpg --import -
             else
@@ -254,7 +264,7 @@ chk_sys_nscd()
 configure_substitute_discovery() {
     if grep -q -- '--discover=no' "$1" && \
             prompt_yes_no "Would you like the Guix daemon to automatically \
-discover substitute servers on the local network? (yes/no)"; then
+discover substitute servers on the local network?"; then
         sed -i 's/--discover=no/--discover=yes/' "$1"
     fi
 }
@@ -490,7 +500,7 @@ sys_enable_guix_daemon()
 sys_authorize_build_farms()
 { # authorize the public key of the build farm
     if prompt_yes_no "Permit downloading pre-built package binaries from the \
-project's build farm? (yes/no)"; then
+project's build farm?"; then
         guix archive --authorize \
              < ~root/.config/guix/current/share/guix/ci.guix.gnu.org.pub \
             && _msg "${PAS}Authorized public key for ci.guix.gnu.org"