]> git.ipfire.org Git - thirdparty/linux-firmware.git/commitdiff
copy-firmware.sh: warn if the destination folder is not empty
authorEmil Velikov <emil.l.velikov@gmail.com>
Sun, 22 Sep 2024 16:00:01 +0000 (17:00 +0100)
committerMario Limonciello <superm1@gmail.com>
Thu, 10 Oct 2024 14:33:32 +0000 (14:33 +0000)
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>
copy-firmware.sh

index 381bde291f198577a17d50e19e4486d7583b84e1..fa83492ee042ea252647ca7bd7061701bf84ca9f 100755 (executable)
@@ -16,6 +16,10 @@ err() {
     exit 1
 }
 
+warn() {
+    printf "WARNING: %s\n" "$*"
+}
+
 while test $# -gt 0; do
     case $1 in
         -v | --verbose)
@@ -63,6 +67,10 @@ if test -z "$destdir"; then
     err "destination directory was not specified"
 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
 grep -E '^(RawFile|File):' WHENCE | sed -E -e 's/^(RawFile|File): */\1 /;s/"//g' | while read k f; do
     test -f "$f" || continue