-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·381 lines (292 loc) · 8.71 KB
/
install
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#!/usr/bin/env bash
set -e
# ---------------------------------------------- #
#
# "install --help" for more information.
#
# ---------------------------------------------- #
# ---------------------------------------------- #
# shell-utils #
# ---------------------------------------------- #
# Colors
red="\e[31m"
green="\e[32m"
yellow="\e[33m"
normal="\e[0m"
function alert_die {
local error="${1}"
print_new_line
alert "Error: ${error}"
die
}
function print {
echo -e "${*}"
}
function print_error {
print >&2 "${*}"
}
function print_new_line {
print ""
}
# Prints a green success message.
function success {
print "${green}${*}${normal}"
}
# Prints a yellow warning message.
function warning {
print "${yellow}${*}${normal}"
}
# Prints a red error message.
function alert {
print_error "${red}${*}${normal}"
}
# Wrapper for "exit" when error.
function die {
exit 1
}
# Wrapper for "exit" without error.
function close {
exit 0
}
function validate_checksum {
local checksum=${1}
local file=${2}
print "${checksum}" "${file}" | sha256sum --quiet --check -
}
# ---------------------------------------------- #
# Install #
# ---------------------------------------------- #
function help {
cat <<EOF
Install package dotfiles.
Syntax: ${0} [OPTIONS...]
Options:
-h, --help: Show this message"
--deps Install all dependencies to install and run the development environment
--docker Install zinit plugins for docker and docker compose
--elixir Add plugins and environment variables for Elixir development
--fonts Install Fira Code from Nerd fonts
--wsl-gpg Setup files used by GPG inside WSL
--wsl-ssh Install dependencies and setup files used by GPG inside WSL
--[no-]asdf [Do not] install asdf (install it by default)
--[no-]zsh [Do not] install zsh (install it by default)
EOF
}
function may_update_package_list {
if [[ ${opt_deps} -eq 1 ||
${opt_zsh} -eq 1 ||
${opt_wsl_gpg} -eq 1 ||
${opt_wsl_ssh} -eq 1 ]]; then
sudo apt update -qq
fi
}
function may_install_deps_packages {
if [[ ${opt_deps} -eq 0 ]]; then
return 0
fi
sudo apt install -y -qq --no-install-recommends \
curl \
gnupg2 \
make \
nano \
openssh-client \
tar \
wget \
xz-utils
success "✓ Dependencies packages installed"
}
function may_install_zsh {
if [[ ${opt_zsh} -eq 1 ]]; then
sudo apt install -y -qq --no-install-recommends zsh
cp -r "${config_dir}/zsh/." "${HOME}"
fi
}
function uncomment_zshrc_variable {
local variable=${1}
sed -i "/^# local ${variable}=/s/^# //" "${dot_zshrc}"
}
function may_install_asdf {
if [[ ${opt_asdf} -eq 0 ]]; then
return 0
fi
if which asdf >/dev/null; then
warning "asdf already installed: skipped"
return 0
fi
mkdir "${ASDF_DIR}"
git clone --quiet --branch v0.9.0 \
https://github.com/asdf-vm/asdf.git "${ASDF_DIR}"
print ". \$HOME/.asdf/asdf.sh" >>"${dot_bashrc}"
print ". \$HOME/.asdf/completions/asdf.bash" >>"${dot_bashrc}"
success "✓ asdf installed"
}
function may_setup_wsl_gpg {
if [[ ${opt_wsl_gpg} -eq 0 ]]; then
return 0
fi
gnupg_dir="${HOME}/.gnupg"
gpg_agent_config="${gnupg_dir}/gpg-agent.conf"
if [[ -f "${gpg_agent_config}" ]]; then
warning "GPG for WSL is already set up: skipped"
return 0
fi
mkdir -p "${gnupg_dir}"
chmod 700 "${gnupg_dir}"
cp -r "${config_dir}/gpg/." "${gnupg_dir}"
gpg-connect-agent reloadagent /bye
success "✓ Setup GPG for WSL done"
}
function may_setup_wsl_ssh {
if [[ ${opt_wsl_ssh} -eq 0 ]]; then
return 0
fi
if which keychain >/dev/null; then
warning "SSH for WSL is already set up: skipped"
return 0
fi
sudo apt install -y -qq --no-install-recommends keychain
# shellcheck disable=SC2016
print 'eval "$(keychain --eval --agents ssh id_rsa)"' >>"${dot_bashrc}"
uncomment_zshrc_variable "dotfiles_wsl_ssh"
success "✓ Setup SSH for WSL done"
}
function install_asdf_versions {
setup_asdf_version fzf 0.29.0
setup_asdf_version lsd 0.21.0 https://github.com/argylelabcoat/asdf-lsd.git
}
function setup_asdf_version {
local plugin=${1}
local version=${2}
local plugin_url=${3:-""}
asdf plugin add "${plugin}" "${plugin_url}"
asdf install "${plugin}" "${version}"
asdf global "${plugin}" "${version}"
}
# --------------- BEGIN: Options --------------- #
function may_setup_elixir_plugins {
if [[ ${opt_elixir} -eq 0 ]]; then
return 0
fi
uncomment_zshrc_variable "dotfiles_elixir"
success "✓ Setup for elixir: done"
}
function may_setup_docker_plugins {
if [[ ${opt_docker} -eq 0 ]]; then
return 0
fi
uncomment_zshrc_variable "dotfiles_docker"
success "✓ Setup for docker: done"
}
# Install Fira Code from Nerd fonts
function may_install_fonts {
if [[ ${opt_fonts} -eq 0 ]]; then
return 0
fi
local fonts_dir=${HOME}/.local/share/fonts
if [[ $(find "${fonts_dir}"/Fura*Code*.ttf 2>/dev/null | wc -l) -gt 0 ]]; then
warning "Fonts already installed: skipped"
return 0
fi
local version="2.1.0"
local url=https://github.com/ryanoasis/nerd-fonts/raw/${version}/patched-fonts/FiraCode
local fira_code_light_checksum="5e0e3b18b99fc50361a93d7eb1bfe7ed7618769f4db279be0ef1f00c5b9607d6"
local fira_code_regular_checksum="3771e47c48eb273c60337955f9b33d95bd874d60d52a1ba3dbed924f692403b3"
local fira_code_medium_checksum="42dc83c9173550804a8ba2346b13ee1baa72ab09a14826d1418d519d58cd6768"
local fira_code_bold_checksum="060d4572525972b6959899931b8685b89984f3b94f74c2c8c6c18dba5c98c2fe"
local fira_code_retina_checksum="e254b08798d59ac7d02000a3fda0eac1facad093685e705ac8dd4bd0f4961b0b"
wget -nv -P "${tmp}" ${url}/Light/complete/Fura%20Code%20Light%20Nerd%20Font%20Complete.ttf
wget -nv -P "${tmp}" ${url}/Regular/complete/Fura%20Code%20Regular%20Nerd%20Font%20Complete.ttf
wget -nv -P "${tmp}" ${url}/Medium/complete/Fura%20Code%20Medium%20Nerd%20Font%20Complete.ttf
wget -nv -P "${tmp}" ${url}/Bold/complete/Fura%20Code%20Bold%20Nerd%20Font%20Complete.ttf
wget -nv -P "${tmp}" ${url}/Retina/complete/Fura%20Code%20Retina%20Nerd%20Font%20Complete.ttf
validate_checksum "${fira_code_light_checksum}" "${tmp}/Fura Code Light Nerd Font Complete.ttf"
validate_checksum "${fira_code_regular_checksum}" "${tmp}/Fura Code Regular Nerd Font Complete.ttf"
validate_checksum "${fira_code_medium_checksum}" "${tmp}/Fura Code Medium Nerd Font Complete.ttf"
validate_checksum "${fira_code_bold_checksum}" "${tmp}/Fura Code Bold Nerd Font Complete.ttf"
validate_checksum "${fira_code_retina_checksum}" "${tmp}/Fura Code Retina Nerd Font Complete.ttf"
mkdir -p "${fonts_dir}"
cp "${tmp}"/Fura*Code*.ttf "${fonts_dir}"
success "✓ Fira Code from Nerd fonts installed"
}
function parse_options {
# Install options
opt_asdf=1
opt_deps=0
opt_docker=0
opt_elixir=0
opt_fonts=0
opt_wsl_gpg=0
opt_wsl_ssh=0
opt_zsh=1
for opt in "${@}"; do
case ${opt} in
-h | --help)
help
close
;;
# Install options
--deps) opt_deps=1 ;;
--docker) opt_docker=1 ;;
--elixir) opt_elixir=1 ;;
--fonts) opt_fonts=1 ;;
--wsl-gpg) opt_wsl_gpg=1 ;;
--wsl-ssh) opt_wsl_ssh=1 ;;
# asdf
--no-asdf) opt_asdf=0 ;;
--asdf) continue ;;
# zsh
--no-zsh) opt_zsh=0 ;;
--zsh) continue ;;
--* | -*)
alert "Error: Unknown option ${opt}"
help
die
;;
esac
done
}
# ---------------- END: Options ---------------- #
function validate_installed_git {
command -v git >/dev/null 2>&1 || alert_die "git is not installed."
}
function validate_installed_sudo {
command -v sudo >/dev/null 2>&1 || alert_die "sudo is not installed."
}
function validate {
validate_installed_git
validate_installed_sudo
}
function install {
mkdir -p "${tmp}"
may_update_package_list
may_install_deps_packages
may_install_zsh
may_install_asdf
install_asdf_versions
may_setup_docker_plugins
may_setup_elixir_plugins
may_install_fonts
may_setup_wsl_gpg
may_setup_wsl_ssh
success "✓ Install done! Run 'zsh' to start."
may_warn_wsl_setup
}
function may_warn_wsl_setup {
if [[ ${opt_wsl_gpg} -eq 1 || ${opt_wsl_ssh} -eq 1 ]]; then
warning "Checklist for WSL setup: https://github.com/aifrak/dotfiles#checklist-for-wsl-setup"
fi
}
function clean_tmp {
[[ -d "${tmp}" ]] && rm -r -d "${tmp}"
}
parse_options "${@}"
validate "${@}"
current_dir="$(dirname "$(readlink -f "${0}")")"
config_dir=${current_dir}/config
tmp=${HOME}/tmp/dotfiles
export ASDF_DIR=${HOME}/.asdf
export PATH="${PATH}:${ASDF_DIR}/bin:${ASDF_DIR}/shims"
dot_bashrc=${HOME}/.bashrc
dot_zshrc=${HOME}/.zshrc
trap "clean_tmp" EXIT
install "${@}"