scripts: misc: guix.sh: make it pass shellcheck.

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.

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 .. ]

And finally in guix_version_commit a sed was avoided by using bash
replacement, and when that was not possible (in guix_next_version),
the shellcheck test for that was disabled.

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Acked-by: Adrien 'neox' Bourmault <neox@gnu.org>
This commit is contained in:
Denis 'GNUtoo' Carikli 2024-01-30 23:49:43 +01:00
parent b3a0ddd92c
commit 34007c4baf
Signed by: GNUtoo
GPG Key ID: 5F5DFCC14177E263
2 changed files with 42 additions and 7 deletions

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
# #
# Copyright (C) 2023 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> # Copyright (C) 2023 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
# #
@ -18,31 +18,57 @@
true=0 true=0
false=1 false=1
# shellcheck disable=SC2034
guix_v0_0="6365068393254e1131ab80eb0d68a759e7fd2256" guix_v0_0="6365068393254e1131ab80eb0d68a759e7fd2256"
# shellcheck disable=SC2034
guix_v0_1="a1ba8475a610fd491be4e512e599515f36d8b109" guix_v0_1="a1ba8475a610fd491be4e512e599515f36d8b109"
# shellcheck disable=SC2034
guix_v0_2="e8b3afeb9234bca4a455272a6a831d7994d29b96" guix_v0_2="e8b3afeb9234bca4a455272a6a831d7994d29b96"
# shellcheck disable=SC2034
guix_v0_3="3253830d46cc55dd6b946468edd6a6f72944ef48" guix_v0_3="3253830d46cc55dd6b946468edd6a6f72944ef48"
# shellcheck disable=SC2034
guix_v0_4="81bb9b6665e253c42b078e752ec01020b7434e3f" guix_v0_4="81bb9b6665e253c42b078e752ec01020b7434e3f"
# shellcheck disable=SC2034
guix_v0_5="5d6dbd299e8389e8eb918daac00df9b6f6835e14" guix_v0_5="5d6dbd299e8389e8eb918daac00df9b6f6835e14"
# shellcheck disable=SC2034
guix_v0_6="4ec91959f2d13188894e45f82bf7b8c1c4ea7f4a" guix_v0_6="4ec91959f2d13188894e45f82bf7b8c1c4ea7f4a"
# shellcheck disable=SC2034
guix_v0_7="508ea01ef20652fb2de875d1d91c27f5178e2874" guix_v0_7="508ea01ef20652fb2de875d1d91c27f5178e2874"
# shellcheck disable=SC2034
guix_v0_8="44941798d222901b8f381b3210957d880b90a2fc" guix_v0_8="44941798d222901b8f381b3210957d880b90a2fc"
# shellcheck disable=SC2034
guix_v0_8_1="983c082a747c76bfefcfa0258d804f94c1f5afed" guix_v0_8_1="983c082a747c76bfefcfa0258d804f94c1f5afed"
# shellcheck disable=SC2034
guix_v0_8_2="04bdcdb6365e588aa8037a6c02d424b4eed6e2a9" guix_v0_8_2="04bdcdb6365e588aa8037a6c02d424b4eed6e2a9"
# shellcheck disable=SC2034
guix_v0_8_3="e348eaaf318646e259a5e6803133ad5b296febc1" guix_v0_8_3="e348eaaf318646e259a5e6803133ad5b296febc1"
# shellcheck disable=SC2034
guix_v0_9_0="c8855b991880897b2658dc90164e29c96e2aeb3a" guix_v0_9_0="c8855b991880897b2658dc90164e29c96e2aeb3a"
# shellcheck disable=SC2034
guix_v0_10_0="34bf416e4a61324db80c5cea4ea5463f687057f9" guix_v0_10_0="34bf416e4a61324db80c5cea4ea5463f687057f9"
# shellcheck disable=SC2034
guix_v0_11_0="66edac525b7bb8ba29362c887450ff38c54da08d" guix_v0_11_0="66edac525b7bb8ba29362c887450ff38c54da08d"
# shellcheck disable=SC2034
guix_v0_12_0="a81771f137716c62e7a44355e18ce5487ecf5301" guix_v0_12_0="a81771f137716c62e7a44355e18ce5487ecf5301"
# shellcheck disable=SC2034
guix_v0_13_0="df671177f854da26bb171d9d5e9a6990024107a0" guix_v0_13_0="df671177f854da26bb171d9d5e9a6990024107a0"
# shellcheck disable=SC2034
guix_v0_14_0="40f5c53d89da266055a1dd6571c380f5c57fe5f9" guix_v0_14_0="40f5c53d89da266055a1dd6571c380f5c57fe5f9"
# shellcheck disable=SC2034
guix_v0_15_0="359fdda40f754bbf1b5dc261e7427b75463b59be" guix_v0_15_0="359fdda40f754bbf1b5dc261e7427b75463b59be"
# shellcheck disable=SC2034
guix_v0_16_0="4a0b87f0ec5b6c2dcf82b372dd20ca7ea6acdd9c" guix_v0_16_0="4a0b87f0ec5b6c2dcf82b372dd20ca7ea6acdd9c"
# shellcheck disable=SC2034
guix_v1_0_0="6298c3ffd9654d3231a6f25390b056483e8f407c" guix_v1_0_0="6298c3ffd9654d3231a6f25390b056483e8f407c"
# shellcheck disable=SC2034
guix_v1_0_1="d68de958b60426798ed62797ff7c96c327a672ac" guix_v1_0_1="d68de958b60426798ed62797ff7c96c327a672ac"
# shellcheck disable=SC2034
guix_v1_1_0="d62c9b2671be55ae0305bebfda17b595f33797f2" guix_v1_1_0="d62c9b2671be55ae0305bebfda17b595f33797f2"
# shellcheck disable=SC2034
guix_v1_2_0="a099685659b4bfa6b3218f84953cbb7ff9e88063" guix_v1_2_0="a099685659b4bfa6b3218f84953cbb7ff9e88063"
# shellcheck disable=SC2034
guix_v1_3_0="a0178d34f582b50e9bdbb0403943129ae5b560ff" guix_v1_3_0="a0178d34f582b50e9bdbb0403943129ae5b560ff"
# shellcheck disable=SC2034
guix_v1_4_0="8e2f32cee982d42a79e53fc1e9aa7b8ff0514714" guix_v1_4_0="8e2f32cee982d42a79e53fc1e9aa7b8ff0514714"
guix_known_versions=" \ guix_known_versions=" \
@ -88,6 +114,11 @@ source_guix_profile()
{ {
if [ -f "${HOME}"/.config/guix/current/etc/profile ] ; then if [ -f "${HOME}"/.config/guix/current/etc/profile ] ; then
GUIX_PROFILE="${HOME}/.config/guix/current" 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 . "$GUIX_PROFILE"/etc/profile
fi fi
} }
@ -101,7 +132,7 @@ guix_version_commit()
{ {
version="$1" version="$1"
eval echo $(echo \$guix_"${version}" | sed 's#\.#_#g') eval echo "\$guix_""${version//./_}"
} }
is_guix_system() is_guix_system()
@ -219,6 +250,9 @@ guix_next_version()
esac esac
if is_known_version "${version}" && is_rc_version "${version}"; then if is_known_version "${version}" && is_rc_version "${version}"; then
# According to https://www.shellcheck.net/wiki/SC2001 bash
# substitution doesn't support regexes.
# shellcheck disable=SC2001
echo "${version}" | sed 's/rc[0-9]\+//' echo "${version}" | sed 's/rc[0-9]\+//'
return ${true} return ${true}
else else
@ -230,7 +264,7 @@ next_guix_release()
{ {
version="$1" version="$1"
major="$(echo ${version} | awk -F . '{print $1}')" major="$(echo "${version}" | awk -F . '{print $1}')"
if is_latest_release "${version}" ; then if is_latest_release "${version}" ; then
return ${true} return ${true}
@ -258,7 +292,7 @@ guix_checkout()
for repo in "${HOME}"/.cache/guix/checkouts/*/ ; do for repo in "${HOME}"/.cache/guix/checkouts/*/ ; do
url=$(git --no-pager -C "$repo" remote get-url origin) url=$(git --no-pager -C "$repo" remote get-url origin)
if [ "${url}" = "https://git.savannah.gnu.org/git/guix.git" ] ; then if [ "${url}" = "https://git.savannah.gnu.org/git/guix.git" ] ; then
echo $repo echo "$repo"
fi fi
done done
} }
@ -269,7 +303,7 @@ is_latest_release()
if [ "${revision}" = "${guix_latest_release}" ] ; then if [ "${revision}" = "${guix_latest_release}" ] ; then
return ${true} return ${true}
elif [ -n "$(echo ${revision} | grep '\.')" ] ; then elif echo "${revision}" | grep -q '\.' ; then
return ${false} return ${false}
elif git --no-pager -C "$(guix_checkout)" tag --merged "${revision}" | \ elif git --no-pager -C "$(guix_checkout)" tag --merged "${revision}" | \
grep "^v${guix_latest_release}$" > /dev/null ; then grep "^v${guix_latest_release}$" > /dev/null ; then
@ -283,7 +317,7 @@ update_guix_to_latest_release()
{ {
current_version="$(guix_version)" 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 if is_latest_release "${current_version}" ; then
return ${true} return ${true}
@ -291,7 +325,7 @@ update_guix_to_latest_release()
# We use a released version already # We use a released version already
if [ -n "${major}" ] ; then 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}" guix pull --commit="${commit}"
source_guix_profile source_guix_profile
update_guix_to_latest_release update_guix_to_latest_release

View File

@ -58,6 +58,7 @@ run_shellcheck \
resources/packages/src/distclean \ resources/packages/src/distclean \
resources/packages/u-boot-libre/distclean \ resources/packages/u-boot-libre/distclean \
resources/packages/website/distclean \ resources/packages/website/distclean \
resources/scripts/misc/guix.sh \
resources/scripts/tasks/distclean.sh \ resources/scripts/tasks/distclean.sh \
tests/distclean \ tests/distclean \
tests/lint tests/lint