-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
106 lines (87 loc) · 3.06 KB
/
install.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
#!/usr/bin/env bash
# first and only argument is
# nerd_font_name="NAME"
# "NAME" being name of the Nerd Font that is
# inside ryanoasis/nerd-fonts repository on github
# It's case sensitive, so make sure you check and write font name in right case
# In case of "Hack" nerd font:
# GOOD: "Hack"
# BAD: "hack"
# BAD: "Hack.zip"
# BAD: "hack.zip"
dependencies=(
fc-list
fc-cache
curl
unzip
)
all_dependencies_are_installed=true
for dep in "${dependencies[@]}"; do
if ! command -v "$dep" &>/dev/null; then
all_dependencies_are_installed=false
fi
done
get_font() {
# create a temporary directory
TEMP_FONT_DIR=$(mktemp --directory)
local nerd_fonts_repo_url="https://github.com/ryanoasis/nerd-fonts/releases/latest/download/$nerd_font_name.zip"
# download the font zip file
curl -L -o "$TEMP_FONT_DIR/font.zip" "$nerd_fonts_repo_url"
# unzip the font file
unzip "$TEMP_FONT_DIR/font.zip" -d "$TEMP_FONT_DIR"
# determine the user fonts directory based on the OS
if [[ "$(uname)" == "Darwin" ]]; then
USER_FONTS_DIR="$HOME/Library/Fonts"
else
USER_FONTS_DIR="$HOME/.local/share/fonts"
fi
# create user fonts directory if it doesn't already exist
mkdir -p "$USER_FONTS_DIR"
# move the font files to the user fonts directory
mv "$TEMP_FONT_DIR"/*.{otf,ttf,woff,woff2,eot,svg} "$USER_FONTS_DIR" 2>/dev/null
# update the font cache
fc-cache -f -v
echo "<--- $nerd_font_name installed. --->"
# clean up temporary directory
rm -rf "$TEMP_FONT_DIR"
}
# placeholder for nerd_font_name to be given as an argument to install.sh script
nerd_font_name="${1:-$nerd_font_name}"
if [ -z "$nerd_font_name" ]; then
echo "<--- Provide Nerd Font Name --->"
exit 1
fi
if $all_dependencies_are_installed; then
echo "<--- Installing $nerd_font_name --->"
# check if similar named font is already installed
similar_named_font_found=$(fc-list : family | \sort | \uniq | \grep "$nerd_font_name")
# if similarly named font is not installed, runs the following script
# else, echos similarly named fonts. All of them.
if [ -z "$similar_named_font_found" ]; then
get_font
else
echo "<--- Font / Fonts with name similar to $nerd_font_name found: --->"
fc-list : family | \sort | \uniq | \grep "$nerd_font_name"
read -r -p "Do you want to cancel installation of $nerd_font_name? (Y/n)" prompt_response
if [[ $prompt_response == "n" ]]; then
echo "<--- Installing $nerd_font_name --->"
get_font
else
echo "<--- Installation of $nerd_font_name cancelled --->"
fi
fi
else
echo "<--- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --->"
echo "<--- ONE OR MORE OF THE REQUIRED DEPENDENCIES ARE NOT INSTALLED!!! --->"
echo "<--- DEPENDENCIES: --->"
# checks each package individually to see which packages
# are not installed and echos them all out with their status of installation
for dep in "${dependencies[@]}"; do
if command -v "$dep" &>/dev/null; then
echo "<--- $dep - Status: Installed. --->"
else
echo "<--- $dep - Status: NOT INSTALLED!!! --->"
fi
done
exit 1
fi