From 89bf227a6ec0489732fd719fbe818b4fecf09a55 Mon Sep 17 00:00:00 2001 From: Timur Tabi Date: Mon, 17 Mar 2025 14:16:05 -0500 Subject: [PATCH] copy-firmware: make script smarter about parameters Several improvements to copy-firmware.sh that make it more friendly when passed unknown or not exactly correct command-line parameters. 1) Add a usage() function to show the command-line options. 2) Print that usage on all errors. 3) Don't fail with a weird error if there's a space between -j and the number. 4) Add support for the -h or --help options. 5) Ignore any command-line unsupported parameters that start with a dash. This is necessary because otherwise the script will assume the option is actually a destination directory, and then the "test" command will get confused. Drawback is that we don't support any more destination directories that start with a dash, but no one does that. Signed-off-by: Timur Tabi --- copy-firmware.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/copy-firmware.sh b/copy-firmware.sh index dd4b9b6f..cd5a6893 100755 --- a/copy-firmware.sh +++ b/copy-firmware.sh @@ -11,8 +11,13 @@ compext= destdir= num_jobs=1 +usage() { + echo "Usage: $0 [-v] [-jN] [--xz|--zstd] " +} + err() { printf "ERROR: %s\n" "$*" + usage exit 1 } @@ -39,6 +44,7 @@ while test $# -gt 0; do -j*) num_jobs=$(echo "$1" | sed 's/-j//') + num_jobs=${num_jobs:-1} if [ "$num_jobs" -gt 1 ] && ! has_gnu_parallel; then err "the GNU parallel command is required to use -j" fi @@ -66,6 +72,18 @@ while test $# -gt 0; do shift ;; + -h|--help) + usage + exit 1 + ;; + + -*) + # Ignore anything else that begins with - because that confuses + # the "test" command below + warn "ignoring option $1" + shift + ;; + *) if test -n "$destdir"; then err "unknown command-line options: $*"