-
Notifications
You must be signed in to change notification settings - Fork 302
/
install_manual.sh
executable file
·136 lines (92 loc) · 2.7 KB
/
install_manual.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
#!/usr/bin/env bash
# Requirements to install fonts
REQUIREMENTS="awk curl fc-cache mkdir mktemp unlink unzip"
readonly REQUIREMENTS
# Fonts local directory
LOCAL_FONTS_DIR="${HOME}/.local/share/fonts"
readonly LOCAL_FONTS_DIR
# Latest fonts release info in JSON
LATEST_RELEASE_INFO="https://api.github.com/repos/JetBrains/JetBrainsMono/releases/latest"
readonly LATEST_RELEASE_INFO
RED=$(echo -en '\033[00;31m')
readonly RED
RESTORE=$(echo -en '\033[0m')
readonly RESTORE
# Print error message to STDERR and exit
function die() {
echo >&2 "${RED}$*${RESTORE}"
exit 1
}
# Check requirements
function check_requirements() {
echo "Checking requirements..."
for tool in ${REQUIREMENTS}; do
echo -n "${tool}... "
if command -v "${tool}" >/dev/null 2>&1; then
echo "Found"
else
die "Not found. Please install \"${tool}\" to fix it."
fi
done
}
# Download URL
function download() {
url="${1}"
save_as="${2}"
curl -sL "${1}" -o "${save_as}" || die "Unable to download: ${url}"
}
# Generate temporary filename
function get_tempfile() {
mktemp
}
# Get item from latest release data
function get_item() {
item="${1}"
read_from="${2}"
awk -F '"' "/${item}/ {print \$4}" "${read_from}"
}
# Extract fonts archive
function extract() {
archive="${1}"
extract_to="${2}"
unzip -o "${archive}" -d "${extract_to}" >/dev/null 2>&1
}
# Create fonts directory
function create_fonts_dir() {
if [ ! -d "${LOCAL_FONTS_DIR}" ]; then
echo "Creating fonts directory: ${LOCAL_FONTS_DIR}"
mkdir -p "${LOCAL_FONTS_DIR}" >/dev/null 2>&1 || die "Unable to create fonts directory: ${LOCAL_FONTS_DIR}"
fi
}
# Build fonts cache
function build_fonts_cache() {
fc-cache -f || die "Unable to build fonts cache"
}
# Remove temporary file
function cleanup() {
unlink "${*}" || die "Unable to unlink: ${*}"
}
# Start point
function main() {
echo "Installing latest JetBrains Mono fonts..."
check_requirements
TEMP_LATEST_INFO=$(get_tempfile)
echo "Downloading latest release info: ${LATEST_RELEASE_INFO}"
download "${LATEST_RELEASE_INFO}" "${TEMP_LATEST_INFO}"
TAG_NAME=$(get_item "tag_name" "${TEMP_LATEST_INFO}")
echo "Latest fonts version: ${TAG_NAME}"
BROWSER_URL=$(get_item "browser_download_url" "${TEMP_LATEST_INFO}")
TEMP_FONTS_ARCHIVE=$(get_tempfile)
echo "Downloading fonts archive: ${BROWSER_URL}"
download "${BROWSER_URL}" "${TEMP_FONTS_ARCHIVE}"
create_fonts_dir
echo "Extracting fonts: ${LOCAL_FONTS_DIR}"
extract "${TEMP_FONTS_ARCHIVE}" "${LOCAL_FONTS_DIR}"
echo "Building fonts cache..."
build_fonts_cache
echo "Cleaning up..."
cleanup "${TEMP_LATEST_INFO}"
cleanup "${TEMP_FONTS_ARCHIVE}"
echo "Fonts have been installed"
}
main