forked from nativefier/nativefier-icons
-
Notifications
You must be signed in to change notification settings - Fork 2
/
addIcon
executable file
·73 lines (52 loc) · 1.77 KB
/
addIcon
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
#!/bin/sh
# Will automatically convert and add the output properly to gitCloud
# USAGE
# ./addIcon <input png or svg>
# Example
# ./addIcon ~/Desktop/facebook.png
## Dependencies
# imagemagick, svg2png
set -e
# Exec Paths
type convert >/dev/null 2>&1 || { echo >&2 "Cannot find required ImageMagick Convert executable"; exit 1; }
type identify >/dev/null 2>&1 || { echo >&2 "Cannot find required ImageMagick Identify executable"; exit 1; }
type svg2png >/dev/null 2>&1 || { echo >&2 "Cannot find required svg2png executable"; exit 1; }
CONVERT_TO_ICNS="${BASH_SOURCE%/*}/bin/convertToIcns"
CONVERT_TO_ICO="${BASH_SOURCE%/*}/bin/convertToIco"
TEMP_DIR="convert_temp_hello"
function cleanUp() {
rm -rf "${TEMP_DIR}"
}
trap cleanUp EXIT
mkdir -p "${TEMP_DIR}"
SOURCE=$1
if [ -z "${SOURCE}" ]; then
echo "No source image specified"
exit 1
fi
NAME=$(basename "${SOURCE}")
EXT="${NAME##*.}"
BASE="${NAME%.*}"
if [ "${EXT}" == "svg" ]; then
svg2png "${SOURCE}" "--output=${TEMP_DIR}/${BASE}.png" "--width=1024" "--height=1024"
SOURCE="${TEMP_DIR}/${BASE}.png"
fi
NAME=$(basename "${SOURCE}")
EXT="${NAME##*.}"
if [ "${EXT}" != "png" ]; then
echo ".png or .svg must be provided"
exit 1
fi
# Force exit 0 for cp so that if files are identical the script will still proceed to overwrite
cp "${SOURCE}" "files/${BASE}.png" || :
${CONVERT_TO_ICNS} "${SOURCE}" "files/${BASE}.icns"
${CONVERT_TO_ICO} "${SOURCE}" "files/${BASE}.ico"
## append to .gitCloud.yml
echo "- name: ${BASE}" >> _data/gitCloud.yml
echo " href: files/${BASE}.png" >> _data/gitCloud.yml
echo "- name: ${BASE}" >> _data/gitCloud.yml
echo " href: files/${BASE}.ico" >> _data/gitCloud.yml
echo "- name: ${BASE}" >> _data/gitCloud.yml
echo " href: files/${BASE}.icns" >> _data/gitCloud.yml
trap - EXIT
cleanUp