summaryrefslogtreecommitdiff
path: root/resources/scripts/build/grub
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-08-24 00:30:07 +0100
committerLeah Rowe <leah@libreboot.org>2023-08-24 00:31:19 +0100
commit8f4f0e00ec3c307599f7f27777e3e92c1f9f6e4e (patch)
tree39ec749c16892b69cda00b6241714f475a1989b6 /resources/scripts/build/grub
parent4c6c7d1088eb9dc0c9b2eeeb64febeeb78038583 (diff)
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>
Diffstat (limited to 'resources/scripts/build/grub')
-rwxr-xr-xresources/scripts/build/grub/payload34
1 files changed, 20 insertions, 14 deletions
diff --git a/resources/scripts/build/grub/payload b/resources/scripts/build/grub/payload
index 4886a874..7f1d239f 100755
--- a/resources/scripts/build/grub/payload
+++ b/resources/scripts/build/grub/payload
@@ -21,6 +21,8 @@
[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e
+. "include/err.sh"
+
grubcfgsdir="resources/grub"
keymap=""
@@ -30,26 +32,29 @@ main()
{
printf "Creating GRUB payloads and configuration files\n"
- [ ! -d "grub/" ] && \
- ./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/*
+ handle_dependencies
# Separate GRUB payload per keymap to save space in ROM.
-
for keylayoutfile in ${grubcfgsdir}/keymap/*.gkb; do
+ [ -f "${keylayoutfile}" ] || continue
build_grub_payloads "${keylayoutfile}"
done
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()
{
keylayoutfile=${1}
@@ -79,15 +84,16 @@ build_grub_elf()
--fonts= --themes= --locales= \
--modules="${grub_modules}" \
--install-modules="${grub_install_modules}" \
- ${gcfg} ${grubk}
+ ${gcfg} ${grubk} || \
+ err "cannot create grub payload (grub-mkstandalone)"
}
create_grub_config()
{
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 \
- > elf/grub/grub_${keymap}_test.cfg
+ > elf/grub/grub_${keymap}_test.cfg || err "sed failed: grubtest.cfg"
}
main $@