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.
This commit is contained in:
parent
8319be779f
commit
6a2e303d3a
1 changed files with 19 additions and 9 deletions
|
@ -9,7 +9,7 @@
|
||||||
# Copyright © 2020 Daniel Brooks <db48x@db48x.net>
|
# Copyright © 2020 Daniel Brooks <db48x@db48x.net>
|
||||||
# Copyright © 2021 Jakub Kądziołka <kuba@kadziolka.net>
|
# Copyright © 2021 Jakub Kądziołka <kuba@kadziolka.net>
|
||||||
# Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
|
# 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.
|
# This file is part of GNU Guix.
|
||||||
#
|
#
|
||||||
|
@ -92,15 +92,25 @@ _debug()
|
||||||
fi
|
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.
|
# $1: The prompt question.
|
||||||
prompt_yes_no() {
|
prompt_yes_no() {
|
||||||
while true; do
|
while true; do
|
||||||
read -rp "$1 " yn
|
_flush
|
||||||
|
read -N1 -rsp "$1 [Y/n]" yn
|
||||||
case $yn in
|
case $yn in
|
||||||
[Yy]*) return 0;;
|
$'\n') echo && return 0;;
|
||||||
[Nn]*) return 1;;
|
[Yy]*) echo && return 0;;
|
||||||
*) _msg "Please answer yes or no."
|
[Nn]*) echo && return 1;;
|
||||||
|
*) echo && _msg "Please answer yes or no."
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -137,7 +147,7 @@ chk_gpg_keyring()
|
||||||
if ! gpg --dry-run --list-keys "$gpg_key_id" >/dev/null 2>&1; then
|
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 \
|
if prompt_yes_no "${INF}The following OpenPGP public key is \
|
||||||
required to verify the Guix binary signature: $gpg_key_id.
|
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" \
|
wget "https://sv.gnu.org/people/viewgpg.php?user_id=$user_id" \
|
||||||
--no-verbose -O- | gpg --import -
|
--no-verbose -O- | gpg --import -
|
||||||
else
|
else
|
||||||
|
@ -254,7 +264,7 @@ chk_sys_nscd()
|
||||||
configure_substitute_discovery() {
|
configure_substitute_discovery() {
|
||||||
if grep -q -- '--discover=no' "$1" && \
|
if grep -q -- '--discover=no' "$1" && \
|
||||||
prompt_yes_no "Would you like the Guix daemon to automatically \
|
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"
|
sed -i 's/--discover=no/--discover=yes/' "$1"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -490,7 +500,7 @@ sys_enable_guix_daemon()
|
||||||
sys_authorize_build_farms()
|
sys_authorize_build_farms()
|
||||||
{ # authorize the public key of the build farm
|
{ # authorize the public key of the build farm
|
||||||
if prompt_yes_no "Permit downloading pre-built package binaries from the \
|
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 \
|
guix archive --authorize \
|
||||||
< ~root/.config/guix/current/share/guix/ci.guix.gnu.org.pub \
|
< ~root/.config/guix/current/share/guix/ci.guix.gnu.org.pub \
|
||||||
&& _msg "${PAS}Authorized public key for ci.guix.gnu.org"
|
&& _msg "${PAS}Authorized public key for ci.guix.gnu.org"
|
||||||
|
|
Reference in a new issue