gnuboot/download

141 lines
3.5 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
# Some scripts like the ones in resources/packages/flashrom need
# Makefiles to be generated
. resources/scripts/misc/generate-configure-makefiles.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 \
-executable \
-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