-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·78 lines (68 loc) · 2.41 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
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o noclobber
set -o nounset
#set -o xtrace
FA_VERSION=6.1.1
FA_NAME=fontawesome-free-${FA_VERSION}-web
FA_URL=https://use.fontawesome.com/releases/v${FA_VERSION}/${FA_NAME}.zip
ASSET_DIR=stylesheets/fontawesome
METADATA_DIR=metadata
################
# REQUIREMENTS #
################
# The following packages:
# - python-yq
# - unzip
# - wget
# Get the script directory
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Extract the following files from Fontawesome into this directory:
# - webfonts/
# - css/all.min.css
# - metadata/icons.yml
echo "Downloading: ${FA_URL}"
tmp_dir=$(mktemp -d)
trap "rm -rf $tmp_dir" 0 2 3 15
wget -q -O "${tmp_dir}/fontawesome.zip" "${FA_URL}"
echo "Unpacking: ${FA_NAME}.zip"
unzip -q "${tmp_dir}/fontawesome.zip" -d "${tmp_dir}/fontawesome/"
echo "Copying: webfonts/ to ${ASSET_DIR}/webfonts/"
rm -r "${dir}/${ASSET_DIR}/webfonts/" 2> /dev/null || true
mkdir -p "${dir}/${ASSET_DIR}/webfonts/"
cp -r "${tmp_dir}/fontawesome/${FA_NAME}/webfonts/" "${dir}/${ASSET_DIR}/webfonts/"
echo "Copying: css/all.min.css to ${ASSET_DIR}/css/all.min.css"
rm -r "${dir}/${ASSET_DIR}/css/" 2> /dev/null || true
mkdir -p "${dir}/${ASSET_DIR}/css/"
cp "${tmp_dir}/fontawesome/${FA_NAME}/css/all.min.css" "${dir}/${ASSET_DIR}/css/"
echo "Copying: metadata/icons.yml to ${ASSET_DIR}/metadata/"
rm -r "${dir}/${ASSET_DIR}/metadata/" 2> /dev/null || true
mkdir -p "${dir}/${ASSET_DIR}/metadata/"
cp "${tmp_dir}/fontawesome/${FA_NAME}/metadata/icons.yml" "${dir}/${ASSET_DIR}/metadata/"
# Overwrite icons.app header
echo "Generating: icons.app"
set +o noclobber # Allow overwriting files
cat > "${dir}/icons.app" << EOF
////////////////////////////////////////////
// This file is generated. DO NOT MODIFY! //
////////////////////////////////////////////
// See this repo's README.md for more info.
module elib/elib-fontawesome/icons
section Icons
htmlwrapper{
EOF
set -o noclobber # Disallow overwriting files
# Append icons.app content
cat "${dir}/${ASSET_DIR}/metadata/icons.yml" | yq -r 'to_entries | map(. |
.key as $key |
((.key / "-") | map((.[:1] | ascii_upcase) + .[1:]) | join("")) as $name |
.value.styles[] | . as $style |
.[:1] as $letter |
" fa\($letter)\($name) i[class=\"fa-\($style) fa-\($key)\"]") |
.[]' >> "${dir}/icons.app"
# Append icons.app footer
cat >> "${dir}/icons.app" << EOF
}
EOF
echo "Done!"