2
1
Fork 0
mirror of https://git.savannah.gnu.org/git/gnuboot.git synced 2025-01-04 07:17:40 +01:00
gnuboot/download
Denis 'GNUtoo' Carikli 68cb3ac110
download: make it pass shellcheck
Without that fix, running 'shellcheck -x build' produces the following
errors/warnings:
    In download line 26:
    [ "x${DEBUG+set}" = 'xset' ] && set -v
      ^-------------^ SC2268 (style):
    Avoid x-prefix in comparisons as it no longer serves a purpose.

    In download line 37:
    [ "x${NODELETE+set}" = 'xset' ] && deleteblobs="false"
      ^----------------^ SC2268 (style):
    Avoid x-prefix in comparisons as it no longer serves a purpose.

    In download line 102:
    NODELETE= "${script}"
             ^-- SC1007 (warning):
    Remove space after = if trying to assign a value (for empty string,
    use var='' ... ).

    In download line 117:
    NODELETE= resources/packages/"${package}"/download
             ^-- SC1007 (warning):
    Remove space after = if trying to assign a value (for empty string,
    use var='' ... ).

    In download line 123:
    NODELETE= resources/packages/"${package}"/download $@
             ^-- SC1007 (warning):
    Remove space after = if trying to assign a value (for empty string,
    use var='' ... ).
                                                       ^-- SC2068 (error):
    Double quote array expansions to avoid re-splitting elements.

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

    In download line 131:
    ./.gitcheck clean
    ^---------------^ SC2317 (info):
    Command appears to be unreachable. Check usage (or ignore if invoked
    indirectly).

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

135 lines
3.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# Generic script for downloading programs used by the build system
#
# 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>
# Copyright (C) 2022, Caleb La Grange <thonkpeasant@protonmail.com>
#
# 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/>.
#
# shellcheck source=.gitcheck
./.gitcheck
[ "${DEBUG+set}" = 'set' ] && set -v
set -u -e
./resources/scripts/misc/versioncheck
. resources/scripts/misc/sysexits.sh
# set this when you want to modify each coreboot tree
# for example, you want to test custom patches
# NODELETE='' ./download coreboot
deleteblobs="true"
[ "${NODELETE+set}" = 'set' ] && deleteblobs="false"
rm -f "build_error"
list_modify_paths() {
find resources/packages \
-mindepth 2 -maxdepth 2 \
-type f \
-name "download" \
-printf "%P\n"
}
list_packages() {
list_modify_paths | \
sed 's#/.*##'
}
help() {
cat <<- EOF
Usage:
./download <PACKAGE> <OPTIONS>
./download --help
possible values for 'package':
$(list_packages)
Example: ./download flashrom
Example: ./download coreboot
Some package options allow for additional parameters:
Example: ./download coreboot default
Example: ./download coreboot x60
Each package download script should work without extra paramaters, but
they can use them. For instance, './download coreboot' will download all
coreboot trees by default, but './download coreboot x60' will only
download the coreboot tree required for the target: x60
Each package download script should also accept the --help paramater to
display the usage of the script.
Refer to the documentation for more information.
EOF
}
die() {
ret="$1"
shift 1
printf 'Error: %s\n' "${@}" 1>&2
exit "${ret}"
}
if [ $# -lt 1 ]; then
help
die "${EX_USAGE}" "Please specify arguments."
fi
package="${1}"
shift 1
[ "${package}" = "--help" ] && help && exit 0
if [ "${package}" = "all" ]; then
for script in resources/packages/*/download; do
if [ "${deleteblobs}" = "false" ]; then
NODELETE='' "${script}"
else
"${script}"
fi
done
exit 0
elif [ ! -f "resources/packages/${package}/download" ]; then
help
die "${EX_USAGE}" \
"Invalid package '${package}'." \
" See: './download --help'."
fi
if [ $# -lt 1 ]; then
if [ "${deleteblobs}" = "false" ]; then
NODELETE='' resources/packages/"${package}"/download
else
resources/packages/"${package}"/download
fi
else
if [ "${deleteblobs}" = "false" ]; then
# shellcheck disable=SC2068
NODELETE='' resources/packages/"${package}"/download $@
else
# shellcheck disable=SC2068
resources/packages/"${package}"/download $@
fi
fi
# shellcheck disable=SC2317
./.gitcheck clean
exit 0