gnuboot-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1 08/14] scripts: misc: guix.sh: make it pass shellcheck.


From: Denis 'GNUtoo' Carikli
Subject: [PATCH v1 08/14] scripts: misc: guix.sh: make it pass shellcheck.
Date: Fri, 19 Apr 2024 19:06:25 +0200

Without this fix, running shellcheck -x on
resources/scripts/misc/guix.sh returns many errors.

For each guix version declaration we have something like that:
    In resources/scripts/misc/guix.sh line 21:
    guix_v0_0="6365068393254e1131ab80eb0d68a759e7fd2256"
    ^-------^ SC2034 (warning): guix_v0_0 appears unused.
    Verify use (or export if used externally).
and here the variables are actually used in this code:
    guix_version_commit()
    {
        version="$1"

        eval echo "$(echo \$guix_"${version}" | sed 's#\.#_#g')"
    }
so we workaround by disabling that test for each version declaration.

Then shellcheck cannot find "$GUIX_PROFILE"/etc/profile:
In resources/scripts/misc/guix.sh line 91:
        . "$GUIX_PROFILE"/etc/profile
          ^-------------------------^ SC1091 (info):
   Not following: ./etc/profile: openBinaryFile:
   does not exist (No such file or directory)
so we disabled that test for this line.

After that we have many issues with quoting like this one:
    In resources/scripts/misc/guix.sh line 104:
        eval echo $(echo \$guix_"${version}" | sed 's#\.#_#g')
                  ^-- SC2046 (warning):
                  Quote this to prevent word splitting.
or this one:
    In resources/scripts/misc/guix.sh line 233:
        major="$(echo ${version} | awk -F . '{print $1}')"
                      ^--------^ SC2086 (info):
                      Double quote to prevent globbing and word splitting.
these were fixed.

And finally we also improved a test by using grep -q:
    In resources/scripts/misc/guix.sh line 272:
        elif [ -n "$(echo ${revision} | grep '\.')" ] ; then
               ^-- SC2143 (style):
        Use grep -q instead of comparing output with [ -n .. ]

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
---
 resources/scripts/misc/guix.sh | 43 +++++++++++++++++++++++++++++-----
 tests/lint                     |  1 +
 2 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/resources/scripts/misc/guix.sh b/resources/scripts/misc/guix.sh
index d8aad1f..10daab7 100755
--- a/resources/scripts/misc/guix.sh
+++ b/resources/scripts/misc/guix.sh
@@ -18,31 +18,57 @@
 true=0
 false=1
 
+# shellcheck disable=SC2034
 guix_v0_0="6365068393254e1131ab80eb0d68a759e7fd2256"
+# shellcheck disable=SC2034
 guix_v0_1="a1ba8475a610fd491be4e512e599515f36d8b109"
+# shellcheck disable=SC2034
 guix_v0_2="e8b3afeb9234bca4a455272a6a831d7994d29b96"
+# shellcheck disable=SC2034
 guix_v0_3="3253830d46cc55dd6b946468edd6a6f72944ef48"
+# shellcheck disable=SC2034
 guix_v0_4="81bb9b6665e253c42b078e752ec01020b7434e3f"
+# shellcheck disable=SC2034
 guix_v0_5="5d6dbd299e8389e8eb918daac00df9b6f6835e14"
+# shellcheck disable=SC2034
 guix_v0_6="4ec91959f2d13188894e45f82bf7b8c1c4ea7f4a"
+# shellcheck disable=SC2034
 guix_v0_7="508ea01ef20652fb2de875d1d91c27f5178e2874"
+# shellcheck disable=SC2034
 guix_v0_8="44941798d222901b8f381b3210957d880b90a2fc"
+# shellcheck disable=SC2034
 guix_v0_8_1="983c082a747c76bfefcfa0258d804f94c1f5afed"
+# shellcheck disable=SC2034
 guix_v0_8_2="04bdcdb6365e588aa8037a6c02d424b4eed6e2a9"
+# shellcheck disable=SC2034
 guix_v0_8_3="e348eaaf318646e259a5e6803133ad5b296febc1"
+# shellcheck disable=SC2034
 guix_v0_9_0="c8855b991880897b2658dc90164e29c96e2aeb3a"
+# shellcheck disable=SC2034
 guix_v0_10_0="34bf416e4a61324db80c5cea4ea5463f687057f9"
+# shellcheck disable=SC2034
 guix_v0_11_0="66edac525b7bb8ba29362c887450ff38c54da08d"
+# shellcheck disable=SC2034
 guix_v0_12_0="a81771f137716c62e7a44355e18ce5487ecf5301"
