All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] copy-firmware: make script smarter about parameters
@ 2025-03-17 19:16 Timur Tabi
  2025-03-17 19:16 ` [PATCH 2/2] copy-firmware: fail gracefully if moreutils parallel is installed Timur Tabi
  2025-03-17 20:27 ` [PATCH 1/2] copy-firmware: make script smarter about parameters Mario Limonciello
  0 siblings, 2 replies; 12+ messages in thread
From: Timur Tabi @ 2025-03-17 19:16 UTC (permalink / raw)
  To: jwboyer, superm1, maxim.cournoyer, linux-firmware

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 <ttabi@nvidia.com>
---
 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] <destination directory>"
+}
+
 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: $*"
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-03-18 15:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-17 19:16 [PATCH 1/2] copy-firmware: make script smarter about parameters Timur Tabi
2025-03-17 19:16 ` [PATCH 2/2] copy-firmware: fail gracefully if moreutils parallel is installed Timur Tabi
2025-03-18  6:20   ` Maxim Cournoyer
2025-03-18  7:06     ` Timur Tabi
2025-03-18  6:42   ` Maxim Cournoyer
2025-03-18  7:08     ` Timur Tabi
2025-03-18 14:58       ` Maxim Cournoyer
2025-03-18 15:14         ` Timur Tabi
2025-03-17 20:27 ` [PATCH 1/2] copy-firmware: make script smarter about parameters Mario Limonciello
2025-03-17 21:14   ` Timur Tabi
2025-03-17 21:16     ` Mario Limonciello
2025-03-17 21:45   ` Timur Tabi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.