-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.sh
More file actions
executable file
·91 lines (78 loc) · 1.87 KB
/
filter.sh
File metadata and controls
executable file
·91 lines (78 loc) · 1.87 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
function usage() {
echo "usage: $(basename "$0") <metadata file> <input dir> <output dir>"
}
if [ "$#" == "0" ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]
then
usage
echo "description:"
echo " copies every file from the input dir to output dir"
echo " if the sha1sum of the file is not found in the metadata file"
echo ""
echo " So this can act as a pre filter. Where metadata file is the readme.txt"
echo " input dir is a graphics pack and output dir will be created"
echo " then the output dir can be manually scimmed and the obvious dupes"
echo " are already filtered."
echo "example:"
echo " $(basename "$0") mapres/readme.txt ~/Downloads/AwesomeMapresPack /tmp/mapres"
exit 0
elif [ "$#" != "3" ]
then
usage
exit 1
fi
META_FILE="$1"
IN_DIR="$2"
OUT_DIR="$3"
if [ ! -f "$META_FILE" ]
then
echo "Error: metedata file not found '$META_FILE'"
exit 1
fi
if [ ! -d "$IN_DIR" ]
then
echo "Error: input dir not found '$IN_DIR'"
exit 1
fi
if [ "$OUT_DIR" == "" ]
then
echo "Error: invalid output dir '$OUT_DIR'"
exit 1
fi
if [ -d "$OUT_DIR" ]
then
echo "Error: output dir should not exist yet '$OUT_DIR'"
exit 1
fi
mkdir -p "$OUT_DIR" || exit 1
function is_dupe() {
local sha
sha="$1"
for dupe_sha in $(grep sha1 "$META_FILE" | \
awk '{ print $2}' | \
sort | uniq)
do
if [ "$sha" == "$dupe_sha" ]
then
echo "dupe $sha"
return 0
fi
done
return 1
}
num_dupes=0
num_unqiues=0
for img in "$IN_DIR"/*.png
do
[[ -e "$img" ]] || break
sha="$(sha1sum "$img" | cut -d ' ' -f1)"
if is_dupe "$sha"
then
num_dupes="$((num_dupes + 1))"
else
cp "$img" "$OUT_DIR" || exit 1
num_unqiues="$((num_unqiues + 1))"
fi
done
echo "dupes: $num_dupes"
echo "uniques: $num_unqiues"