| # SPDX-License-Identifier: GPL-2.0 |
| # Deduplicate files in a given destdir |
| # shellcheck disable=SC2209 |
| if test -n "$destdir"; then |
| err "unknown command-line options: $*" |
| if test -z "$destdir"; then |
| err "destination directory was not specified." |
| if ! test -d "$destdir"; then |
| err "provided directory does not exit." |
| if ! command -v rdfind >/dev/null; then |
| err "rdfind is not installed." |
| $verbose "Finding duplicate files" |
| rdfind -makesymlinks true -makeresultsfile true "$destdir" >/dev/null |
| grep DUPTYPE_WITHIN_SAME_TREE results.txt | grep -o "$destdir.*" | while read -r l; do |
| target="$(realpath "$l")" |
| $verbose "Correcting path for $l" |
| ln --force --symbolic --relative "$target" "$l" |