From 4222a1ffd612c12e52528aa84cf6a5289998234c Mon Sep 17 00:00:00 2001 From: Matt DeVillier Date: Fri, 16 Jan 2026 17:26:58 -0600 Subject: [PATCH] util/chromeos/crosfirmware.sh: Refactor dependency checking Refactor exit_if_dependencies_are_missing() to check all dependencies in a single pass using an associative array, collect any missing ones, and report them all together before exiting. This provides better UX by showing all missing dependencies at once rather than exiting after the first one. This replaces the previous approach that would exit immediately upon finding the first missing dependency, often causing users to run the script several times to identify and install all missing dependencies. Change-Id: Ieb03756b24fd2aa1af2c0ffaed717d06c9e85cbb Signed-off-by: Matt DeVillier Reviewed-on: https://review.coreboot.org/c/coreboot/+/90785 Tested-by: build bot (Jenkins) Reviewed-by: Sean Rhodes --- util/chromeos/crosfirmware.sh | 47 ++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/util/chromeos/crosfirmware.sh b/util/chromeos/crosfirmware.sh index 673f3b38a5..ab17c22ad6 100755 --- a/util/chromeos/crosfirmware.sh +++ b/util/chromeos/crosfirmware.sh @@ -5,27 +5,34 @@ # On some systems, `parted` and `debugfs` are located in /sbin. export PATH="$PATH:/sbin" -exit_if_uninstalled() { - local cmd_name="$1" - local deb_pkg_name="$2" - - if type "$cmd_name" >/dev/null 2>&1; then - return - fi - - printf '`%s` was not found. ' "$cmd_name" >&2 - printf 'On Debian-based systems, it can be installed\n' >&2 - printf 'by running `apt install %s`.\n' "$deb_pkg_name" >&2 - - exit 1 -} - exit_if_dependencies_are_missing() { - exit_if_uninstalled "uudecode" "sharutils" - exit_if_uninstalled "debugfs" "e2fsprogs" - exit_if_uninstalled "parted" "parted" - exit_if_uninstalled "curl" "curl" - exit_if_uninstalled "unzip" "unzip" + local missing_deps=() + local -A deps_map=( + ["uudecode"]="sharutils" + ["debugfs"]="e2fsprogs" + ["parted"]="parted" + ["curl"]="curl" + ["unzip"]="unzip" + ) + + # Check all dependencies at once + for cmd_name in "${!deps_map[@]}"; do + if ! type "$cmd_name" >/dev/null 2>&1; then + missing_deps+=("$cmd_name:${deps_map[$cmd_name]}") + fi + done + + # Exit if any dependencies are missing + if [ ${#missing_deps[@]} -gt 0 ]; then + printf 'The following required commands were not found:\n' >&2 + for dep_info in "${missing_deps[@]}"; do + cmd_name="${dep_info%%:*}" + deb_pkg_name="${dep_info##*:}" + printf ' - `%s`\n' "$cmd_name" >&2 + printf ' On Debian-based systems, install with: `apt install %s`\n' "$deb_pkg_name" >&2 + done + exit 1 + fi } get_inventory() {