This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
/
addIcon
executable file
·72 lines (59 loc) · 2.16 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
#!/bin/sh
# Will automatically convert and add the output properly to gitCloud
# USAGE
# =====
# ./addIcon <input.svg or input.png>
# Example:
# ./addIcon ~/Desktop/icon.png
# Exit the shell script on error immediately
set -e
# Check for dependencies
# imagemagick
type convert >/dev/null 2>&1 || { echo >&2 "Cannot find required ImageMagick Convert executable"; exit 1; }
# svg2png
type svg2png >/dev/null 2>&1 || { echo >&2 "Cannot find required svg2png executable"; exit 1; }
# iconutil
type iconutil >/dev/null 2>&1 || { echo >&2 "Cannot find required iconutil executable"; exit 1; }
# Import scripts as variable
CONVERT_TO_PNG="${BASH_SOURCE%/*}/bin/convertToPng"
CONVERT_TO_ICO="${BASH_SOURCE%/*}/bin/convertToIco"
CONVERT_TO_ICNS="${BASH_SOURCE%/*}/bin/convertToIcns"
# Argument
SOURCE=$1
# Check argument
if [ -z "${SOURCE}" ]; then
echo "No source image specified"
exit 1
fi
# File variables
SOURCE_NAME=$(basename "${SOURCE}")
SOURCE_EXT="${SOURCE_NAME##*.}"
SOURCE_BASE="${SOURCE_NAME%.*}"
# Temp directory
TEMP_DIR=".addIcon"
mkdir -p "${TEMP_DIR}"
# Cleanup
function cleanUp() {
rm -rf "${TEMP_DIR}"
}
trap cleanUp EXIT
# Check for file type
if [ "${SOURCE_EXT}" == "svg" ] || [ "${SOURCE_EXT}" == "png" ]; then
${CONVERT_TO_PNG} "${SOURCE}" "${TEMP_DIR}/${SOURCE_BASE}.png"
${CONVERT_TO_ICO} "${TEMP_DIR}/${SOURCE_BASE}.png" "${TEMP_DIR}/${SOURCE_BASE}.ico"
${CONVERT_TO_ICNS} "${SOURCE}" "${TEMP_DIR}/${SOURCE_BASE}.icns"
# Force exit 0 for cp so that if files are identical the script will still proceed to overwrite
cp "${TEMP_DIR}/${SOURCE_BASE}.png" "files/${SOURCE_BASE}.png" || :
cp "${TEMP_DIR}/${SOURCE_BASE}.ico" "files/${SOURCE_BASE}.ico" || :
cp "${TEMP_DIR}/${SOURCE_BASE}.icns" "files/${SOURCE_BASE}.icns" || :
## append to .gitCloud.yml
echo "- name: ${SOURCE_BASE}" >> _data/gitCloud.yml
echo " href: files/${SOURCE_BASE}.png" >> _data/gitCloud.yml
echo "- name: ${SOURCE_BASE}" >> _data/gitCloud.yml
echo " href: files/${SOURCE_BASE}.ico" >> _data/gitCloud.yml
echo "- name: ${SOURCE_BASE}" >> _data/gitCloud.yml
echo " href: files/${SOURCE_BASE}.icns" >> _data/gitCloud.yml
else
echo "SVG or PNG must be provided"
exit 1
fi