gnuboot/update
Denis 'GNUtoo' Carikli 7bf153a207
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>
2023-12-06 17:32:33 +01:00

131 lines
3 KiB
Bash
Executable file

#!/usr/bin/env bash
# generic update scripts for updating configs and such
#
# Copyright (C) 2014, 2015, 2020, 2021 Leah Rowe <info@minifree.org>
# Copyright (C) 2015 Patrick "P. J." McDermott <pj@pehjota.net>
# Copyright (C) 2015, 2016 Klemens Nanni <contact@autoboot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
[ "${DEBUG+set}" = 'set' ] && set -v
set -u -e
projectname="$(cat projectname)"
./resources/scripts/misc/versioncheck
. resources/scripts/misc/sysexits.sh
list_update_paths() {
find resources/packages \
-mindepth 2 -maxdepth 2 \
-type d \
-name "update" \
-printf "%P\n"
}
list_packages() {
list_update_paths | \
sed 's#/.*##'
}
# Takes exactly one package as parameter
listoptions() {
package="${1}"
find resources/packages/"${package}/update/" \
-mindepth 1 -maxdepth 1 \
-type f \
-printf "%P\n"
}
help() {
cat <<- EOF
Usage:
./update <PACKAGE> <OPTION>
./update --help
possible values for 'package':
$(list_packages)
Example: ./update coreboot configs
Example: ./update coreboot configs x60
Refer to the ${projectname} documentation for more information.
EOF
}
die() {
ret="$1"
shift 1
printf 'Error: %s\n' "${@}" 1>&2
exit "${ret}"
}
if [ $# -lt 1 ]; then
die "${EX_USAGE}" \
"Wrong number of arguments specified. See './update --help'."
fi
package="${1}"
[ "${package}" = "--help" ] && help && exit 0
if [ $# -gt 1 ]; then
option="${2}"
shift 2
case "${option}" in
list)
if [ ! -d resources/packages/"${package}" ] ; then
die "${EX_USAGE}" \
"Invalid package '${package}'." \
" See './update --help'."
else
printf "Available options for package '%s':\n\n" \
"${package}"
listoptions "${package}"
fi
;;
all)
for option in $(listoptions "${package}"); do
# shellcheck disable=SC2068
resources/packages/"${package}"/update/"${option}" $@
done
;;
*)
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
die "${EX_USAGE}" \
"Invalid option for '${package}'." \
" See './update ${package} list'."
fi
else
help
die "${EX_USAGE}" \
"Invalid package '${package}'." \
" See './update --help'."
fi
;;
esac
else
help
exit 0
fi