unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#58345] [PATCH 0/3] Customize PS1 on foreign distributions
@ 2022-10-07  5:27 Maxim Cournoyer
  2022-10-07  5:31 ` [bug#58345] [PATCH 1/3] guix-install.sh: Improve prompt_yes_no procedure Maxim Cournoyer
  0 siblings, 1 reply; 8+ messages in thread
From: Maxim Cournoyer @ 2022-10-07  5:27 UTC (permalink / raw)
  To: 58345; +Cc: Maxim Cournoyer

Hi!

The following fixes a usability issue, which is that users entering 'guix
shell' or 'guix environment' would not have any visual feedback in the prompt
about where they are.  I've tested it on three different foreign
distributions, and it worked well on all of them.

Thanks,

Maxim Cournoyer (3):
  guix-install.sh: Improve prompt_yes_no procedure.
  guix-install.sh: Introduce 'die' utility function.
  guix-install.sh: Add Bash prompt customization option.

 etc/guix-install.sh | 69 +++++++++++++++++++++++++++++++--------------
 1 file changed, 48 insertions(+), 21 deletions(-)

-- 
2.37.3





^ permalink raw reply	[flat|nested] 8+ messages in thread

* [bug#58345] [PATCH 1/3] guix-install.sh: Improve prompt_yes_no procedure.
  2022-10-07  5:27 [bug#58345] [PATCH 0/3] Customize PS1 on foreign distributions Maxim Cournoyer
@ 2022-10-07  5:31 ` Maxim Cournoyer
  2022-10-07  5:31   ` [bug#58345] [PATCH 2/3] guix-install.sh: Introduce 'die' utility function Maxim Cournoyer
  2022-10-07  5:32   ` [bug#58345] [PATCH 3/3] guix-install.sh: Add Bash prompt customization option Maxim Cournoyer
  0 siblings, 2 replies; 8+ messages in thread
From: Maxim Cournoyer @ 2022-10-07  5:31 UTC (permalink / raw)
  To: 58345; +Cc: Maxim Cournoyer

* 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.
---
 etc/guix-install.sh | 28 +++++++++++++++++++---------
 1 file 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"
-- 
2.37.3





^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [bug#58345] [PATCH 2/3] guix-install.sh: Introduce 'die' utility function.
  2022-10-07  5:31 ` [bug#58345] [PATCH 1/3] guix-install.sh: Improve prompt_yes_no procedure Maxim Cournoyer
@ 2022-10-07  5:31   ` Maxim Cournoyer
  2022-10-07  8:30     ` zimoun
  2022-10-07  5:32   ` [bug#58345] [PATCH 3/3] guix-install.sh: Add Bash prompt customization option Maxim Cournoyer
  1 sibling, 1 reply; 8+ messages in thread
From: Maxim Cournoyer @ 2022-10-07  5:31 UTC (permalink / raw)
  To: 58345; +Cc: Maxim Cournoyer

* etc/guix-install.sh (die): New function.
(chk_sys_arch): Use it.
(guix_get_bin_list, guix_get_bin, sys_create_store): Likewise.
---
 etc/guix-install.sh | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 8c05d19657..6bf70b7941 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -99,6 +99,11 @@ _flush()
     done
 }
 
+die()
+{
+    _err "${ERR}$*"
+}
+
 # Return true if user answered yes, false otherwise.  It defaults to "yes"
 # when a single newline character is input.
 # $1: The prompt question.
@@ -230,8 +235,7 @@ chk_sys_arch()
             local arch=powerpc64le
             ;;
         *)
-            _err "${ERR}Unsupported CPU type: ${arch}"
-            exit 1
+            die "Unsupported CPU type: ${arch}"
     esac
 
     case "$os" in
@@ -239,8 +243,7 @@ chk_sys_arch()
             local os=linux
             ;;
         *)
-            _err "${ERR}Your operation system (${os}) is not supported."
-            exit 1
+            die "Your operation system (${os}) is not supported."
     esac
 
     ARCH_OS="${arch}-${os}"
@@ -295,8 +298,7 @@ guix_get_bin_list()
     if [[ "${#bin_ver_ls}" -ne "0" ]]; then
         _msg "${PAS}Release for your system: ${default_ver}"
     else
-        _err "${ERR}Could not obtain list of Guix releases."
-        exit 1
+        die "Could not obtain list of Guix releases."
     fi
 
     # Use default to download according to the list and local ARCH_OS.
@@ -321,8 +323,7 @@ guix_get_bin()
             "${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig"; then
         _msg "${PAS}download completed."
     else
-        _err "${ERR}could not download ${url}/${bin_ver}.tar.xz."
-        exit 1
+        die "could not download ${url}/${bin_ver}.tar.xz."
     fi
 
     pushd "${dl_path}" >/dev/null
@@ -330,8 +331,7 @@ guix_get_bin()
         _msg "${PAS}Signature is valid."
         popd >/dev/null
     else
-        _err "${ERR}could not verify the signature."
-        exit 1
+        die "could not verify the signature."
     fi
 }
 
@@ -343,8 +343,7 @@ sys_create_store()
     _debug "--- [ ${FUNCNAME[0]} ] ---"
 
     if [[ -e "/var/guix" || -e "/gnu" ]]; then
-        _err "${ERR}A previous Guix installation was found.  Refusing to overwrite."
-        exit 1
+        die "A previous Guix installation was found.  Refusing to overwrite."
     fi
 
     cd "$tmp_path"
-- 
2.37.3





^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [bug#58345] [PATCH 3/3] guix-install.sh: Add Bash prompt customization option.
  2022-10-07  5:31 ` [bug#58345] [PATCH 1/3] guix-install.sh: Improve prompt_yes_no procedure Maxim Cournoyer
  2022-10-07  5:31   ` [bug#58345] [PATCH 2/3] guix-install.sh: Introduce 'die' utility function Maxim Cournoyer
@ 2022-10-07  5:32   ` Maxim Cournoyer
  2022-10-07  8:34     ` zimoun
  1 sibling, 1 reply; 8+ messages in thread
From: Maxim Cournoyer @ 2022-10-07  5:32 UTC (permalink / raw)
  To: 58345; +Cc: Maxim Cournoyer

* etc/guix-install.sh (sys_customize_bashrc): New function.
(main): Use it.
---
 etc/guix-install.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 6bf70b7941..2b304d1bdc 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -566,6 +566,23 @@ sys_create_shell_completion()
         _msg "${PAS}installed shell completion"
 }
 
+sys_customize_bashrc()
+{
+    prompt_yes_no "Customize users Bash shell prompt for Guix?" || return
+    for bashrc in /home/*/.bashrc /root/.bashrc; do
+        test -f "$bashrc" || continue
+        grep -Fq '$GUIX_ENVIRONMENT' "$bashrc" && continue
+        cp "${bashrc}" "${bashrc}.bak"
+        echo '
+if [ -n "$GUIX_ENVIRONMENT" ]; then
+    if [[ $PS1 =~ (.*)"\\$" ]]; then
+        PS1="${BASH_REMATCH[1]} [env]\\\$ "
+    fi
+fi
+' >> "$bashrc"
+    done
+    _msg "${PAS}Bash shell prompt successfully customized for Guix"
+}
 
 welcome()
 {
@@ -635,6 +652,7 @@ main()
     sys_authorize_build_farms
     sys_create_init_profile
     sys_create_shell_completion
+    sys_customize_bashrc
 
     _msg "${INF}cleaning up ${tmp_path}"
     rm -r "${tmp_path}"
-- 
2.37.3





^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [bug#58345] [PATCH 2/3] guix-install.sh: Introduce 'die' utility function.
  2022-10-07  5:31   ` [bug#58345] [PATCH 2/3] guix-install.sh: Introduce 'die' utility function Maxim Cournoyer
@ 2022-10-07  8:30     ` zimoun
  2022-10-07 12:23       ` Maxim Cournoyer
  0 siblings, 1 reply; 8+ messages in thread
From: zimoun @ 2022-10-07  8:30 UTC (permalink / raw)
  To: Maxim Cournoyer, 58345; +Cc: Maxim Cournoyer

Hi Maxim,

On ven., 07 oct. 2022 at 01:31, Maxim Cournoyer <maxim.cournoyer@gmail.com> wrote:

> +die()
> +{
> +    _err "${ERR}$*"
> +}
> +

[...]

> -            _err "${ERR}Unsupported CPU type: ${arch}"
> -            exit 1
> +            die "Unsupported CPU type: ${arch}"

This new script using ’die’, does it exit correctly and return an
appropriated exit code on failure?



Cheers,
simon




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [bug#58345] [PATCH 3/3] guix-install.sh: Add Bash prompt customization option.
  2022-10-07  5:32   ` [bug#58345] [PATCH 3/3] guix-install.sh: Add Bash prompt customization option Maxim Cournoyer
@ 2022-10-07  8:34     ` zimoun
  2022-10-07 12:28       ` bug#58345: " Maxim Cournoyer
  0 siblings, 1 reply; 8+ messages in thread
From: zimoun @ 2022-10-07  8:34 UTC (permalink / raw)
  To: Maxim Cournoyer, 58345; +Cc: Maxim Cournoyer

Hi Maxim,

On ven., 07 oct. 2022 at 01:32, Maxim Cournoyer <maxim.cournoyer@gmail.com> wrote:
> * etc/guix-install.sh (sys_customize_bashrc): New function.
> (main): Use it.

Nice idea!

> +sys_customize_bashrc()
> +{
> +    prompt_yes_no "Customize users Bash shell prompt for Guix?" || return
> +    for bashrc in /home/*/.bashrc /root/.bashrc; do
> +        test -f "$bashrc" || continue
> +        grep -Fq '$GUIX_ENVIRONMENT' "$bashrc" && continue
> +        cp "${bashrc}" "${bashrc}.bak"
> +        echo '

Maybe comment, something like:

# Automatically added by Guix install script
> +if [ -n "$GUIX_ENVIRONMENT" ]; then
> +    if [[ $PS1 =~ (.*)"\\$" ]]; then
> +        PS1="${BASH_REMATCH[1]} [env]\\\$ "
> +    fi
> +fi
> +' >> "$bashrc"
> +    done
> +    _msg "${PAS}Bash shell prompt successfully customized for Guix"
> +}

LGTM!


Cheers,
simon




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [bug#58345] [PATCH 2/3] guix-install.sh: Introduce 'die' utility function.
  2022-10-07  8:30     ` zimoun
@ 2022-10-07 12:23       ` Maxim Cournoyer
  0 siblings, 0 replies; 8+ messages in thread
From: Maxim Cournoyer @ 2022-10-07 12:23 UTC (permalink / raw)
  To: zimoun; +Cc: 58345

Hello,

zimoun <zimon.toutoune@gmail.com> writes:

> Hi Maxim,
>
> On ven., 07 oct. 2022 at 01:31, Maxim Cournoyer <maxim.cournoyer@gmail.com> wrote:
>
>> +die()
>> +{
>> +    _err "${ERR}$*"
>> +}
>> +
>
> [...]
>
>> -            _err "${ERR}Unsupported CPU type: ${arch}"
>> -            exit 1
>> +            die "Unsupported CPU type: ${arch}"
>
> This new script using ’die’, does it exit correctly and return an
> appropriated exit code on failure?

Good catch, I had forgotten to include "exit 1" after the _err call in
die().

Fixed!

-- 
Thanks,
Maxim




^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#58345: [PATCH 3/3] guix-install.sh: Add Bash prompt customization option.
  2022-10-07  8:34     ` zimoun
@ 2022-10-07 12:28       ` Maxim Cournoyer
  0 siblings, 0 replies; 8+ messages in thread
From: Maxim Cournoyer @ 2022-10-07 12:28 UTC (permalink / raw)
  To: zimoun; +Cc: 58345-done

Hello,

zimoun <zimon.toutoune@gmail.com> writes:

> Hi Maxim,
>
> On ven., 07 oct. 2022 at 01:32, Maxim Cournoyer <maxim.cournoyer@gmail.com> wrote:
>> * etc/guix-install.sh (sys_customize_bashrc): New function.
>> (main): Use it.
>
> Nice idea!
>
>> +sys_customize_bashrc()
>> +{
>> +    prompt_yes_no "Customize users Bash shell prompt for Guix?" || return
>> +    for bashrc in /home/*/.bashrc /root/.bashrc; do
>> +        test -f "$bashrc" || continue
>> +        grep -Fq '$GUIX_ENVIRONMENT' "$bashrc" && continue
>> +        cp "${bashrc}" "${bashrc}.bak"
>> +        echo '
>
> Maybe comment, something like:
>
> # Automatically added by Guix install script
>> +if [ -n "$GUIX_ENVIRONMENT" ]; then
>> +    if [[ $PS1 =~ (.*)"\\$" ]]; then
>> +        PS1="${BASH_REMATCH[1]} [env]\\\$ "
>> +    fi
>> +fi
>> +' >> "$bashrc"
>> +    done
>> +    _msg "${PAS}Bash shell prompt successfully customized for Guix"
>> +}

Good idea!  Applied, like:

@@ -575,6 +575,7 @@ sys_customize_bashrc()
         grep -Fq '$GUIX_ENVIRONMENT' "$bashrc" && continue
         cp "${bashrc}" "${bashrc}.bak"
         echo '
+# Automatically added by the Guix install script.
 if [ -n "$GUIX_ENVIRONMENT" ]; then
     if [[ $PS1 =~ (.*)"\\$" ]]; then
         PS1="${BASH_REMATCH[1]} [env]\\\$ "

>
> LGTM!

Alright, the series have been pushed to master, and the script available
at https://guix.gnu.org/install.sh should soon reflect the changes.

Thanks for reviewing!

-- 
Maxim




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-10-07 14:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-07  5:27 [bug#58345] [PATCH 0/3] Customize PS1 on foreign distributions Maxim Cournoyer
2022-10-07  5:31 ` [bug#58345] [PATCH 1/3] guix-install.sh: Improve prompt_yes_no procedure Maxim Cournoyer
2022-10-07  5:31   ` [bug#58345] [PATCH 2/3] guix-install.sh: Introduce 'die' utility function Maxim Cournoyer
2022-10-07  8:30     ` zimoun
2022-10-07 12:23       ` Maxim Cournoyer
2022-10-07  5:32   ` [bug#58345] [PATCH 3/3] guix-install.sh: Add Bash prompt customization option Maxim Cournoyer
2022-10-07  8:34     ` zimoun
2022-10-07 12:28       ` bug#58345: " Maxim Cournoyer

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).