summaryrefslogtreecommitdiff
path: root/include/mrc.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/mrc.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/mrc.sh')
-rwxr-xr-xinclude/mrc.sh18
1 files changed, 7 insertions, 11 deletions
diff --git a/include/mrc.sh b/include/mrc.sh
index 21ce5f01..43a59d82 100755
--- a/include/mrc.sh
+++ b/include/mrc.sh
@@ -14,15 +14,14 @@ extract_mrc()
_file="${_file%.zip}"
(
- cd "${appdir}" || err "extract_mrc: !cd ${appdir}"
+ x_ cd "${appdir}"
extract_partition ROOT-A "${_file}" root-a.ext2
extract_shellball root-a.ext2 chromeos-firmwareupdate-${MRC_board}
extract_coreboot chromeos-firmwareupdate-${MRC_board}
)
- "${cbfstool}" "${appdir}/"coreboot-*.bin extract -n mrc.bin \
- -f "${_dest}" -r RO_SECTION || \
- err "extract_mrc: could not fetch mrc.bin"
+ x_ "${cbfstool}" "${appdir}/"coreboot-*.bin extract -n mrc.bin \
+ -f "${_dest}" -r RO_SECTION
}
extract_partition()
@@ -39,9 +38,8 @@ extract_partition()
START=$(( $( echo ${ROOTP} | cut -f2 -d\ | tr -d "B" ) ))
SIZE=$(( $( echo ${ROOTP} | cut -f4 -d\ | tr -d "B" ) ))
- dd if="${FILE}" of="${ROOTFS}" bs=${_bs} skip=$(( ${START} / ${_bs} )) \
- count=$(( ${SIZE} / ${_bs} )) || \
- err "extract_partition: can't extract root file system"
+ x_ dd if="${FILE}" of="${ROOTFS}" bs=${_bs} \
+ skip=$(( ${START} / ${_bs} )) count=$(( ${SIZE} / ${_bs} ))
}
extract_shellball()
@@ -62,8 +60,7 @@ extract_coreboot()
printf "Extracting coreboot image\n"
[ -f "${_shellball}" ] || \
err "extract_coreboot: shellball missing in google cros image"
- sh "${_shellball}" --unpack "${_unpacked}" || \
- err "extract_coreboot: shellball exits with non-zero status"
+ x_ sh "${_shellball}" --unpack "${_unpacked}"
# TODO: audit the f* out of that shellball, for each mrc version.
# it has to be updated for each mrc update. we should ideally
@@ -75,6 +72,5 @@ extract_coreboot()
_version=$( cat "${_unpacked}/VERSION" | grep BIOS\ version: | \
cut -f2 -d: | tr -d \ )
- cp "${_unpacked}/bios.bin" "coreboot-${_version}.bin" || \
- err "extract_coreboot: cannot copy google cros rom"
+ x_ cp "${_unpacked}/bios.bin" "coreboot-${_version}.bin"
}