copy-firmware.sh: add err() helper

v2:
 - use printf instead of echo -e

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
This commit is contained in:
Emil Velikov 2024-09-22 16:48:35 +01:00 committed by Mario Limonciello
parent 6360b4a1d7
commit 97d200d75b
1 changed files with 10 additions and 11 deletions

View File

@ -11,6 +11,11 @@ compress=cat
compext= compext=
destdir= destdir=
err() {
printf "ERROR: %s\n" "$*"
exit 1
}
while test $# -gt 0; do while test $# -gt 0; do
case $1 in case $1 in
-v | --verbose) -v | --verbose)
@ -26,8 +31,7 @@ while test $# -gt 0; do
--xz) --xz)
if test "$compext" = ".zst"; then if test "$compext" = ".zst"; then
echo "ERROR: cannot mix XZ and ZSTD compression" err "cannot mix XZ and ZSTD compression"
exit 1
fi fi
compress="xz --compress --quiet --stdout --check=crc32" compress="xz --compress --quiet --stdout --check=crc32"
compext=".xz" compext=".xz"
@ -36,8 +40,7 @@ while test $# -gt 0; do
--zstd) --zstd)
if test "$compext" = ".xz"; then if test "$compext" = ".xz"; then
echo "ERROR: cannot mix XZ and ZSTD compression" err "cannot mix XZ and ZSTD compression"
exit 1
fi fi
# shellcheck disable=SC2209 # shellcheck disable=SC2209
compress="zstd --compress --quiet --stdout" compress="zstd --compress --quiet --stdout"
@ -47,8 +50,7 @@ while test $# -gt 0; do
*) *)
if test -n "$destdir"; then if test -n "$destdir"; then
echo "ERROR: unknown command-line options: $*" err "unknown command-line options: $*"
exit 1
fi fi
destdir="$1" destdir="$1"
@ -58,8 +60,7 @@ while test $# -gt 0; do
done done
if test -z "$destdir"; then if test -z "$destdir"; then
echo "ERROR: destination directory was not specified" err "destination directory was not specified"
exit 1
fi fi
# shellcheck disable=SC2162 # file/folder name can include escaped symbols # shellcheck disable=SC2162 # file/folder name can include escaped symbols
@ -115,9 +116,7 @@ done
# Verify no broken symlinks # Verify no broken symlinks
if test "$(find "$destdir" -xtype l | wc -l)" -ne 0 ; then if test "$(find "$destdir" -xtype l | wc -l)" -ne 0 ; then
echo "ERROR: Broken symlinks found:" err "Broken symlinks found:\\n$(find "$destdir" -xtype l)"
find "$destdir" -xtype l
exit 1
fi fi
exit 0 exit 0