unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: 74962@debbugs.gnu.org
Cc: "Maxim Cournoyer" <maxim.cournoyer@gmail.com>,
	"Janneke Nieuwenhuizen" <janneke@gnu.org>,
	"Josselin Poiret" <dev@jpoiret.xyz>,
	"Ludovic Courtès" <ludo@gnu.org>,
	"Mathieu Othacehe" <othacehe@gnu.org>
Subject: [bug#74962] [PATCH v3 3/5] etc/guix-install.sh: Fix quoting and other issues.
Date: Thu, 19 Dec 2024 16:45:31 +0900	[thread overview]
Message-ID: <093604124092d3b024127068cbbeff3f9aa62d76.1734594333.git.maxim.cournoyer@gmail.com> (raw)
In-Reply-To: <3d0ccfc5f28f48b0a4e513e4ebfd3018c85b4407.1734594333.git.maxim.cournoyer@gmail.com>

This change fixes most issues reported by the 'shellcheck' command.

* etc/guix-install.sh (add_init_sys_require): Use -n instead of ! -z.
(sys_create_build_user): Quote variable expansion.
(sys_delete_build_user): Likewise.
(sys_create_shell_completion): Likewise.
(sys_delete_user_profiles): Likewise.
(sys_delete_guix_daemon): Explicitly access first array item.
(sys_create_store): Update shellcheck code to ignore.
(SYSV_INIT_REQUIRE): Ignore unused warning.
(sys_customize_bashrc): Ignore warnings due to using variables inside a
literal.
(main): Replace $@ with $* inside string.

Change-Id: Ia88509b461b3844f2dd5abf9fb21a5b2bbb8a1e1
---

Changes in v3:
 - Add comments to avoid remaining shellcheck warnings.

 etc/guix-install.sh | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 481eb6f12a..8d3d9d224b 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -77,6 +77,7 @@ REQUIRE=(
 
 # Add variables using form FOO_INIT_REQUIRE when init system FOO dependencies
 # should be checked.
+# shellcheck disable=SC2034  # the variable name is computed
 SYSV_INIT_REQUIRE=(
     "daemonize"
 )
@@ -151,7 +152,7 @@ chk_require()
 add_init_sys_require()
 { # Add the elements of FOO_INIT_SYS to REQUIRE
     local init_require="${INIT_SYS}_REQUIRE[@]"
-    if [[ ! -z "$init_require" ]]; then
+    if [[ -n "$init_require" ]]; then
         # Have to add piecemeal because ${!foo[@]} performs direct array key
         # expansion, not indirect plain array expansion.
         for r in "${!init_require}"; do
@@ -390,7 +391,7 @@ sys_create_store()
        ~root/.config/guix/current
 
     GUIX_PROFILE=~root/.config/guix/current
-    # shellcheck disable=SC1090
+    # shellcheck disable=SC1091
     source "${GUIX_PROFILE}/etc/profile"
     _msg "${PAS}activated root profile at ${GUIX_PROFILE}"
 }
@@ -427,12 +428,12 @@ sys_create_build_user()
     for i in $(seq -w 1 10); do
         if id "guixbuilder${i}" &>/dev/null; then
             _msg "${INF}user is already in the system, reset"
-            usermod -g guixbuild -G guixbuild${KVMGROUP}     \
+            usermod -g guixbuild -G "guixbuild${KVMGROUP}"     \
                     -d /var/empty -s "$(which nologin)" \
                     -c "Guix build user $i"             \
                     "guixbuilder${i}";
         else
-            useradd -g guixbuild -G guixbuild${KVMGROUP}     \
+            useradd -g guixbuild -G "guixbuild${KVMGROUP}"     \
                     -d /var/empty -s "$(which nologin)" \
                     -c "Guix build user $i" --system    \
                     "guixbuilder${i}";
@@ -445,7 +446,7 @@ sys_delete_build_user()
 {
     for i in $(seq -w 1 10); do
         if id -u "guixbuilder${i}" &>/dev/null; then
-            userdel -f guixbuilder${i}
+            userdel -f "guixbuilder${i}"
         fi
     done
 
@@ -551,7 +552,7 @@ sys_delete_guix_daemon()
     local local_bin
     local var_guix
 
-    _debug "--- [ $FUNCNAME ] ---"
+    _debug "--- [ ${FUNCNAME[0]} ] ---"
 
     info_path="/usr/local/share/info"
     local_bin="/usr/local/bin"
@@ -681,7 +682,7 @@ sys_create_shell_completion()
 
     { # Just in case
         for dir_shell in $bash_completion $zsh_completion $fish_completion; do
-            [ -d "$dir_shell" ] || mkdir -p $dir_shell
+            [ -d "$dir_shell" ] || mkdir -p "$dir_shell"
         done;
 
         ln -sf ${var_guix}/etc/bash_completion.d/* "$bash_completion";
@@ -696,8 +697,10 @@ sys_customize_bashrc()
 
     for bashrc in /home/*/.bashrc /root/.bashrc; do
         test -f "$bashrc" || continue
+        # shellcheck disable=SC2016  # checking for literal $GUIX_ENVIRONMENT
         grep -Fq '$GUIX_ENVIRONMENT' "$bashrc" && continue
         cp "${bashrc}" "${bashrc}.bak"
+        # shellcheck disable=SC2016,SC2028  # that's also a string literal
         echo '
 # Automatically added by the Guix install script.
 if [ -n "$GUIX_ENVIRONMENT" ]; then
@@ -747,10 +750,10 @@ sys_delete_user_profiles()
     rm -rf ~root/.cache/guix
 
     _msg "${INF}removing .guix-profile, .cache/guix and .config/guix of all /home users"
-    for user in `ls -1 /home`; do
-        rm -f /home/$user/.guix-profile
-        rm -rf /home/$user/.cache/guix
-        rm -rf /home/$user/.config/guix
+    for user in /home/*; do
+        rm -f "/home/$user/.guix-profile"
+        rm -rf "/home/$user/.cache/guix"
+        rm -rf "/home/$user/.config/guix"
     done
 }
 
@@ -898,7 +901,7 @@ main()
         if [ '--uninstall' = "${uninstall_flag}" ]; then
             main_uninstall
         else
-            echo "unsupported parameters: $@"
+            echo "unsupported parameters: $*"
             exit 1
         fi
     fi
-- 
2.46.0





  parent reply	other threads:[~2024-12-19  7:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-19  6:57 [bug#74962] [PATCH] etc/guix-install.sh: Explicit shebang to use /usr/bin/env Maxim Cournoyer
2024-12-19  7:17 ` [bug#74962] [PATCH 1/3] etc/teams.scm: Add etc/guix-install.sh to installer team scope Maxim Cournoyer
2024-12-19  7:17   ` [bug#74962] [PATCH 2/3] etc/guix-install.sh: Explicit shebang to use /usr/bin/env Maxim Cournoyer
2024-12-19  8:18     ` Janneke Nieuwenhuizen
2024-12-19  7:17   ` [bug#74962] [PATCH 3/3] etc/guix-install.sh: Fix quoting and other issues Maxim Cournoyer
2024-12-19  7:45 ` [bug#74962] [PATCH v3 1/5] etc/teams.scm: Add etc/guix-install.sh to installer team scope Maxim Cournoyer
2024-12-19  7:45   ` [bug#74962] [PATCH v3 2/5] etc/guix-install.sh: Explicit shebang to use /usr/bin/env Maxim Cournoyer
2024-12-19  7:45   ` Maxim Cournoyer [this message]
2024-12-19  7:45   ` [bug#74962] [PATCH v3 4/5] etc/guix-install.sh: Remove 'which' commands from requirements Maxim Cournoyer
2024-12-19  7:45   ` [bug#74962] [PATCH v3 5/5] etc/guix-install.sh: Sort requirements Maxim Cournoyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=093604124092d3b024127068cbbeff3f9aa62d76.1734594333.git.maxim.cournoyer@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=74962@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=janneke@gnu.org \
    --cc=ludo@gnu.org \
    --cc=othacehe@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).