mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
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>
This commit is contained in:
+7
-11
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user