gnuboot/modify
Denis 'GNUtoo' Carikli 2a5e494ac9
modify: make it pass shellcheck
Without that fix, running 'shellcheck -x build' produces the following
errors/warnings:
    In modify line 23:
    [ "x${DEBUG+set}" = 'xset' ] && set -v
      ^-------------^ SC2268 (style):
      Avoid x-prefix in comparisons as it no longer serves a purpose.

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

    In modify line 113:
    "${pkg_dir}"/modify/"${option}" $@
                                    ^-- SC2068 (error):
    Double quote array expansions to avoid re-splitting elements.

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Acked-by: Adrien 'neox' Bourmault <neox@gnu.org>
2023-12-06 17:32:28 +01:00

131 lines
2.9 KiB
Bash
Executable file

#!/usr/bin/env bash
# generic scripts for modifying 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/sysexits.sh
./resources/scripts/misc/versioncheck
list_modify_paths() {
find resources/packages \
-mindepth 2 -maxdepth 2 \
-type d \
-name "modify" \
-printf "%P\n"
}
list_packages() {
list_modify_paths | \
sed 's#/.*##'
}
# Takes exactly one package as parameter
listoptions() {
package="${1}"
find resources/packages/"${package}/modify/" \
-mindepth 1 -maxdepth 1 \
-type f \
-printf "%P\n"
}
help() {
cat <<- EOF
Usage:
./modify <PACKAGE> <OPTION>
./modify --help
possible values for 'package':
$(list_packages)
Example: ./modify coreboot configs
Example: ./modify 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 './modify --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 './modify 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}"/modify/"${option}" $@
done
;;
*)
if [ -d resources/packages/"${package}"/modify ]; then
pkg_dir=resources/packages/"${package}"
if [ -f "${pkg_dir}"/modify/"${option}" ]; then
# shellcheck disable=SC2068
"${pkg_dir}"/modify/"${option}" $@
else
help
die "${EX_USAGE}" \
"Invalid option for '${package}'." \
" See './modify ${package} list'."
fi
else
help
die "${EX_USAGE}" \
"Invalid package '${package}'. See './modify help'."
fi
esac
else
help
exit 0
fi