summaryrefslogtreecommitdiff
path: root/lbmk
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-10-01 06:33:43 +0100
committerLeah Rowe <leah@libreboot.org>2023-10-01 22:47:02 +0100
commit8c03b886c4d4b9bcfb1cb30b3704b8af561c2f45 (patch)
tree828eb1ad589300517e9a41581eee4b5d9605d3e8 /lbmk
parent5f914a4d00da5ab9324c55eaecc40aa2ee000f63 (diff)
Greatly simplify error handling in shell scripts
Instead of having detailed error messages, run most commands through a function that calls err() under fault conditions. Where detail is still required, err() is still called manually. Where it isn't, the error message is simply whatever command was executed to cause the error. This results in a massive sloccount reduction for lbmk; specifically, 178 sloc reduction, or a 8.1% reduction. The total sloccount is now 2022, for shell scripts. Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'lbmk')
-rwxr-xr-xlbmk13
1 files changed, 4 insertions, 9 deletions
diff --git a/lbmk b/lbmk
index 395cd130..5dc59b9c 100755
--- a/lbmk
+++ b/lbmk
@@ -21,9 +21,7 @@ option=""
main()
{
- id -u 1>/dev/null 2>/dev/null || \
- fail "cannot ascertain user id"
-
+ xx_ id -u 1>/dev/null 2>/dev/null
initialise_command $@
shift 2
@@ -40,8 +38,7 @@ initialise_command()
[ $# -lt 1 ] && fail "Too few arguments. Try: ${0} help"
mode="${1}"
- [ "${mode}" != "dependencies" ] || \
- install_packages $@ || fail "Can't install dependencies"
+ [ "${mode}" != "dependencies" ] || xx_ install_packages $@
[ "$(id -u)" != "0" ] || \
fail "running this command as root is not permitted"
@@ -68,8 +65,7 @@ install_packages()
aur_notice=""
. "config/dependencies/${2}"
- ${pkg_add} ${pkglist} || \
- fail "install_packages: Error installing dependencies"
+ xx_ ${pkg_add} ${pkglist}
[ "${aur_notice}" = "" ] || \
printf "You must install AUR packages: %s\n" "${aur_notice}" 1>&2
@@ -79,8 +75,7 @@ install_packages()
execute_command()
{
if [ "${option}" = "list" ]; then
- listitems "${buildpath}/${mode}" || \
- fail "execute_command: cannot list command options"
+ xx_ listitems "${buildpath}/${mode}"
lbmk_exit 0
fi
[ -f "${buildpath}/${mode}/${option}" ] || \