diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-30 16:44:52 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-30 16:44:52 +0000 |
commit | 1ae1ce35210e35559848b88ecd07206cdffd5f94 (patch) | |
tree | d0bfb00539f99b9026d387607ad594f507383bf3 /copy-firmware.sh | |
parent | Adding upstream version 20230625. (diff) | |
download | firmware-nonfree-upstream.tar.xz firmware-nonfree-upstream.zip |
Adding upstream version 20240709.upstream/20240709upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'copy-firmware.sh')
-rwxr-xr-x | copy-firmware.sh | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/copy-firmware.sh b/copy-firmware.sh index 58eb7e3..6757c6c 100755 --- a/copy-firmware.sh +++ b/copy-firmware.sh @@ -9,6 +9,7 @@ prune=no # shellcheck disable=SC2209 compress=cat compext= +skip_dedup=0 while test $# -gt 0; do case $1 in @@ -24,7 +25,7 @@ while test $# -gt 0; do ;; --xz) - if test "$compext" == ".zst"; then + if test "$compext" = ".zst"; then echo "ERROR: cannot mix XZ and ZSTD compression" exit 1 fi @@ -34,7 +35,7 @@ while test $# -gt 0; do ;; --zstd) - if test "$compext" == ".xz"; then + if test "$compext" = ".xz"; then echo "ERROR: cannot mix XZ and ZSTD compression" exit 1 fi @@ -44,6 +45,19 @@ while test $# -gt 0; do shift ;; + --ignore-duplicates) + skip_dedup=1 + shift + ;; + + -*) + if test "$compress" = "cat"; then + echo "ERROR: unknown command-line option: $1" + exit 1 + fi + compress="$compress $1" + shift + ;; *) if test "x$destdir" != "x"; then echo "ERROR: unknown command-line options: $*" @@ -56,12 +70,24 @@ 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 '^File:' WHENCE | sed -e 's/^File: *//g;s/"//g' | while read 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 install -d "$destdir/$(dirname "$f")" $verbose "copying/compressing file $f$compext" - if test "$compress" != "cat" && grep -q "^Raw: $f\$" WHENCE; then + if test "$compress" != "cat" && test "$k" = "RawFile"; then $verbose "compression will be skipped for file $f" cat "$f" > "$destdir/$f" else @@ -69,6 +95,16 @@ grep '^File:' WHENCE | sed -e 's/^File: *//g;s/"//g' | while read f; do 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 @@ -94,9 +130,16 @@ grep -E '^Link:' WHENCE | sed -e 's/^Link: *//g;s/-> //g' | while read f d; do $verbose "WARNING: missing target for symlink $f" fi else - install -d "$destdir/$(dirname "$f")" - $verbose "creating link $f$compext -> $d$compext" - ln -s "$d$compext" "$destdir/$f$compext" + directory="$destdir/$(dirname "$f")" + install -d "$directory" + target="$(cd "$directory" && realpath -m -s "$d")" + if test -d "$target"; then + $verbose "creating link $f -> $d" + ln -s "$d" "$destdir/$f" + else + $verbose "creating link $f$compext -> $d$compext" + ln -s "$d$compext" "$destdir/$f$compext" + fi fi done |