forked from JustDerb/yed-aws-palettes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate.sh
executable file
·118 lines (98 loc) · 3.13 KB
/
update.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
#!/bin/bash
[[ -n "${VERBOSE}" ]] && set -x
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ensure_on_path() {
command -v "$1" >/dev/null 2>&1 || { echo >&2 "I require '$1' but it's not installed. Aborting."; exit 1; }
}
display_help() {
echo >&2 "$0 <url> <version> <commit>"
echo -e >&2 "\turl: URL to Azure Icons"
echo -e >&2 "\tcommit: Auto-commit changes"
}
ensure_on_path curl
ensure_on_path java
ensure_on_path mvn
ensure_on_path git
ensure_on_path unzip
if [[ $# -lt 1 ]]; then
display_help
exit 1
fi
URL=$1
COMMIT=$2
TMP_DIR=$(mktemp -d)
[[ -z "${NO_CLEANUP}" ]] && trap "{ echo Removing ${TMP_DIR}; rm -rf ${TMP_DIR}; }" EXIT
echo >&2 "Downloading $1"
curl "${URL}" --output "${TMP_DIR}/azure-icons.zip"
unzip -o "${TMP_DIR}/azure-icons.zip" -d "${TMP_DIR}"
ICON_DIR=$(cd "${TMP_DIR}"/Azure_Public_Service_Icons/Icons && pwd)
ICON_VERSION=''
REGEX_NUMBER='([0-9]+)'
if ! [[ ${URL} =~ ${REGEX_NUMBER} ]]; then
echo >&2 "Couldn't parse version number from URL: ${URL}"
exit 1
else
ICON_VERSION="${BASH_REMATCH[1]}"
fi
if [ -z "$ICON_VERSION" ]; then
echo >&2 "Couldn't parse version number from URL: ${URL}"
exit 1
fi
echo "Detected version: ${ICON_VERSION}"
# Compile our translator
pushd "${DIR}/translator"
mvn package
popd
# Clear our old .graphml files
rm -f "${DIR}"/*.graphml
fix_mistakes() {
case "$(echo $1 | tr '[:upper:]' '[:lower:]')" in
"internet of things")
echo "IoT"
;;
*)
echo "$1"
;;
esac
}
find "${ICON_DIR}" -mindepth 1 -type d | sort | while read section; do
SECTION_NAME="$(echo ${section} | tr ' ' '_')"
SECTION_NAME="$(basename ${SECTION_NAME})"
SECTION_NAME="$(echo ${SECTION_NAME} | tr '_-' ' ' | tr -s ' ' ' ')"
SECTION_NAME="$(fix_mistakes "${SECTION_NAME}")"
if [ -z "$SECTION_NAME" ]; then
echo >&2 "Got empty section when parsing ${section}"
exit 1
fi
SECTION_NAME="Azure - ${SECTION_NAME}"
echo "Found: ${SECTION_NAME}"
mkdir -p "${TMP_DIR}/sections/${SECTION_NAME}"
cp "${section}"/*.svg "${TMP_DIR}/sections/${SECTION_NAME}" || \
echo "WARNING: ${section} had no SVGs!"
done
find "${TMP_DIR}/sections/${SECTION_NAME}" -type d -empty -prune \
-print -exec rmdir {} \;
for section in "${TMP_DIR}/sections/"*; do
SECTION_NAME="${section#${TMP_DIR}/sections/}"
if [ -z "$SECTION_NAME" ]; then
echo >&2 "Got empty section when parsing ${section}"
exit 1
fi
echo "Generating palette for: ${SECTION_NAME}"
java -jar "${DIR}/translator/target/yed-translator-1.0-SNAPSHOT.jar" \
--out "${DIR}/${SECTION_NAME}.graphml" \
--url "${URL}" \
--version "${ICON_VERSION}" \
"${section}/"*.svg
done
echo "AZURE_ICONS_VERSION=${ICON_VERSION}" > "${DIR}/metadata.config"
echo "AZURE_ICONS_URL=${URL}" >> "${DIR}/metadata.config"
if [[ -n "${COMMIT}" ]]; then
git add "${DIR}/"*.graphml
git add "${DIR}/metadata.config"
# Glob matching doesn't pick up our deleted .graphml files
git ls-files --deleted | grep ".graphml" | tr \\n \\0 | xargs -0 git add
git commit -m "Updating .graphml files to version ${ICON_VERSION}"
echo "git: Updating .graphml files to version ${ICON_VERSION}"
fi