update: make it pass shellcheck

Without that fix, running 'shellcheck -x build' produces the following
errors/warnings:
    In update line 81:
    case "${option}" in
    ^-- SC1009 (info):
    The mentioned syntax error was in this case expression.

    In update line 82:
    list)
    ^-- SC1073 (error):
    Couldn't parse this case item. Fix to allow more checks.

    In update line 92:
    all)
       ^-- SC1072 (error):
       Fix any mentioned problems and try again.
       ^-- SC1074 (error):
       Did you forget the ;; after the previous case item?

After fixing these and rerunning 'shellcheck -x build', we then have
the following errors/warnings:
    In update line 23:
    [ "x${DEBUG+set}" = 'xset' ] && set -v
      ^-------------^ SC2268 (style):
    Avoid x-prefix in comparisons as it no longer serves a purpose.

    In update line 32:
    ls -d resources/packages/*/update/ | \
    ^-- SC2012 (info):
    Use find instead of ls to better handle non-alphanumeric filenames.

    In update line 40:
    ls -d resources/packages/"${package}"/update/* | \
    ^-- SC2012 (info):
    Use find instead of ls to better handle non-alphanumeric filenames.

    In update line 95:
    resources/packages/"${package}"/update/"${option}" $@
                                                       ^-- SC2068 (error):
    Double quote array expansions to avoid re-splitting elements.

    In update line 102:
    "${pkg_dir}"/update/"${option}" $@
                                    ^-- SC2068 (error):
    Double quote array expansions to avoid re-splitting elements.
so we fix them as well.

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 2023-11-28 17:37:25 +01:00 committed by Adrien 'neox' Bourmault
parent 68cb3ac110
commit 7bf153a207
Signed by: neox
GPG Key ID: 2974E1D5F25DFCC8
2 changed files with 19 additions and 5 deletions

View File

@ -44,6 +44,7 @@ run_shellcheck \
build \
download \
modify \
update \
resources/packages/descriptors/distclean \
resources/packages/flashrom/distclean \
resources/packages/grub/distclean \

23
update
View File

@ -20,7 +20,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
[ "x${DEBUG+set}" = 'xset' ] && set -v
[ "${DEBUG+set}" = 'set' ] && set -v
set -u -e
projectname="$(cat projectname)"
@ -28,17 +28,26 @@ projectname="$(cat projectname)"
. resources/scripts/misc/sysexits.sh
list_update_paths() {
find resources/packages \
-mindepth 2 -maxdepth 2 \
-type d \
-name "update" \
-printf "%P\n"
}
list_packages() {
ls -d resources/packages/*/update/ | \
sed 's#resources/packages/##' | \
list_update_paths | \
sed 's#/.*##'
}
# Takes exactly one package as parameter
listoptions() {
package="${1}"
ls -d resources/packages/"${package}"/update/* | \
sed 's#resources/packages/'"${package}"'/update/##'
find resources/packages/"${package}/update/" \
-mindepth 1 -maxdepth 1 \
-type f \
-printf "%P\n"
}
help() {
@ -89,8 +98,10 @@ if [ $# -gt 1 ]; then
"${package}"
listoptions "${package}"
fi
;;
all)
for option in $(listoptions "${package}"); do
# shellcheck disable=SC2068
resources/packages/"${package}"/update/"${option}" $@
done
;;
@ -98,6 +109,7 @@ if [ $# -gt 1 ]; then
if [ -d resources/packages/"${package}"/update ]; then
pkg_dir=resources/packages/"${package}"
if [ -f "${pkg_dir}"/update/"${option}" ]; then
# shellcheck disable=SC2068
"${pkg_dir}"/update/"${option}" $@
else
help
@ -111,6 +123,7 @@ if [ $# -gt 1 ]; then
"Invalid package '${package}'." \
" See './update --help'."
fi
;;
esac
else
help