summaryrefslogtreecommitdiff
path: root/include/blobutil.sh
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 /include/blobutil.sh
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 'include/blobutil.sh')
-rwxr-xr-xinclude/blobutil.sh12
1 files changed, 6 insertions, 6 deletions
diff --git a/include/blobutil.sh b/include/blobutil.sh
index 51f11de9..3b59ba2e 100755
--- a/include/blobutil.sh
+++ b/include/blobutil.sh
@@ -52,14 +52,14 @@ fetch()
_dest="${5##*../}"
_dl="${blobdir}/cache/${dlsum}"
- mkdir -p "${_dl%/*}" || err "fetch: !mkdir ${_dl%/*}"
+ x_ mkdir -p "${_dl%/*}"
dl_fail="y"
vendor_checksum "${dlsum}" "${_dl}" && dl_fail="n"
for url in "${dl}" "${dl_bkup}"; do
[ "${dl_fail}" = "n" ] && break
[ -z "${url}" ] && continue
- rm -f "${_dl}" || err "fetch: !rm -f ${_dl}"
+ x_ rm -f "${_dl}"
curl --location --retry 3 -A "${_ua}" "${url}" -o "${_dl}" || \
wget --tries 3 -U "${_ua}" "${url}" -O "${_dl}" || \
continue
@@ -68,7 +68,7 @@ fetch()
[ "${dl_fail}" = "y" ] && \
err "fetch ${dlsum}: matched file unavailable"
- rm -Rf "${_dl}_extracted" || err "!rm ${_dl}_extracted"
+ x_ rm -Rf "${_dl}_extracted"
mkdirs "${_dest}" "extract_${dl_type}" || return 0
eval "extract_${dl_type}"
@@ -89,9 +89,9 @@ mkdirs()
{
[ -f "${1}" ] && \
printf "mkdirs ${1} ${2}: already downloaded\n" 1>&2 && return 1
- mkdir -p "${1%/*}" || err "mkdirs ${1} ${2}: !mkdir ${1%/*}"
- rm -Rf "${appdir}" || err "mkdirs ${1} ${2}: can't remove ${appdir}"
- mkdir -p "${appdir}/" || err "mkdirs ${1} ${2}: !mkdir ${appdir}"
+ x_ mkdir -p "${1%/*}"
+ x_ rm -Rf "${appdir}"
+ x_ mkdir -p "${appdir}/"
extract_archive "${_dl}" "${appdir}" || \
[ "${2}" = "extract_e6400vga" ] || err "mkdirs ${1} ${2}: !extract"
}