From: Timur Tabi <ttabi@nvidia.com>
To: <jwboyer@kernel.org>, <superm1@gmail.com>,
<maxim.cournoyer@gmail.com>, <linux-firmware@kernel.org>
Subject: [PATCH 1/2] copy-firmware: make script smarter about parameters
Date: Mon, 17 Mar 2025 14:16:05 -0500 [thread overview]
Message-ID: <20250317191606.64181-1-ttabi@nvidia.com> (raw)
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
next reply other threads:[~2025-03-17 19:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-17 19:16 Timur Tabi [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250317191606.64181-1-ttabi@nvidia.com \
--to=ttabi@nvidia.com \
--cc=jwboyer@kernel.org \
--cc=linux-firmware@kernel.org \
--cc=maxim.cournoyer@gmail.com \
--cc=superm1@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.