-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_iptc_keywords
executable file
·78 lines (56 loc) · 1.46 KB
/
set_iptc_keywords
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
#! /usr/bin/env bash
set -e
shopt -s nocasematch
declare -r COLLECTOR_CMD=$(dirname "$0")/lib/collect_associated_files.sh
. "$(dirname "$0")/lib/sidecar.sh"
. "$(dirname "$0")/lib/jpeg.sh"
while getopts "v" opt; do
case $opt in
v )
declare -r VERBOSE=;;
esac
done
shift $(expr $OPTIND - 1 )
declare -r KEYWORDS=$1
if [[ -z $KEYWORDS ]]; then
echo "[ERROR] No keywords" >&2
exit 1
elif [[ -f $KEYWORDS || -d $KEYWORDS ]]; then
echo "[ERROR] Keywords parameter seems to be a file or directory - actual keywords parameter is missing?" >&2
exit 1
fi
shift 1
declare -r FILES=$@
set -u
"$COLLECTOR_CMD" $FILES | while read -r file; do
if [[ $file =~ .*\.pp[23]$ ]]; then
if ! [[ -w $file ]]; then
chmod u+w "$file"
declare restore_write_protection=
fi
if ! grep -q "^\[IPTC\]$" "$file"; then
echo -e "\n[IPTC]\nKeywords=;\n" >> $file
fi
sidecar_add_iptc_keywords "$file" "$KEYWORDS"
if [[ -v restore_write_protection ]]; then
chmod u-w "$file"
unset restore_write_protection
fi
if [[ -v VERBOSE ]]; then
echo "[INFO] $file" >&2
fi
elif [[ $file =~ .*/converted/.*\.jpg$ ]]; then
if ! [[ -w $file ]]; then
test -v SIMULATE || chmod u+w "$file"
declare restore_write_protection=
fi
jpeg_set_iptc_keywords "$KEYWORDS" "$file"
if [[ -v restore_write_protection ]]; then
chmod u-w "$file"
unset restore_write_protection
fi
if [[ -v VERBOSE ]]; then
echo "[INFO] $file" >&2
fi
fi
done