mirror of
https://gitlab.com/kernel-firmware/linux-firmware.git
synced 2025-12-10 07:44:48 +01:00
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 <ttabi@nvidia.com>
This commit is contained in:
parent
6a94efbe2a
commit
89bf227a6e
1 changed files with 18 additions and 0 deletions
|
|
@ -11,8 +11,13 @@ compext=
|
||||||
destdir=
|
destdir=
|
||||||
num_jobs=1
|
num_jobs=1
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: $0 [-v] [-jN] [--xz|--zstd] <destination directory>"
|
||||||
|
}
|
||||||
|
|
||||||
err() {
|
err() {
|
||||||
printf "ERROR: %s\n" "$*"
|
printf "ERROR: %s\n" "$*"
|
||||||
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,6 +44,7 @@ while test $# -gt 0; do
|
||||||
|
|
||||||
-j*)
|
-j*)
|
||||||
num_jobs=$(echo "$1" | sed 's/-j//')
|
num_jobs=$(echo "$1" | sed 's/-j//')
|
||||||
|
num_jobs=${num_jobs:-1}
|
||||||
if [ "$num_jobs" -gt 1 ] && ! has_gnu_parallel; then
|
if [ "$num_jobs" -gt 1 ] && ! has_gnu_parallel; then
|
||||||
err "the GNU parallel command is required to use -j"
|
err "the GNU parallel command is required to use -j"
|
||||||
fi
|
fi
|
||||||
|
|
@ -66,6 +72,18 @@ while test $# -gt 0; do
|
||||||
shift
|
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
|
if test -n "$destdir"; then
|
||||||
err "unknown command-line options: $*"
|
err "unknown command-line options: $*"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue