-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
210 lines (191 loc) · 6.19 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env bash
## Colors.
BLUE='\033[0;36m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
RED='\033[0;31m'
PURPLE='\033[0;35m'
NC='\033[0m'
## Logs.
INFO="${NC}[${BLUE}INFO${NC}]"
WARN="${NC}[${ORANGE}WARN${NC}]"
ERROR="${NC}[${ORANGE}ERROR${NC}]"
DONE="${NC}[${PURPLE}DONE${NC}]"
OK="${GREEN}OK${NC}"
NF="${BLUE}Not Found${NC}"
## Checking for curl.
echo -en "$INFO Checking for curl..."
if ! type curl >/dev/null 2>&1; then
echo -e "\n$ERROR This script requires curl. Exiting."
exit 1
fi
echo -e "$OK"
## Checking for git.
echo -en "$INFO Checking for git..."
if ! type git >/dev/null 2>&1; then
echo -e "\n$ERROR This script requires git. Exiting."
exit 1
fi
echo -e "$OK"
## Checking for tar.
echo -en "$INFO Checking for tar..."
if ! type tar >/dev/null 2>&1; then
echo -e "\n$ERROR This script requires tar. Exiting."
exit 1
fi
echo -e "$OK"
## Checking for optional zsh.
echo -en "$INFO Checking for zsh..."
if type zsh >/dev/null 2>&1; then
if ! [[ $SHELL =~ "zsh" ]]; then
echo -e "\n$WARN You are not using zsh, change your default shell using ${PURPLE}chsh${NC} or ${PURPLE}usermod${NC}."
else
echo -e "$OK"
fi
else
echo -e "\n$WARN zsh not installed."
fi
## Moving to home directory for installation.
echo -en "$INFO Moving to home directory..."
cd $HOME || exit 1
echo -e "$OK"
## Download grml .zshrc.
echo -en "$INFO Checking for .zshrc..."
if [[ -f .zshrc ]]; then
dest=".zshrc.$(date +%F).old"
echo -en "\n$WARN .zshrc already exits. Moving it to $dest..."
mv .zshrc $dest || exit 1
echo -e "$OK"
else
echo -e "$NF"
fi
echo -en "$INFO Downloading .zshrc from grml website..."
curl -sLo .zshrc https://git.grml.org/f/grml-etc-core/etc/zsh/zshrc || exit 1
echo -e "$OK"
## Download .zshrc.local.
echo -en "$INFO Checking for .zshrc.local..."
if [[ -f ".zshrc.local" ]]; then
dest=".zshrc.local.$(date +%F).old"
echo -en "\n$WARN .zshrc.local already exits. Moving it to $dest..."
mv ".zshrc.local" $dest || exit 1
echo -e "$OK"
else
echo -e "$NF"
fi
echo -en "$INFO Downloading .zshrc.local from GitHub..."
curl -sLo ".zshrc.local" "https://raw.githubusercontent.com/scotow/zsh-setup/master/local.zsh" || exit 1
echo -e "$OK"
## Check/create .zsh directory.
echo -en "$INFO Checking for .zsh directory..."
if [[ -e .zsh ]]; then
if [[ -d .zsh ]]; then
echo -e "$OK"
else
echo -e "\n$ERROR .zsh already exists and it's not a directory. Exiting."
exit 1
fi
else
echo -e "$NF"
echo -en "$INFO Creating .zsh directory..."
mkdir .zsh || exit 1
echo -e "$OK"
fi
## Download zsh-autosuggestions and zsh-syntax-highlighting.
for plugin in 'zsh-autosuggestions' 'zsh-syntax-highlighting'; do
echo -en "$INFO Checking for $plugin..."
if [[ -d ".zsh/$plugin" ]]; then
echo -e "\n$WARN .zsh/$plugin already exits. Skipping."
else
echo -e "$NF"
echo -en "$INFO Cloning $plugin from GitHub..."
git clone -q "https://github.com/zsh-users/$plugin" ".zsh/$plugin" || exit 1
echo -e "$OK"
fi
done
## Install fzf binary.
echo -en "$INFO Checking for fzf binary..."
if ! type fzf >/dev/null 2>&1; then
echo -e "$NF"
if [[ -e .zsh/bin/fzf ]]; then
echo -e "$WARN .zsh/bin/fzf already exists but is not in the the current path."
else
echo -en "$INFO Installing fzf is only supported on linux/macOS. Checking..."
distro="$(uname -s | tr 'A-Z' 'a-z')"
if [[ $distro == *linux* ]]; then
distro="linux"
elif [[ $distro == *darwin* ]]; then
distro="darwin"
else
echo -e "\n$WARN Cannot use the following distro for fzf installation: $distro. Skipping fzf installation."
distro="none"
fi
if [[ "$distro" != "none" ]]; then
archi="$(uname -m | tr 'A-Z' 'a-z')"
if [[ $archi == *aarch64* || $archi == arm64 ]]; then
archi="arm64"
elif [[ $archi == *64* ]]; then
archi="amd64"
elif [[ $archi == *armv5* ]]; then
archi="armv5"
elif [[ $archi == *armv6* ]]; then
archi="armv6"
elif [[ $archi == *armv7* ]]; then
archi="armv7"
else
echo -e "\n$WARN Cannot use the following architecture for fzf installation: $archi. Skipping fzf installation."
archi="none"
fi
fi
if [[ "$distro" != "none" && "$archi" != "none" ]]; then
echo -e "$OK"
echo -en "$INFO Checking for .zsh/bin directory..."
if [[ -e .zsh/bin ]]; then
if [[ -d .zsh/bin ]]; then
echo -e "$OK"
else
echo -e "\n$WARN .zsh/bin already exists and it's not a directory. Skipping fzf installation."
distro="none"
fi
else
echo -e "$NF"
echo -en "$INFO Creating .zsh/bin directory..."
mkdir .zsh/bin || exit 1
echo -e "$OK"
fi
echo -en "$INFO Fetching fzf last version number..."
version=$(curl -sI 'https://github.com/junegunn/fzf/releases/latest' | grep -i Location: | rev | cut -d/ -f1 | rev | tr -d '\n\r')
if [[ -z "$version" ]]; then
echo -e "\n$ERROR Cannot fetch latest version number. Exiting."
exit 1
fi
echo -e "${BLUE}$version${NC}"
echo -en "$INFO Downloading fzf binary..."
if [[ "$distro" == "linux" ]]; then
curl -sL "https://github.com/junegunn/fzf/releases/download/$version/fzf-$version-${distro}_${archi}.tar.gz" | tar -xzf - -C .zsh/bin || exit 1
elif [[ "$distro" == "darwin" ]]; then
cd $(mktemp -d)
curl -sLJO "https://github.com/junegunn/fzf/releases/download/$version/fzf-$version-${distro}_${archi}.zip" && unzip *.zip && mv fzf $HOME/.zsh/bin/ || exit 1
cd -
fi
echo -e "$OK"
fi
fi
else
echo -e "$OK"
fi
## Download fzf plugins.
for file in fzf-key-bindings fzf-completion; do
echo -en "$INFO Checking for $file..."
if [[ -f ".zsh/$file.zsh" ]]; then
dest=".zsh/$file.zsh.$(date +%F).old"
echo -en "\n$WARN .zsh/$file.zsh already exits. Moving it to $dest..."
mv ".zsh/$file.zsh" $dest || exit 1
echo -e "$OK"
else
echo -e "$NF"
fi
echo -en "$INFO Downloading $file from Github..."
curl -sLo ".zsh/$file.zsh" "https://raw.githubusercontent.com/scotow/zsh-setup/master/$file.zsh" || exit 1
echo -e "$OK"
done
echo -e "\n$DONE Installation complete. Restart your shell or run ${PURPLE}exec zsh${NC} to apply."