+# shellcheck disable=SC2034
 guix_v0_13_0="df671177f854da26bb171d9d5e9a6990024107a0"
+# shellcheck disable=SC2034
 guix_v0_14_0="40f5c53d89da266055a1dd6571c380f5c57fe5f9"
+# shellcheck disable=SC2034
 guix_v0_15_0="359fdda40f754bbf1b5dc261e7427b75463b59be"
+# shellcheck disable=SC2034
 guix_v0_16_0="4a0b87f0ec5b6c2dcf82b372dd20ca7ea6acdd9c"
+# shellcheck disable=SC2034
 guix_v1_0_0="6298c3ffd9654d3231a6f25390b056483e8f407c"
+# shellcheck disable=SC2034
 guix_v1_0_1="d68de958b60426798ed62797ff7c96c327a672ac"
+# shellcheck disable=SC2034
 guix_v1_1_0="d62c9b2671be55ae0305bebfda17b595f33797f2"
+# shellcheck disable=SC2034
 guix_v1_2_0="a099685659b4bfa6b3218f84953cbb7ff9e88063"
+# shellcheck disable=SC2034
 guix_v1_3_0="a0178d34f582b50e9bdbb0403943129ae5b560ff"
+# shellcheck disable=SC2034
 guix_v1_4_0="8e2f32cee982d42a79e53fc1e9aa7b8ff0514714"
 
 guix_known_versions=" \
@@ -88,6 +114,11 @@ source_guix_profile()
 {
     if [ -f "${HOME}"/.config/guix/current/etc/profile ] ; then
         GUIX_PROFILE="${HOME}/.config/guix/current"
+
+        # For some reasons using "# shellcheck
+        # source=${HOME}/.config/guix/current/etc/profile" doesn't
+        # work, so we need to tell shellcheck not to test that file.
+        # shellcheck disable=SC1091
         . "$GUIX_PROFILE"/etc/profile
     fi
 }
@@ -101,7 +132,7 @@ guix_version_commit()
 {
     version="$1"
 
-    eval echo $(echo \$guix_"${version}" | sed 's#\.#_#g')
+    eval echo "$(echo \$guix_"${version}" | sed 's#\.#_#g')"
 }
 
 is_guix_system()
@@ -230,7 +261,7 @@ next_guix_release()
 {
     version="$1"
 
-    major="$(echo ${version} | awk -F . '{print $1}')"
+    major="$(echo "${version}" | awk -F . '{print $1}')"
 
     if is_latest_release "${version}" ; then
         return ${true}
@@ -258,7 +289,7 @@ guix_checkout()
     for repo in "${HOME}"/.cache/guix/checkouts/*/ ; do
         url=$(git --no-pager -C "$repo" remote get-url origin)
         if [ "${url}" = "https://git.savannah.gnu.org/git/guix.git"; ] ; then
-            echo $repo
+            echo "$repo"
         fi
     done
 }
@@ -269,7 +300,7 @@ is_latest_release()
 
     if [ "${revision}" = "${guix_latest_release}" ] ; then
         return ${true}
-    elif [ -n "$(echo ${revision} | grep '\.')" ] ; then
+    elif echo "${revision}" | grep -q '\.' ; then
         return ${false}
     elif git --no-pager -C "$(guix_checkout)" tag --merged "${revision}" | \
             grep "^v${guix_latest_release}$" > /dev/null ; then
@@ -283,7 +314,7 @@ update_guix_to_latest_release()
 {
     current_version="$(guix_version)"
 
-    major="$(echo ${current_version} | awk -F . '{print $1}')"
+    major="$(echo "${current_version}" | awk -F . '{print $1}')"
 
     if is_latest_release "${current_version}" ; then
         return ${true}
@@ -291,7 +322,7 @@ update_guix_to_latest_release()
 
     # We use a released version already
     if [ -n "${major}" ] ; then
-        commit=$(guix_version_commit v$(guix_next_version 
"${current_version}"))
+        commit="$(guix_version_commit "v$(guix_next_version 
"${current_version}")")"
         guix pull --commit="${commit}"
         source_guix_profile
         update_guix_to_latest_release
diff --git a/tests/lint b/tests/lint
index dc9d637..9218cb4 100755
--- a/tests/lint
+++ b/tests/lint
@@ -58,6 +58,7 @@ run_shellcheck \
     resources/packages/src/distclean \
     resources/packages/u-boot-libre/distclean \
     resources/packages/website/distclean \
+    resources/scripts/misc/guix.sh \
     resources/scripts/tasks/distclean.sh \
     tests/distclean \
     tests/lint
-- 
2.41.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]