-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
install
executable file
·635 lines (551 loc) · 17.6 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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
#!/usr/bin/env bash
# CI handling
CI=${CI:-False}
if [[ -n ${CI} ]]; then
sudo() {
"$@"
}
fi
BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WHOAMI="$(whoami)"
log_info() {
local icon
icon="[ ]${2:-""}"
printf "\\r \\033[00;20m${icon} %s\\n" "${1}"
}
log_notice() {
local icon
icon="[ ]${2:-""}"
printf "\\r \\033[00;20m${icon} %s\\n" "${1}"
}
log_warning() {
local icon
icon="[ ]${2:-""}"
printf "\\r \\033[00;20m${icon} %s\\n" "${1}"
}
log_done() {
local icon
icon="[ ]${2-""}"
printf "\\r \\033[00;20m${icon} %s\\n" "${1}"
}
log_die() {
local icon
icon="${2-""}[ 😱 ]"
printf "\\r \\033[00;20m${icon} %s\\n" "${1}"
exit "${3:-1}"
}
install_links() {
"${BASEDIR}/dotbot/bin/dotbot" -q -d "${BASEDIR}" -c "${BASEDIR}/install.conf.yaml"
}
install_packages() {
local icon
icon="[ Y ]"
log_notice "Installing prerequisites" "${icon}"
sudo pacman -Syq --needed --noconfirm base-devel git
_install_yay
log_notice "Preliminary upgrade" "${icon}"
yay -Syy
log_notice "Installing base packages" "${icon}"
yay -Syq --needed --noconfirm --quiet --combinedupgrade --batchinstall \
curl \
lsb-release \
ruby \
wget \
zsh
log_notice "Installing *env dependencies" "${icon}"
yay -Syq --needed --noconfirm --quiet --combinedupgrade --batchinstall \
ccache \
make \
openssl \
zlib
log_notice "Installing development" "${icon}"
yay -Syq --needed --noconfirm --quiet --combinedupgrade --batchinstall \
ctags \
neovim \
git \
git-lfs \
git-extras \
meld \
maven \
prettier \
shellcheck \
shfmt \
the_silver_searcher \
subversion \
yamllint \
stylua-bin \
jq \
yq \
xfce4-terminal
log_notice "Installing utilities" "${icon}"
yay -Syq --needed --noconfirm --combinedupgrade --batchinstall \
aria2 \
cron \
gnupg \
htop \
vtop \
python-wal-vtop \
httpie \
lnav \
nvtop \
preload \
ranger \
screenfetch \
tlp-rdw \
tree \
zathura \
zathura-pdf-mupdf \
xclip \
ueberzug && {
for srv in tlp cron; do
sudo systemctl enable --now "${srv}"
sudo systemctl start "${srv}"
done
}
log_notice "Installing browsers" "${icon}"
yay -Syq --needed --noconfirm --combinedupgrade --batchinstall \
brave-bin \
firefox \
google-chrome-dev
log_notice "Installing IDEs" "${icon}"
yay -Syq --needed --noconfirm --combinedupgrade --batchinstall \
intellij-idea-community-edition \
pycharm-community-edition
log_notice "Installing virtualization" "${icon}"
yay -Syq --needed --noconfirm --combinedupgrade --batchinstall \
docker \
docker-compose \
ctop \
fuse-overlayfs \
hadolint-bin \
virtualbox && {
docker_conf=$(mktemp)
cat >>"${docker_conf}" <<EOF
kernel.unprivileged_userns_clone = 1
EOF
sudo mv -f "${docker_conf}" /etc/sysctl.d/docker.conf &&
sudo sysctl --system | grep -o kernel.unprivileged_userns_clone &&
sudo usermod -aG docker "${WHOAMI}" &&
sudo systemctl enable --now docker &&
sudo systemctl start docker
}
log_notice "Installing GUI" "${icon}"
yay -Syq --needed --noconfirm --combinedupgrade --batchinstall \
i3-gaps \
i3status \
i3lock \
feh \
rofi \
dunst \
python-pywal \
polybar \
polybar-spotify-module \
picom && {
systemctl --user enable spotify-listener
systemctl --user start spotify-listener
}
log_notice "Installing themes & fonts" "${icon}"
yay -Syq --needed --noconfirm --combinedupgrade --batchinstall \
ttf-iosevka \
ttf-font-awesome \
ttf-material-design-icons \
ant-dracula-gtk-theme
log_notice "Installing " "${icon}"
yay -Syq --needed --noconfirm --combinedupgrade --batchinstall \
bluez \
bluez-utils \
blueman && {
sudo systemctl enable bluetooth.service
sudo systemctl start bluetooth.service
}
log_notice "Installing multimedia" "${icon}"
yay -Syq --needed --noconfirm --combinedupgrade --batchinstall \
spotify \
avizo \
pulseaudio-alsa \
pulseaudio-bluetooth
lspci -k | grep -qe "NVIDIA" && {
log_notice "Installing NVIDIA" "${icon}"
yay -Sq --needed --noconfirm nvidia
}
log_notice "Installing " "${icon}"
yay -Syq --needed --noconfirm --combinedupgrade --batchinstall \
slack \
zoom
log_notice "Removing things I do not need" "${icon}"
_remove_redundant_packages
}
_yay_clean() {
yay -Sqy
yay -Rsn --noconfirm "$(yay -Qdtq)" 2>/dev/null || true # remove unneeded dependencies
yay --afterclean --removemake --save
}
_remove_redundant_packages() {
yay -Rs --noconfirm \
nano \
termite \
alacritty \
xterm \
terminator \
nitrogen \
xterm || true
_yay_clean
}
_install_yay() {
command -v yay >/dev/null || {
rm -rf /tmp/yay || true
git clone https://aur.archlinux.org/yay.git --depth 1 /tmp/yay
pushd /tmp/yay || exit
makepkg -si
popd || exit
} && log_notice "Yay is already installed" "[ ]"
}
post_install() {
gem install \
sqlint \
neovim \
2>/dev/null 1>/dev/null
gem environment
wal --theme base16-atelier-dune -n --vte
wal-vtop >/dev/null
}
_env_binary() {
# fetches path to binary of given *env
# nodenv, jenv etc etc etc
local env
env="${1}"
if ! command -v "${env}" >/dev/null 2>&1; then
env_bin="${HOME}/.${env}/bin/${env}"
else
env_bin=$(command -v "${env}")
fi
echo "${env_bin}"
}
configure_envs() {
local pyenv
local pyenv_root
local nodenv
local nodenv_root
local goenv
local goenv_root
local python_icon="[ ]"
local neovim_icon="[ ]${python_icon}"
goenv=$(_env_binary "goenv")
goenv_root=$($goenv root)
pyenv=$(_env_binary "pyenv")
pyenv_root=$($pyenv root)
nodenv=$(_env_binary "nodenv")
nodenv_root=$($nodenv root)
jenv=$(_env_binary "jenv")
jenv_root=$($jenv root)
if [ ! -f "${pyenv_root}/version" ]; then
log_notice "Installing latest Python" "${python_icon}"
for py_major in {2,3}; do
$pyenv latest install -s "${py_major}"
"${pyenv_root}/versions/$($pyenv latest --print-installed "${py_major}")/bin/pip" install --upgrade pip
"${pyenv_root}/versions/$($pyenv latest --print-installed "${py_major}")/bin/pip" install \
-r "${BASEDIR}/requirements/system.txt" \
-r "${BASEDIR}/requirements/utils.txt"
log_done "Installed Python ${py_major}" "${python_icon}"
done
$pyenv global "$($pyenv latest --print-installed)"
else
log_done "Python -> $(cat "${pyenv_root}/version")"
fi
for py_major in {2,3}; do
if [ ! -d "${pyenv_root}/versions/neovim${py_major}" ]; then
log_notice "Initializing neovim setup for Python ${py_major}" "${neovim_icon}"
$pyenv virtualenv "$($pyenv latest --print "${py_major}")" "neovim${py_major}"
"${pyenv_root}/versions/neovim${py_major}/bin/pip" install --upgrade pip
"${pyenv_root}/versions/neovim${py_major}/bin/pip" install -r "${BASEDIR}/requirements/neovim.txt"
else
local neovim_py_version
neovim_py_version="$(
"${pyenv_root}/versions/neovim${py_major}/bin/python" \
--version \
2>&1 |
awk '{print $2}'
)"
log_done "neovim${py_major} -> ${neovim_py_version}" "${neovim_icon}"
fi
done
if [ ! -f "${nodenv_root}/version" ]; then
echo "Installing latest Node"
$nodenv latest install -s 14
$nodenv global "$($nodenv latest --print-installed)"
"${nodenv_root}/versions/$($nodenv latest --print-installed)/bin/npm" install --global --production "${BASEDIR}/package.json"
else
log_done "Node -> $(cat "${nodenv_root}/version")" "[ ]"
fi
if [ ! -f "${goenv_root}/version" ]; then
echo "Installing latest GO"
$goenv latest install -s 1 &&
$goenv global "$($goenv latest --print-installed)"
go="${goenv_root}/versions/$($goenv latest --print-installed)/bin/go"
$go get -u \
golang.org/x/lint/golint \
golang.org/x/tools/gopls \
github.com/golangci/golangci-lint/cmd/golangci-lint \
github.com/stamblerre/gocode \
github.com/cpuguy83/go-md2man
command -v shfmt >/dev/null || GO111MODULE=on $go get mvdan.cc/sh/v3/cmd/shfmt
else
log_done "Go -> $(cat "${goenv_root}/version")" "[ ]"
fi
if [ ! -d "${jenv_root}/_versions/" ]; then
mkdir "${jenv_root}/_versions/"
fi
if [ ! -f "${jenv_root}/version" ]; then
echo "Installing latest Java"
local javaVersion
local downloadUrl
local archiveName
local jdkVersion
local releaseType
javaVersion="$(http https://api.adoptopenjdk.net/v3/info/available_releases | jq -r '.most_recent_feature_release')"
releaseType="ga"
downloadUrl=$(
http \
"https://api.adoptopenjdk.net/v3/assets/feature_releases/${javaVersion}/${releaseType}" \
architecture==x64 \
sort_method==DATE \
sort_order==DESC \
image_type==jdk \
jvw_impl==hotspot \
os==linux \
project==jdk \
vendor==adoptopenjdk |
jq -r '.[0]["binaries"][0]["package"]["link"]'
)
archiveName=$(echo "${downloadUrl}" | awk -F "/" '{print $NF}')
if [ ! -f "/tmp/${archiveName}" ]; then
aria2c \
-d "/tmp" \
-o "${archiveName}" \
-j 5 \
"${downloadUrl}"
fi
jdkVersion=$(tar -tf "/tmp/${archiveName}" | head -n 1 | sed -e 's|/||gi')
tar -xzf "/tmp/${archiveName}" -C "${jenv_root}/_versions/" && {
$jenv add "${jenv_root}/_versions/${jdkVersion}"
$jenv global "$($jenv versions | grep "${javaVersion}" | head -n 1 | awk -F' ' '{print $1}')"
}
if command -v java >/dev/null 2>&1; then
echo "Enabling default java"
local default_java_home
default_java_home=$(update-alternatives --query java | grep Best | awk '{print $2}' | sed -e 's|bin/java||g')
if [ -d "${default_java_home}" ]; then
$jenv add "${default_java_home}"
fi
fi
$jenv enable-plugin export >/dev/null
$jenv enable-plugin maven >/dev/null
else
log_done "Java -> $(cat "${jenv_root}/version")" "[ ]"
fi
$nodenv package-hooks install --all
$pyenv rehash
$nodenv rehash
$goenv rehash
$jenv rehash
}
configure_nvim() {
local goenv pyenv nodenv jenv new_path old_path
goenv=$(_env_binary "goenv")
pyenv=$(_env_binary "pyenv")
nodenv=$(_env_binary "nodenv")
jenv=$(_env_binary "jenv")
old_path="${PATH}"
new_path="${PATH}:$($goenv root)/shims:$($pyenv root)/shims:$($nodenv root)/shims:$($jenv root)/shims"
export PATH="${new_path}"
nvim --headless +PlugInstall +qall!
nvim --headless +UpdateRemotePlugins +qall!
export PATH="${old_path}"
unset goenv
unset pyenv
unset nodenv
unset jenv
unset new_path
}
configure_wakatime() {
local wakatime_api_key=""
local wakatime_hostname=""
local icon="[ ]"
wakatime_hostname="$(hostname)"
if [ ! -f "${HOME}/.wakatime.cfg" ]; then
log_notice "Configuring Wakatime" "${icon}"
while [[ $# -gt 0 ]]; do
arg="${1}"
case "${arg}" in
--wakatime-api-key)
wakatime_api_key="${2}"
shift
shift
;;
--wakatime-hostname)
wakatime_hostname="${2}"
shift
shift
;;
esac
done
if [ -z "${wakatime_api_key}" ]; then
log_die "--wakatime-api-key required..." "${icon}"
else
install -m 666 "${BASEDIR}/wakatime.cfg" "${HOME}/.wakatime.cfg"
sed -e "
s|%API_KEY%|${wakatime_api_key}|g;
s|%HOSTNAME%|${wakatime_hostname}|g;
" -i "${HOME}/.wakatime.cfg"
log_done "Wakatime configured" "${icon}"
fi
else
log_done "Wakatime configured" "${icon}"
fi
}
configure_git() {
local git_username=""
local git_password=""
local git_email=""
local gpg_full_name=""
local gpg_passphrase=""
local force="no"
local reconfiguring
local icon="[ ]"
local ssh_keyname="github"
while [[ $# -gt 0 ]]; do
arg="${1}"
case "${arg}" in
--git-username)
git_username="${2}"
shift
shift
;;
--git-password)
git_password="${2}"
shift
shift
;;
--git-email)
git_email="${2}"
shift
shift
;;
--gpg-fullname)
gpg_full_name="${2}"
shift
shift
;;
--gpg-passphrase)
gpg_passphrase="${2}"
shift
shift
;;
--force)
force="yes"
shift
shift
;;
*)
# whatever
shift
shift
;;
esac
done
[ "${force}" == "yes" ] && {
rm -rf "${HOME}/.gitconfig.local"
find "${HOME}/.ssh/" -name "${ssh_keyname}*" -exec rm -rf {} \;
reconfiguring="yes"
}
chown -R "$(whoami)" ~/.gnupg/
find ~/.gnupg -type f -exec chmod 600 {} \;
find ~/.gnupg -type d -exec chmod 700 {} \;
if [ ! -f "${HOME}/.gitconfig.local" ]; then
[ "${reconfiguring}" != "yes" ] && log_info "Git profile not yet configured" "${icon}"
if [ -z "${git_username}" ]; then
log_die "--username must be set" "${icon}" 3
fi
if [ -z "${git_password}" ]; then
log_die "--password must be set" "${icon}" 3
fi
if [ -z "${git_email}" ]; then
log_die "--email must be set" "${icon}" 3
fi
if [ -z "${gpg_full_name}" ]; then
log_die "--gpg-fullname must be set" "${icon}" 3
fi
if [ -z "${gpg_passphrase}" ]; then
log_die "--gpg-passphrase must be set" "${icon}" 3
fi
# 1. generate ssh key
gen_ssh_key "${ssh_keyname}" "${git_password}" "${git_username}@$(hostname)"
log_done ".ssh/${ssh_keyname} configured" "${icon}"
key_type="rsa"
key_strength=4096
key_valid_for_years=1
expire_date="$(date +"%Y-%m-%d" -d"+${key_valid_for_years} year")"
key_config=$(mktemp)
# 2. generating GPK key to sign the commits
cat >>"${key_config}" <<EOF
Key-Type: ${key_type}
Key-Length: ${key_strength}
Name-Real: ${gpg_full_name}
Name-Comment: ${git_username} GPG key generated with dotfiles [${expire_date}]
Name-Email: ${git_email}
Expire-Date: ${expire_date}
Passphrase: ${gpg_passphrase}
EOF
gpg2 --quiet --no-verbose --batch --expert --full-gen-key "${key_config}"
rm -rf "${key_config}"
# assumed the highest rsa length:
local signingKey=""
signingKey=$(
gpg2 \
--quiet --no-verbose --list-secret-keys --keyid-format LONG |
grep -B 2 "${git_email}" |
grep sec |
awk -F"[/ ]+" '{print $3}'
)
log_done "GPG key ${signingKey} generated" "${icon}"
touch "${HOME}/.gitconfig.local"
(
git config --file="${HOME}/.gitconfig.local" user.name "${git_username}"
git config --file="${HOME}/.gitconfig.local" user.email "${git_email}"
git config --file="${HOME}/.gitconfig.local" user.signingKey "${signingKey}"
git config --file="${HOME}/.gitconfig.local" gpg.program gpg2
git config --file="${HOME}/.gitconfig.local" commit.gpgsign true
git config --file="${HOME}/.gitconfig.local" github.user "${git_username}"
)
log_done "Git profile configured" "${icon}"
log_notice "Remember to upload the GPG and SSH keys to Github" "${icon}"
else
log_done "Git already configured" "${icon}"
fi
}
gen_ssh_key() {
local name="${1}"
local password="${2}"
local comment="${3}"
local type="${4:-ed25519}"
ssh-keygen \
-t "${type}" \
-b 4096 \
-C "${comment}" \
-f "${HOME}/.ssh/${name}" \
-N "${password}" \
-q
}
if ((SHLVL > 1)); then
echo "kornicameister/dotfiles"
if ((EUID == 0)) && [[ -z ${CI:-} ]]; then
log_die "Altough root is required to install packages, ./install must not be launched as root" "${icon}" 3
fi
install_packages && post_install
install_links
configure_envs
configure_git "$@"
configure_nvim
configure_wakatime "$@"
screenfetch
fi