]> git.proxmox.com Git - mirror_linux-firmware.git/blobdiff - copy-firmware.sh
Merge branch 'cirrus-20240904' into 'main'
[mirror_linux-firmware.git] / copy-firmware.sh
index 59ff976e1a539afa20bfb2ea34fdfafb853a3a4f..6757c6ce03a3086816ce95b0085c281a9afaaf26 100755 (executable)
@@ -9,16 +9,13 @@ prune=no
 # shellcheck disable=SC2209
 compress=cat
 compext=
-quiet=">/dev/null"
-rdfind_results=/dev/null
+skip_dedup=0
 
 while test $# -gt 0; do
     case $1 in
         -v | --verbose)
             # shellcheck disable=SC2209
             verbose=echo
-            quiet=
-            rdfind_results=results.txt
             shift
             ;;
 
@@ -48,6 +45,11 @@ while test $# -gt 0; do
             shift
             ;;
 
+        --ignore-duplicates)
+            skip_dedup=1
+            shift
+            ;;
+
         -*)
             if test "$compress" = "cat"; then
                 echo "ERROR: unknown command-line option: $1"
@@ -68,6 +70,18 @@ while test $# -gt 0; do
     esac
 done
 
+if [ -z "$destdir" ]; then
+       echo "ERROR: destination directory was not specified"
+       exit 1
+fi
+
+if ! command -v rdfind >/dev/null; then
+       if [ "$skip_dedup" != 1 ]; then
+               echo "ERROR: rdfind is not installed.  Pass --ignore-duplicates to skip deduplication"
+               exit 1
+       fi
+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
@@ -81,6 +95,16 @@ grep -E '^(RawFile|File):' WHENCE | sed -E -e 's/^(RawFile|File): */\1 /;s/"//g'
     fi
 done
 
+if [ "$skip_dedup" != 1 ] ; then
+       $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
+fi
+
 # 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 +143,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