From 4c55675d7adaf2aadb39aceeecc65cc86ace6917 Mon Sep 17 00:00:00 2001 From: Mario Limonciello Date: Wed, 8 Nov 2023 17:02:06 -0600 Subject: [PATCH 1/3] Fix symlink creation for some files rdfind was trying to duplicate symlinks created by WHENCE causing problems. Move the call before WHENCE creates symlinks. Reported-by: Timur Tabi Signed-off-by: Mario Limonciello --- copy-firmware.sh | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/copy-firmware.sh b/copy-firmware.sh index 59ff976e..3026c216 100755 --- a/copy-firmware.sh +++ b/copy-firmware.sh @@ -9,16 +9,12 @@ prune=no # shellcheck disable=SC2209 compress=cat compext= -quiet=">/dev/null" -rdfind_results=/dev/null while test $# -gt 0; do case $1 in -v | --verbose) # shellcheck disable=SC2209 verbose=echo - quiet= - rdfind_results=results.txt shift ;; @@ -81,6 +77,14 @@ grep -E '^(RawFile|File):' WHENCE | sed -E -e 's/^(RawFile|File): */\1 /;s/"//g' fi done +$verbose "Finding duplicate files" +rdfind -makesymlinks true -makeresultsfile false "$destdir" >/dev/null +find "$destdir" -type l | while read -r l; do + target="$(realpath "$l")" + $verbose "Correcting path for $l" + ln -fs "$(realpath --relative-to="$(dirname "$(realpath -s "$l")")" "$target")" "$l" +done + # shellcheck disable=SC2162 # file/folder name can include escaped symbols grep -E '^Link:' WHENCE | sed -e 's/^Link: *//g;s/-> //g' | while read f d; do if test -L "$f$compext"; then @@ -119,12 +123,6 @@ grep -E '^Link:' WHENCE | sed -e 's/^Link: *//g;s/-> //g' | while read f d; do fi done -$verbose rdfind -makesymlinks true "$destdir" -outputname $rdfind_results "$quiet" -find "$destdir" -type l | while read -r l; do - target="$(realpath "$l")" - ln -fs "$(realpath --relative-to="$(dirname "$(realpath -s "$l")")" "$target")" "$l" -done - exit 0 # vim: et sw=4 sts=4 ts=4 From 195eae5962588c588ec1ef8d34a716da008afdb1 Mon Sep 17 00:00:00 2001 From: Mario Limonciello Date: Wed, 8 Nov 2023 17:13:51 -0600 Subject: [PATCH 2/3] Add checks for destination directory being specified Signed-off-by: Mario Limonciello --- copy-firmware.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/copy-firmware.sh b/copy-firmware.sh index 3026c216..cca3913b 100755 --- a/copy-firmware.sh +++ b/copy-firmware.sh @@ -64,6 +64,11 @@ while test $# -gt 0; do esac done +if [ -z "$destdir" ]; then + echo "ERROR: destination directory was not specified" + exit 1 +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 From cf8315ded9b422d2e8b620ffe8bb661221639c8f Mon Sep 17 00:00:00 2001 From: Mario Limonciello Date: Wed, 8 Nov 2023 17:14:52 -0600 Subject: [PATCH 3/3] Ensure rdfind is installed Signed-off-by: Mario Limonciello --- copy-firmware.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/copy-firmware.sh b/copy-firmware.sh index cca3913b..f9b1f0ff 100755 --- a/copy-firmware.sh +++ b/copy-firmware.sh @@ -69,6 +69,11 @@ if [ -z "$destdir" ]; then exit 1 fi +if ! which rdfind 2>/dev/null >/dev/null; then + echo "ERROR: rdfind is not installed" + exit 1 +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