From bf54edbe87f205bf76e831ffeb9c057816e62a20 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 23 Sep 2024 14:09:40 +0100 Subject: [PATCH] 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. Signed-off-by: Emil Velikov Link: https://lore.kernel.org/r/20240923-misc-fixes-v2-12-397f23443628@gmail.com Signed-off-by: Mario Limonciello --- copy-firmware.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/copy-firmware.sh b/copy-firmware.sh index 610c8b65..12b97ae3 100755 --- a/copy-firmware.sh +++ b/copy-firmware.sh @@ -16,6 +16,10 @@ err() { exit 1 } +warn() { + echo "WARNING: $*" +} + 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