From 8c03b886c4d4b9bcfb1cb30b3704b8af561c2f45 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 1 Oct 2023 06:33:43 +0100 Subject: 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 --- include/mrc.sh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'include/mrc.sh') 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" } -- cgit v1.2.1