Debian Codegraph @

firmware/dedup-firmware.sh

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 # SPDX-License-Identifier: GPL-2.0
3 #
4 # Deduplicate files in a given destdir
5 #
6
7 errscip-shell shell shell-project 0.0.0 err().() {
8 echoscip-shell system . . echo. "ERROR: $*"
9 exit 1
10 }
11
12 verbose=:
13 destdir=
14 while testscip-shell system . . test. $# -gt 0; do
15 case $1 in
16 -v | --verbose)
17 # shellcheck disable=SC2209
18 verbose=echo
19 shift
20 ;;
21 *)
22 if testscip-shell system . . test. -n "$destdir"; then
23 errscip-shell shell shell-project 0.0.0 err(). "unknown command-line options: $*"
24 fi
25
26 destdir="$1"
27 shift
28 ;;
29 esac
30 done
31
32 if testscip-shell system . . test. -z "$destdir"; then
33 errscip-shell shell shell-project 0.0.0 err(). "destination directory was not specified."
34 fi
35
36 if ! testscip-shell system . . test. -d "$destdir"; then
37 errscip-shell shell shell-project 0.0.0 err(). "provided directory does not exit."
38 fi
39
40 if ! command -v rdfind >/dev/nullscip-shell filesystem . . `/dev/null`.; then
41 errscip-shell shell shell-project 0.0.0 err(). "rdfind is not installed."
42 fi
43
44 $verbose "Finding duplicate files"
45 rdfind -makesymlinks true -makeresultsfile true "$destdir" >/dev/nullscip-shell filesystem . . `/dev/null`.
46
47 grepscip-shell system . . grep. DUPTYPE_WITHIN_SAME_TREE results.txt | grepscip-shell system . . grep. -o "$destdir.*" | while read -r l; do
48 target="$(realpathscip-shell system . . realpath. "$l")"
49 $verbose "Correcting path for $l"
50 lnscip-shell system . . ln. --force --symbolic --relative "$target" "$l"
51 done
52
53 rmscip-shell system . . rm. results.txt