copy-firmware.sh: warn if the destination folder is not empty

If the user provides an existing non-empty folder (their /usr/lib/firmware/ or otherwise)
there is a high chance we'll silently overwrite existing files. That may or may not be what
they wanted, so throw a warning so highlight that.

v2:
 - use printf instead of echo

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
This commit is contained in:
Emil Velikov 2024-09-22 17:00:01 +01:00 committed by Mario Limonciello
parent 97d200d75b
commit 32f71d6d45
1 changed files with 8 additions and 0 deletions

View File

@ -16,6 +16,10 @@ err() {
exit 1 exit 1
} }
warn() {
printf "WARNING: %s\n" "$*"
}
while test $# -gt 0; do while test $# -gt 0; do
case $1 in case $1 in
-v | --verbose) -v | --verbose)
@ -63,6 +67,10 @@ if test -z "$destdir"; then
err "destination directory was not specified" err "destination directory was not specified"
fi fi
if test -d "$destdir"; then
find "$destdir" -type d -empty >/dev/null || warn "destination folder is not empty."
fi
# shellcheck disable=SC2162 # file/folder name can include escaped symbols # shellcheck disable=SC2162 # file/folder name can include escaped symbols
grep -E '^(RawFile|File):' WHENCE | sed -E -e 's/^(RawFile|File): */\1 /;s/"//g' | while read k f; do grep -E '^(RawFile|File):' WHENCE | sed -E -e 's/^(RawFile|File): */\1 /;s/"//g' | while read k f; do
test -f "$f" || continue test -f "$f" || continue