-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixdup.sh
executable file
·50 lines (47 loc) · 1.11 KB
/
fixdup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
# Does the same as the python version only slower.
# Systems without python can therefore use this.
suffix=.fixdup.$$
link=1
dryRun=0
if [ "$#" = "1" ]; then
if [ "$1" = "del" ]; then
link=0
elif [ "$1" = "tdel" ]; then
link=0
dryRun=1
elif [ "$1" = "tmerge" ]; then
dryRun=1
fi
fi
keepfile='nextfile'
while read file; do
if [ -z "$file" ]; then
keepfile="nextfile"
elif [ "nextfile" = "$keepfile" ]; then
keepfile="$file"
if [ "$dryRun" = "1" ]; then
printf "\n\nkeeping: $keepfile\n"
if [ "$link" = "1" ]; then
printf "hardlinking: "
else
printf "deleting: "
fi
fi
else
if [ "$dryRun" = "1" ]; then
printf "$file "
else
if [ "$link" = "1" ]; then
ln -f -b --suffix="$suffix" -- "$keepfile" "$file" 2>/dev/null ||
ln -sf -b --suffix="$suffix" -- "$keepfile" "$file"
rm -f "$file$suffix"
else
rm -f "$file"
fi
fi
fi
done
if [ "$dryRun" = "1" ] && [ "$keepfile" != "nextfile" ]; then
echo
fi