-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiconVersioning.sh
executable file
ยท156 lines (110 loc) ยท 5.14 KB
/
iconVersioning.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
_scriptVersion="1.1.3"
_debug=
echo "------------------------------------------------------------------------------------------------------"
echo "๐ App Icon Annotating script v${_scriptVersion} // Created by ๐ Ilya Stroganov [https://github.com/jormungand]"
echo "โ Created under inspiration of the similar script by Krzysztof Zabลocki [http://merowing.info/]"
echo "------------------------------------------------------------------------------------------------------"
##############################################################################################################
##############################################################################################################
##############################################################################################################
## API
##
DEBUG() {
[[ -n "${_debug}" ]] && echo -e "DEBUG: $@"
}
##############################################################################################################
annotateIcon() {
_file="${1}"
_caption="${2}"
[[ -f "${_file}" ]] || {
echo "โ ๏ธ File not found: ${_file} --> skipped"
return;
}
echo "โ
Processing file: ${_file}"
_name="$( basename "${_file}" )"
_tmpDir="$( mktemp -d )"
xcrun pngcrush -revert-iphone-optimizations -q "${_file}" "${_tmpDir}/${_name}" >/dev/null 2>&1
_dim="$( identify -format %w "${_tmpDir}/${_name}" )"
_margin="$(( ${_dim} / 6 ))"
_offset="$(( ${_dim} - ${_margin} ))"
_bandRegion="${_dim}x${_margin}+0+${_offset}"
_labelSize="${_offset}x${_margin}"
## TODO: save as "${_tmpDir}/${_name}-annotated.png", then run re-optimize using pngcrush
convert "${_tmpDir}/${_name}" -region "${_bandRegion}" -blur "10x10" +region \
-fill "#0004" -draw "rectangle 0,${_offset},${_dim},${_dim}" \
\( -background "#fff0" -fill "#ffff" -gravity "center" -font "ArialB" -size "${_labelSize}" caption:"${_caption}" \) \
-gravity "south" -composite "${_file}"
rm -rf "${_tmpDir}"
}
##############################################################################################################
##############################################################################################################
##############################################################################################################
## prerequisites: ImageMagick & Ghostscript
##
export PATH="/usr/local/bin:/usr/libexec:$PATH"
_convert="$( which convert )"
_gs="$( which gs )"
[[ -x "${_convert}" && -x "${_gs}" ]] || {
echo "โ๏ธ ERROR: Install dependencies first:"
echo -e "\tbrew install imagemagick ghostscript"
echo -e "\n\n----------------------------\n๐ CANCELLED\n"
exit 0;
}
## PlistBuddy
[[ -x "$( which PlistBuddy )" ]] || {
echo "โ๏ธ ERROR: Couldn't find PlistBuddy"
echo -e "PATH = (\n$( echo $PATH | tr ':' '\n' | awk '{ print "\t"$1 }' | sort -ru )\n)"
echo -e "\n\n----------------------------\n๐ CANCELLED\n"
exit 0;
}
##############################################################################################################
## Get build params
##
echo -e "๐ Reading configuration:\n---"
_infoPlist="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
[[ -f "${_infoPlist}" ]] || {
echo "โ๏ธ ERROR: Info plist is not found: INFOPLIST_PATH = [${INFOPLIST_PATH}], TARGET_BUILD_DIR = [${TARGET_BUILD_DIR}]"
echo -e "\n\n----------------------------\n๐ CANCELLED\n"
exit;
}
_version="$( PlistBuddy -c "Print CFBundleShortVersionString" "${_infoPlist}" )"
_buildNum="$( PlistBuddy -c "Print CFBundleVersion" "${_infoPlist}" )"
_bundleID="$( PlistBuddy -c "Print CFBundleIdentifier" "${_infoPlist}" )"
echo "๐น Version = [${_version}]"
echo "๐น BuildNum = [${_buildNum}]"
echo "๐น BundleID = [${_bundleID}]"
## Git status
git rev-parse --git-dir >/dev/null 2>&1 || {
echo "โ๏ธ ERROR: Git dir is not found: PWD = [${PWD}]"
echo -e "\n\n----------------------------\n๐ CANCELLED\n"
exit 0;
}
_commit="$( git rev-parse --short HEAD )"
_branch="$( git rev-parse --abbrev-ref HEAD )"
echo "๐น Commit = [${_commit}]"
echo "๐น Branch = [${_branch}]"
_caption="${_version} (${_buildNum})"
echo -e "---\nโ
Icon badge caption string = [${_caption}]"
##############################################################################################################
pushd "$( dirname "${_infoPlist}" )" >/dev/null
echo "------------------------------------------------------------------------------------------------------"
echo -e "๐ Searching for icons:\n---"
for _key in "CFBundleIcons" "CFBundleIcons~ipad"; do
_icons+="$( PlistBuddy -c "Print '${_key}:CFBundlePrimaryIcon:CFBundleIconFiles'" "${_infoPlist}" | grep -vE '[{}]' )"
_icons="$( echo "${_icons[@]}" | tr ' ' "\n" | sort -u )"
done
for _i in ${_icons[@]}; do
echo -e "๐ธ ${_i}"
done
## Enumerating through exact files
echo "------------------------------------------------------------------------------------------------------"
for _i in ${_icons[@]}; do
echo "โ [${_i}*.png]"
for _f in $( find ${PWD} -iname "${_i}*.png" ); do
annotateIcon "${_f}" "${_caption}"
done
echo "---"
done
popd >/dev/null
echo -e "\n\n----------------------------\n๐ DONE\n----------------------------\n"