2023-05-27 09:52:37 +00:00
|
|
|
#!/usr/bin/env sh
|
2023-09-25 01:19:30 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2023-09-25 01:27:26 +00:00
|
|
|
# SPDX-FileCopyrightText: 2014,2015,2020,2021,2023 Leah Rowe <leah@libreboot.org>
|
2023-09-25 01:19:30 +00:00
|
|
|
# SPDX-FileCopyrightText: 2015 Patrick "P. J." McDermott <pj@pehjota.net>
|
|
|
|
# SPDX-FileCopyrightText: 2015, 2016 Klemens Nanni <contact@autoboot.org>
|
|
|
|
# SPDX-FileCopyrightText: 2022, Caleb La Grange <thonkpeasant@protonmail.com>
|
2023-05-27 09:52:37 +00:00
|
|
|
|
|
|
|
[ "x${DEBUG+set}" = 'xset' ] && set -v
|
|
|
|
set -u -e
|
|
|
|
|
2023-08-23 17:56:31 +00:00
|
|
|
. "include/err.sh"
|
2023-09-02 09:22:39 +00:00
|
|
|
. "include/export.sh"
|
2023-09-27 20:46:20 +00:00
|
|
|
. "include/option.sh"
|
2023-09-01 00:33:17 +00:00
|
|
|
|
2023-09-16 09:56:40 +00:00
|
|
|
linkpath="${0}"
|
|
|
|
linkname="${linkpath##*/}"
|
|
|
|
buildpath="./script/${linkname}"
|
2023-10-04 07:06:10 +00:00
|
|
|
eval "$(setvars "" mode option project version versiondate)"
|
2023-05-27 09:52:37 +00:00
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
2023-10-01 05:33:43 +00:00
|
|
|
xx_ id -u 1>/dev/null 2>/dev/null
|
2023-09-16 09:56:40 +00:00
|
|
|
initialise_command $@
|
|
|
|
shift 2
|
|
|
|
|
2023-10-04 07:06:10 +00:00
|
|
|
check_git
|
2023-10-04 09:02:59 +00:00
|
|
|
check_project "fail"
|
2023-09-16 09:56:40 +00:00
|
|
|
|
|
|
|
execute_command $@
|
|
|
|
lbmk_exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
initialise_command()
|
|
|
|
{
|
|
|
|
[ "${linkname}" = "lbmk" ] && fail "Don't run this script directly."
|
2023-09-01 00:33:17 +00:00
|
|
|
[ $# -lt 1 ] && fail "Too few arguments. Try: ${0} help"
|
2023-05-27 09:52:37 +00:00
|
|
|
|
|
|
|
mode="${1}"
|
2023-10-01 05:33:43 +00:00
|
|
|
[ "${mode}" != "dependencies" ] || xx_ install_packages $@
|
2023-10-02 08:00:22 +00:00
|
|
|
[ "$(id -u)" != "0" ] || fail "this command as root is not permitted"
|
2023-08-24 15:37:40 +00:00
|
|
|
|
2023-09-16 09:39:04 +00:00
|
|
|
[ "${mode}" = "help" ] && usage ${0} && lbmk_exit 0
|
2023-10-02 08:00:22 +00:00
|
|
|
if [ "${mode}" = "list" ]; then
|
|
|
|
listitems "${buildpath}"
|
|
|
|
lbmk_exit 0
|
|
|
|
elif [ $# -lt 2 ]; then
|
|
|
|
usage ${0}
|
|
|
|
lbmk_exit 1
|
|
|
|
fi
|
2023-08-24 15:37:40 +00:00
|
|
|
|
2023-05-27 09:52:37 +00:00
|
|
|
option="${2}"
|
2023-09-16 09:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
install_packages()
|
|
|
|
{
|
|
|
|
if [ $# -lt 2 ]; then
|
|
|
|
printf "You must specify a distro, namely:\n" 1>&2
|
2023-10-02 08:00:22 +00:00
|
|
|
printf "Look at files under config/dependencies/\n" 1>&2
|
2023-09-16 09:56:40 +00:00
|
|
|
printf "Example: ./build dependencies debian\n" 1>&2
|
2023-09-16 10:37:20 +00:00
|
|
|
fail "install_packages: target not specified"
|
2023-09-16 09:56:40 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
[ -f "config/dependencies/${2}" ] || fail "Unsupported target"
|
|
|
|
|
|
|
|
aur_notice=""
|
|
|
|
. "config/dependencies/${2}"
|
2023-05-27 09:52:37 +00:00
|
|
|
|
2023-10-01 05:33:43 +00:00
|
|
|
xx_ ${pkg_add} ${pkglist}
|
2023-09-16 09:56:40 +00:00
|
|
|
[ "${aur_notice}" = "" ] || \
|
|
|
|
printf "You must install AUR packages: %s\n" "${aur_notice}" 1>&2
|
much, much stricter, more verbose error handling
lbmk is much more likely to crash now, in error conditions,
which is a boon for further auditing.
also: in "fetch", remove the downloaded program
if fail() was called.
this would also be done for gnulib, when downloading
grub, but done in such a way that gnulib goes first.
where calls to err write "ERROR" in the string, they
no longer say "ERROR" because the "err" function itself
now does that automatically.
also: listmodes/listoptions (in "lbmk") now reports an
error if no scripts and/or directories are found.
also: where a warning is given, but not an error, i've
gone through in some places and redirected the output
to stderr, not stdout
as part of error checks: running anything as root, except
for the "./build dependencies *" commands, is no longer
permitted and lbmk will throw an error
mrc downloads: debugfs output no longer redirected to /dev/null,
and stderr no longer redirected to stdout. everything is verbose.
certain non-error states are also more verbose. for example,
patch_rom in blobs/inject will now state when injection succeeds
certain actual errors(bugs) were fixed:
for example, build/release/roms now correctly prepares the blobs
hash files for a given target, containing only the files and
checksums in the list. Previously, a printf message was included.
Now, with this new code: blobutil/inject rightly verifies hashes.
doing all of this in one giant patch is cleaner
than 100 patches changing each file. even this is yet part
of a much larger audit going on in the Libreboot project.
Signed-off-by: Leah Rowe <leah@libreboot.org>
2023-08-24 19:19:41 +00:00
|
|
|
|
2023-09-16 09:56:40 +00:00
|
|
|
lbmk_exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
execute_command()
|
|
|
|
{
|
2023-09-16 10:19:15 +00:00
|
|
|
if [ "${option}" = "list" ]; then
|
2023-10-01 05:33:43 +00:00
|
|
|
xx_ listitems "${buildpath}/${mode}"
|
2023-09-16 10:19:15 +00:00
|
|
|
lbmk_exit 0
|
|
|
|
fi
|
2023-09-16 10:28:26 +00:00
|
|
|
[ -f "${buildpath}/${mode}/${option}" ] || \
|
|
|
|
fail "Invalid command. Run: ${linkpath} help"
|
2023-09-16 10:37:20 +00:00
|
|
|
"${buildpath}/${mode}/${option}" $@ || \
|
|
|
|
fail "execute_command: ${buildpath}/${mode}/${option} ${@}"
|
2023-08-20 20:17:02 +00:00
|
|
|
}
|
|
|
|
|
2023-05-27 09:52:37 +00:00
|
|
|
usage()
|
|
|
|
{
|
|
|
|
progname=${0}
|
|
|
|
cat <<- EOF
|
|
|
|
USAGE: ${progname} <MODE> <OPTION>
|
|
|
|
|
|
|
|
possible values for 'mode':
|
2023-09-27 20:46:20 +00:00
|
|
|
$(listitems "${buildpath}")
|
2023-05-27 09:52:37 +00:00
|
|
|
|
2023-09-10 18:25:22 +00:00
|
|
|
For each of the above modes, you may also do:
|
|
|
|
${progname} <MODE> list
|
|
|
|
|
2023-10-06 00:34:14 +00:00
|
|
|
Example: ./build coreboot list, which would yield:
|
|
|
|
$(./build coreboot list)
|
2023-05-27 09:52:37 +00:00
|
|
|
|
2023-10-04 07:06:10 +00:00
|
|
|
Refer to ${project} documentation for more info.
|
2023-05-27 09:52:37 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2023-09-01 00:33:17 +00:00
|
|
|
lbmk_exit()
|
|
|
|
{
|
2023-10-02 08:00:22 +00:00
|
|
|
tmp_cleanup || err "lbmk_exit: can't rm tmpdir upon exit $1: ${tmpdir}"
|
2023-09-01 00:33:17 +00:00
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
fail()
|
|
|
|
{
|
2023-10-02 08:00:22 +00:00
|
|
|
tmp_cleanup || printf "WARNING: can't rm tmpdir: %s\n" "${tmpdir}" 1>&2
|
2023-09-01 00:33:17 +00:00
|
|
|
err "${1}"
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp_cleanup()
|
|
|
|
{
|
2023-10-02 08:00:22 +00:00
|
|
|
[ "${tmpdir_was_set}" = "n" ] || return 0
|
|
|
|
rm -Rf "${tmpdir}" || return 1
|
2023-09-01 00:33:17 +00:00
|
|
|
}
|
|
|
|
|
2023-05-27 09:52:37 +00:00
|
|
|
main $@
|