From 07ffc2005a975030408cc836b19087e46fc24729 Mon Sep 17 00:00:00 2001 From: Timur Tabi Date: Mon, 17 Mar 2025 13:32:15 -0500 Subject: [PATCH 1/3] copy-firmware: add usage help text Add a -h/--help command-line option to show some usage help text. Also display that usage whenever an error occurs. Signed-off-by: Timur Tabi --- copy-firmware.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/copy-firmware.sh b/copy-firmware.sh index dd4b9b6f..9a2b7156 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 } @@ -66,6 +71,11 @@ while test $# -gt 0; do shift ;; + -h|--help) + usage + exit 1 + ;; + *) if test -n "$destdir"; then err "unknown command-line options: $*" From 142c0a71434fa86d41d36f4b6e4cbba43c29b631 Mon Sep 17 00:00:00 2001 From: Timur Tabi Date: Mon, 17 Mar 2025 13:32:15 -0500 Subject: [PATCH 2/3] copy-firmware: make script smarter about bad parameters Two improvements to copy-firmware.sh that make it more friendly when passed unknown or not exactly correct command-line parameters. 1) Don't fail with a weird error if there's a space between -j and the number. 2) 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/copy-firmware.sh b/copy-firmware.sh index 9a2b7156..cd5a6893 100755 --- a/copy-firmware.sh +++ b/copy-firmware.sh @@ -44,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 @@ -76,6 +77,13 @@ while test $# -gt 0; do 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: $*" From dd90046b703b1a6b32e0d87080ff64ca3645f14c Mon Sep 17 00:00:00 2001 From: Timur Tabi Date: Mon, 17 Mar 2025 14:01:02 -0500 Subject: [PATCH 3/3] copy-firmware: fail gracefully if moreutils parallel is installed The copy-firmware.sh script can use the "parallel" command to parallelize some operations, but it needs the GNU version of parallel. There is another, simpler version of parallel that is part of the moreutils package, but that version confuses the has_gnu_parallel() function. So first test to make sure that the --version parameter is even recognized before trying to use it. If in the future, moreutils parallel adds support for --version, this script should still work because that version should never report "GNU parallel". Signed-off-by: Timur Tabi --- copy-firmware.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/copy-firmware.sh b/copy-firmware.sh index cd5a6893..6a32127e 100755 --- a/copy-firmware.sh +++ b/copy-firmware.sh @@ -27,6 +27,13 @@ warn() { has_gnu_parallel() { if command -v parallel > /dev/null; then + # The moreutils package comes with a simpler version of "parallel" + # that does not support the --version or -a options. Check for + # that first. In some distros, installing the "parallel" package + # will replace the moreutils version with the GNU version. + if ! parallel --version > /dev/null 2>&1; then + return 1 + fi if parallel --version | grep -Fqi 'gnu parallel'; then return 0 fi