use the new coding style in scripts

there were stragglers left over from the last audit,
and these stragglers still exist even after all the
major re-factoring as of late

the new style is: bsd-like coding style and error
handling. verbose yet simple error handling. we use
an "err" function in a way reminiscent of most C
programs that you see in openbsd base (err.h)

this style is very clean, resulting in readable code

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2023-08-24 00:30:07 +01:00
parent 4c6c7d1088
commit 8f4f0e00ec
8 changed files with 119 additions and 66 deletions
+25 -15
View File
@@ -24,26 +24,36 @@
[ "x${DEBUG+set}" = 'xset' ] && set -v [ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e set -u -e
# clean coreboot utilities (dependencies for 'build'): . "include/err.sh"
printf "Cleaning the previous build of coreboot and its utilities\n" main()
{
printf "Cleaning the previous build of coreboot and its utilities\n"
rm -Rf cbutils rm -Rf cbutils || err "cannot remove cbutils/"
[ ! -d "coreboot/" ] && exit 0
[ ! -d "coreboot/" ] && exit 0 clean_cbutils
}
for tree in coreboot/*; do clean_cbutils()
[ "${tree##*/}" = "coreboot" ] && continue {
[ -d "${tree}" ] || continue for tree in coreboot/*; do
[ "${tree##*/}" = "coreboot" ] && continue
[ -d "${tree}" ] || continue
# Clean coreboot, of course # Clean coreboot, of course
make -C "${tree}/" distclean make -C "${tree}/" distclean || \
err "cannot distclean coreboot tree, ${tree}"
# Clean its utilities as well # Clean its utilities as well
for util in cbfstool ifdtool nvramtool cbmem; do for util in cbfstool ifdtool nvramtool cbmem; do
make distclean -C "${tree}/util/${util}/" make distclean -C "${tree}/util/${util}/" || \
err "cannot clean util, ${util}, at ${tree}"
done
make distclean -C "${tree}/payloads/libpayload/" || \
err "cannot distclean libpayload, at ${tree}"
done done
make distclean -C "${tree}/payloads/libpayload/" }
done
printf "\n\n" main $@
+6 -1
View File
@@ -29,9 +29,14 @@ main()
printf "Cleaning crossgcc builds in all coreboot archives\n" printf "Cleaning crossgcc builds in all coreboot archives\n"
[ ! -d "coreboot/" ] && exit 0 [ ! -d "coreboot/" ] && exit 0
clean_crossgcc
}
clean_crossgcc()
{
for board in coreboot/*; do for board in coreboot/*; do
[ -d "${board}" ] || continue
[ "${board##*/}" = "coreboot" ] && continue [ "${board##*/}" = "coreboot" ] && continue
[ ! -d "${board}" ] && continue
make -C "${board}/" crossgcc-clean || err "make-clean" make -C "${board}/" crossgcc-clean || err "make-clean"
done done
} }
+18 -9
View File
@@ -2,7 +2,7 @@
# helper script: clean the dependencies that were built in seabios # helper script: clean the dependencies that were built in seabios
# #
# Copyright (C) 2015, 2020, 2021 Leah Rowe <info@minifree.org> # Copyright (C) 2015,2020,2021,2023 Leah Rowe <info@minifree.org>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@@ -26,13 +26,22 @@ set -u -e
# clean bucts # clean bucts
# -------------------------------------------------------- # --------------------------------------------------------
printf "Cleaning the previous builds of seabios\n" main()
{
[ ! -d "elf/seabios" ] || rm -Rf elf/seabios || \
err "cannot remove elf/seabios"
[ ! -d "seabios/" ] && exit 0
[ ! -d "elf/seabios" ] || rm -Rf elf/seabios || err "cannot remove elf/seabios" clean_seabios
[ ! -d "seabios/" ] && exit 0 }
for x in seabios/*; do clean_seabios()
[ "${x}" = "seabios/seabios" ] && continue {
[ ! -d "${x}" ] && continue for x in seabios/*; do
make -C "${x}" distclean || err "cannot distclean tree, ${x}" [ ! -d "${x}" ] && continue
done [ "${x}" = "seabios/seabios" ] && continue
make -C "${x}" distclean || err "cannot distclean tree, ${x}"
done
}
main $@
+22 -11
View File
@@ -2,7 +2,7 @@
# helper script: clean the u-boot builds # helper script: clean the u-boot builds
# #
# Copyright (C) 2014, 2015, 2016, 2020 Leah Rowe <info@minifree.org> # Copyright (C) 2014-2016, 2020, 2023 Leah Rowe <info@minifree.org>
# Copyright (C) 2015 Klemens Nanni <contact@autoboot.org> # Copyright (C) 2015 Klemens Nanni <contact@autoboot.org>
# Copyright (C) 2022 Alper Nebi Yasak <alpernebiyasak@gmail.com> # Copyright (C) 2022 Alper Nebi Yasak <alpernebiyasak@gmail.com>
# #
@@ -23,17 +23,28 @@
[ "x${DEBUG+set}" = 'xset' ] && set -v [ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e set -u -e
printf "Cleaning u-boot builds for all boards\n" . "include/err.sh"
for board in u-boot/*; do main()
if [ "${board##*/}" = "u-boot" ] || [ ! -d "${board}" ]; then {
continue printf "Cleaning u-boot builds for all boards\n"
fi clean_uboot
}
make -C "${board}/" distclean clean_uboot()
{
for board in u-boot/*; do
if [ "${board##*/}" = "u-boot" ] || [ ! -d "${board}" ]; then
continue
fi
[ -e "${board}/.git" ] && \ make -C "${board}/" distclean || \
git -C "${board}" clean -fdx err "cannot distclean u-boot dir, ${board}"
done
printf "\n\n" [ ! -e "${board}/.git" ] || \
git -C "${board}" clean -fdx || \
err "cannot clean u-boot git repo, ${board}"
done
}
main $@
+15 -13
View File
@@ -21,10 +21,12 @@
[ "x${DEBUG+set}" = 'xset' ] && set -v [ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e set -u -e
printf "Building coreboot utils\n" . "include/err.sh"
main() main()
{ {
printf "Building coreboot utils\n"
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
for board in "${@}"; do for board in "${@}"; do
build_for_mainboard ${board} || \ build_for_mainboard ${board} || \
@@ -45,28 +47,28 @@ build_for_mainboard() {
[ -f "resources/coreboot/${board}/target.cfg" ] || continue [ -f "resources/coreboot/${board}/target.cfg" ] || continue
tree="undefined" tree="undefined"
. "resources/coreboot/${board}/target.cfg" # source . "resources/coreboot/${board}/target.cfg" # source
if [ "${tree}" = "undefined" ]; then [ "${tree}" = "undefined" ] && \
printf "build/cbutils: improper tree definition for '%s'" \ err "build/cbutils: improper tree definition for '${board}'"
"${board}" buildutils "${tree}"
return 1
fi
buildutils "${tree}" || return 1
} }
buildutils() { buildutils() {
tree="${1}" tree="${1}"
[ -d "coreboot/${tree}/" ] || \ [ -d "coreboot/${tree}/" ] || \
./fetch_trees coreboot $tree || return 1 ./fetch_trees coreboot $tree || \
err "cannot fetch ${tree}"
for util in cbfstool ifdtool; do for util in cbfstool ifdtool; do
[ -f "cbutils/${tree}/${util}" ] && continue [ -f "cbutils/${tree}/${util}" ] && continue
[ -d "cbutils/${tree}" ] || \ [ -d "cbutils/${tree}" ] || \
mkdir -p "cbutils/${tree}" || return 1 mkdir -p "cbutils/${tree}" || \
err "cannot create directory, cbutils/${tree}"
utildir="coreboot/${tree}/util/${util}" utildir="coreboot/${tree}/util/${util}"
make distclean -C "${utildir}" || return 1 make distclean -C "${utildir}" || err "cannot clean ${utildir}"
make -j$(nproc) -C "${utildir}" || return 1 make -j$(nproc) -C "${utildir}" || err "cannot build ${utildir}"
mv "${utildir}/${util}" "cbutils/${tree}" || return 1 cp "${utildir}/${util}" "cbutils/${tree}" || \
make distclean -C "${utildir}" || return 1 err "cannot copy util, ${util}, to cbutils/${tree}/"
make distclean -C "${utildir}" || err "can't clean ${utildir}"
done done
} }
+20 -14
View File
@@ -21,6 +21,8 @@
[ "x${DEBUG+set}" = 'xset' ] && set -v [ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e set -u -e
. "include/err.sh"
grubcfgsdir="resources/grub" grubcfgsdir="resources/grub"
keymap="" keymap=""
@@ -30,26 +32,29 @@ main()
{ {
printf "Creating GRUB payloads and configuration files\n" printf "Creating GRUB payloads and configuration files\n"
[ ! -d "grub/" ] && \ handle_dependencies
./fetch grub
[ ! -f "grub/grub-mkstandalone" ] && \
./build grub utils
[ ! -d "elf/" ] && \
mkdir -p elf/
[ ! -d "elf/grub" ] && \
mkdir -p elf/grub/
rm -f elf/grub/*
# Separate GRUB payload per keymap to save space in ROM. # Separate GRUB payload per keymap to save space in ROM.
for keylayoutfile in ${grubcfgsdir}/keymap/*.gkb; do for keylayoutfile in ${grubcfgsdir}/keymap/*.gkb; do
[ -f "${keylayoutfile}" ] || continue
build_grub_payloads "${keylayoutfile}" build_grub_payloads "${keylayoutfile}"
done done
printf "Done! Check elf/grub/ to see the files.\n\n" printf "Done! Check elf/grub/ to see the files.\n\n"
} }
handle_dependencies()
{
[ -d "grub/" ] || \
./fetch grub || err "cannot fetch grub"
[ -f "grub/grub-mkstandalone" ] || \
./build grub utils || err "cannot build grub utils"
[ -d "elf/grub" ] || \
mkdir -p elf/grub || err "cannot create directory, elf/grub"
rm -f elf/grub/* || err "cannot delete files in directory, elf/grub/"
}
build_grub_payloads() build_grub_payloads()
{ {
keylayoutfile=${1} keylayoutfile=${1}
@@ -79,15 +84,16 @@ build_grub_elf()
--fonts= --themes= --locales= \ --fonts= --themes= --locales= \
--modules="${grub_modules}" \ --modules="${grub_modules}" \
--install-modules="${grub_install_modules}" \ --install-modules="${grub_install_modules}" \
${gcfg} ${grubk} ${gcfg} ${grubk} || \
err "cannot create grub payload (grub-mkstandalone)"
} }
create_grub_config() create_grub_config()
{ {
sed "s/usqwerty/${keymap}/" < ${grubcfgsdir}/config/grub.cfg \ sed "s/usqwerty/${keymap}/" < ${grubcfgsdir}/config/grub.cfg \
> elf/grub/grub_${keymap}.cfg > elf/grub/grub_${keymap}.cfg || err "sed failed: grub.cfg"
sed "s/grubtest.cfg/grub.cfg/" < elf/grub/grub_${keymap}.cfg \ sed "s/grubtest.cfg/grub.cfg/" < elf/grub/grub_${keymap}.cfg \
> elf/grub/grub_${keymap}_test.cfg > elf/grub/grub_${keymap}_test.cfg || err "sed failed: grubtest.cfg"
} }
main $@ main $@
+12 -2
View File
@@ -46,8 +46,14 @@ main()
[ -z "${project}" ] && err "project name not specified" [ -z "${project}" ] && err "project name not specified"
[ "${project}" = "ich9utils" ] && project="util/ich9utils" [ "${project}" = "ich9utils" ] && project="util/ich9utils"
[ -d "${project}" ] || ./fetch "${project%/*}" \ handle_dependencies
|| err "Cannot download project, ${project%/*}" run_make_command
}
handle_dependencies()
{
[ -d "${project}" ] || ./fetch "${project%/*}" || \
err "Cannot download project, ${project%/*}"
[ -d "${project}" ] || err "Project, ${project%/*}, not downloaded" [ -d "${project}" ] || err "Project, ${project%/*}, not downloaded"
if [ "${project}" = "uefitool" ]; then if [ "${project}" = "uefitool" ]; then
@@ -56,6 +62,10 @@ main()
cmake UEFIExtract/ || err "cannot cmake UEFIExtract" cmake UEFIExtract/ || err "cannot cmake UEFIExtract"
) )
fi fi
}
run_make_command()
{
[ ! -z "${mode}" ] || \ [ ! -z "${mode}" ] || \
make -C "${project}" || err "'make' failed (${project})" make -C "${project}" || err "'make' failed (${project})"
[ -z "${mode}" ] || \ [ -z "${mode}" ] || \
+1 -1
View File
@@ -17,7 +17,7 @@
# #
[ "x${DEBUG+set}" = 'xset' ] && set -v [ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e set -u
version="version-unknown" version="version-unknown"
[ -f version ] && version="$(cat version)" [ -f version ] && version="$(cat version)"