-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess.sh
executable file
·68 lines (62 loc) · 2.11 KB
/
preprocess.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/zsh
echo "Preprocessing image files..."
if [ ! -d .s3/source-images.phylopic.org/images ]; then
echo "No folder for source images!" 1>&2
exit 1
fi
echo "Setting up scratch and destination..."
{
if [ -d .scratch ]; then
rm -rf .scratch
fi
mkdir .scratch
mkdir .scratch/raster &
mkdir .scratch/vector
wait
} &
{
if [ ! -d .s3/images.phylopic.org ]; then
mkdir .s3/images.phylopic.org
fi
if [ ! -d .s3/images.phylopic.org/images ]; then
mkdir .s3/images.phylopic.org/images
else
for file in .s3/images.phylopic.org/images; do
if [ ! -d '.s3/source-images.phylopic.org/images/'$file ]; then
rm -rf '.s3/images.phylopic.org/images/'$file
fi
done
fi
}
wait
echo "Set up scratch and destination. Copying source images to scratch..."
for file in .s3/source-images.phylopic.org/images/**/source; do
type=$(file --mime-type --brief $file 2>&1)
if [ "$type" = "image/svg+xml" ]; then
comparison=$(echo $file |
sed 's/^\.s3\/source-images\.phylopic\.org\//.s3\/images.phylopic.org\//' |
sed 's/source$/source.svg/')
changed=$(cmp --silent $file $comparison && echo 0 || echo 1)
if [[ $changed -eq 1 ]]; then
dest=$(echo $file |
sed 's/^\.s3\/source-images\.phylopic\.org\/images\//.scratch\/vector\//' |
sed 's/\/source$/.source.svg/')
cp $file $dest
fi
else
extension=$(echo $type |
sed 's/^image\///')
comparison=$(echo $file |
sed 's/^\.s3\/source-images\.phylopic\.org\//.s3\/images.phylopic.org\//' |
sed 's/source$/source.'$extension'/')
changed=$(cmp --silent $file $comparison && echo 0 || echo 1)
if [[ $changed -eq 1 ]]; then
dest=$(echo $file |
sed 's/^\.s3\/source-images\.phylopic\.org\/images\//.scratch\/raster\//' |
sed 's/\/source$/.source.'$extension'/')
cp $file $dest
fi
fi
done
echo "Copied source images to scratch."
echo "Preprocessed image files."