-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvin
executable file
·919 lines (761 loc) · 34.1 KB
/
envin
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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
#!/bin/bash
# shellcheck disable=SC2015,SC2016
# ────────────────────────────────────────────────────────────────────────────────
# Config
ENVIN_HTTPS_REPOSITORY="https://github.com/Nephylhim/EnvIn.git"
ENVIN_SSH_REPOSITORY="[email protected]:Nephylhim/EnvIn.git"
ENVIN_DEFAULT_PATH="$HOME/.envin"
DOTFILES_REPOSITORY="Nephylhim/dotfiles"
DOTFILES_SSH_REPOSITORY="[email protected]:Nephylhim/dotfiles.git"
SOFT_INSTALL_DIR="$HOME/opt"
ZSH=${ZSH:-/home/thomas/.oh-my-zsh}
# ────────────────────────────────────────────────────────────────────────────────
# Init / standard utils
set -eo pipefail
PATH=$PATH:/sbin:/usr/sbin:$HOME/go/bin:/usr/local/go/bin:$HOME/gittools:$HOME/bin:$HOME/.cargo/bin:$HOME/.local/bin
RED=$'\e[01;31m'
GREEN=$'\e[1;32m'
BLUE=$'\e[1;34m'
YELLOW=$'\e[33m'
NC=$'\e[0m'
BOLD="$(tput bold)"
NORM="$(tput sgr0)"
shell_dir="$(dirname "${BASH_SOURCE[0]}")" # relative path
cd "$shell_dir" &>/dev/null
shell_dir="$(pwd)"
cd - &>/dev/null
red() { echo -ne "${RED}$*${NC}"; }
green() { echo -ne "${GREEN}$*${NC}"; }
blue() { echo -ne "${BLUE}$*${NC}"; }
yellow() { echo -ne "${YELLOW}$*${NC}"; }
linfo() { echo -e "[$(blue INFO)] $*"; }
lfail() { echo -e "[$(red FAIL)] $*"; }
lok() { echo -e "[$(green " OK ")] $*"; }
ldebug() {
if $debug; then
echo -e "[$(yellow DEBU)] $(yellow "$*")"
fi
}
# ────────────────────────────────────────────────────────────────────────────────
# Utils functions
cmdExists() {
command -v "$1" >/dev/null 2>&1
return $?
}
verifyDebPkgInstalled() {
pkg=$1
dpkg -l "$pkg" &>/dev/null
return $?
}
fileExists() {
if [[ -f $1 ]]; then
return 0
else
return 1
fi
}
dirExists() {
if [[ -d $1 ]]; then
return 0
else
return 1
fi
}
listCfgValues() {
arrayName=$1
filename=$2
unset values
declare -n values="$arrayName"
while IFS='' read -r line || [[ -n "$line" ]]; do
if grep -qP '^(?:#|\/\/)' <<<"$line"; then
continue
fi
# shellcheck disable=SC2001
value=$(perl -pe 's/^(.*?) *(?:#.*)?$/\1/gm' <<<"$line")
if [[ $value == "" ]]; then
continue
fi
values+=("$value")
done <"$filename"
}
verify_admin() {
# sudo group line in /etc/group
sudoGrp=$(grep '^sudo:' </etc/group)
# verify that the user is present in the sudo group line
if ! grep -Eq "${USER}[,\n]" <<<"$sudoGrp\n"; then
linfo "User $USER is not sudoer, adding it to sudoers using 'su' command. You'll have to enter root password"
su -c "echo '$USER ALL=(ALL) ALL' >> /etc/sudoers"
sudo usermod -aG sudo "$USER" # This doesn't work as is, as the user would need to log out before being able to use sudo. This method is more clean and so the user is added to the group. However the user is also temporarily added in the sudoer file in order to continue the script
lok "User $USER added to sudoers"
fi
linfo "Verifying user can sudo. You may have to enter your sudo password"
if sudo true; then
lok "User is sudoer"
else
lfail "User is not sudoer. This script must use sudo to work properly"
exit 1
fi
}
sudoer_file_remove_user() {
sudo sed -Ei "/^${USER}[\t ]+ALL/d" '/etc/sudoers'
}
update_system() {
sudo apt update
sudo apt upgrade
}
ensureDebPkg() {
# cmd=$1
# if [[ $2 != "" ]]; then
# pkg=$2
# else
# pkg=$1
# fi
pkg=$1
ldebug "Verifying pkg $pkg is installed"
# ldebug "Package name: $pkg"
if verifyDebPkgInstalled "$pkg"; then
lok "$(yellow "$pkg") installed"
else
ldebug "Package not installed, installing it"
installPkg "$pkg"
fi
}
listCargoBins() {
if [[ $cargoBinsList == "" ]]; then
cargoBinsList=$(cargo install --list | grep '^[^ ]' | cut -f1 -d' ')
fi
echo "$cargoBinsList"
}
# verifyCargoCmd() {
# cmd=$1
# if [[ $2 != "" ]]; then
# crate=("${@:2}")
# else
# crate=("$1")
# fi
# ldebug "Verifying cmd $cmd is installed"
# ldebug "Crate name: ${crate[*]}"
# if cmdExists "$cmd"; then
# lok "${YELLOW}$cmd${NC} installed"
# else
# ldebug "Command not installed, installing it"
# cargoInstall "${crate[@]}"
# fi
# }
verifyCargoBin() {
crateName=$1
if [[ $2 != "" ]]; then
crate=("${@:2}")
else
crate=("$1")
fi
ldebug "Verifying crate $crateName is installed"
ldebug "full crate: ${crate[*]}"
cargoBins=$(listCargoBins)
if grep -Pq "^${crateName}\$" <<<"$cargoBins"; then
lok "${YELLOW}$crateName${NC} installed"
else
ldebug "Command not installed, installing it"
cargoInstall "${crate[@]}"
fi
}
installPkg() {
linfo "${YELLOW}$*${NC} not installed. Installing..."
sudo apt install -y "$@"
lok "Installation successful: ${YELLOW}$*${NC}"
}
cargoInstall() {
linfo "${YELLOW}$*${NC} not installed. Installing..."
cargo install "$@"
lok "Installation successful: ${YELLOW}$*${NC}"
}
ensureDconfValue() {
local reg=$1
local expected=$2
local val
val=$(dconf read "$reg")
if [[ "$val" == "$expected" ]]; then
lok "dconf reg correctly setup $reg"
else
linfo "dconf reg $reg not correctly setup. changing value"
dconf write "$reg" "$expected"
val=$(dconf read "$reg")
if [[ "$val" == "$expected" ]]; then
lok "dconf reg correctly setup $reg"
else
lfail "dconf reg not correctly setup. $reg shoud be $expected (got $val)"
return 1
fi
fi
}
ensureDconfDirValues() {
local dir=$1
local expectedResults=("${@:2}")
# echo ""
# echo "*: $*"
# echo "dconf dir: $dir"
# echo "dconf expected results: ${expectedResults[*]}"
local dve
for dve in "${expectedResults[@]}"; do
dvar=$(cut -d':' -f1 <<<"$dve")
expected=$(cut -d':' -f2 <<<"$dve")
# echo "should be: $dvar -> $expected"
ensureDconfValue "${dir}${dvar}" "$expected"
done
}
printNInstall() {
name=$1
cmd=$2
linfo "$name not installed. Installing..."
eval "$cmd"
lok "Installation successful: $name"
}
ensureGitRepositoryPresent() {
remote=$1
path=$2
basePath=$(dirname "$path")
name=${3:-$(basename "$path")}
pushRemote=${4:-$remote}
if test -d "$path"; then
lok "$(yellow "$name") already exists"
return
else
linfo "$(yellow "$name") does not exist yet. Installing..."
fi
if ! test -d "$basePath"; then
linfo "Parent directory $(yellow "$basePath") doesn't exist yet, creating it..."
mkdir -p "$basePath"
fi
linfo "Cloning $(yellow "$name")"
git clone --recurse-submodules -j8 "$remote" "$path"
if [[ "$pushRemote" != "$remote" ]]; then
linfo "Setting remote push URL to $(yellow "$pushRemote")"
cd "$path"
git remote set-url origin "$pushRemote" --push
fi
cd "$shell_dir" &>/dev/null
lok "$(yellow "$name") set up"
}
extract() {
if [ -f "$1" ]; then
case $1 in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
# ────────────────────────────────────────────────────────────────────────────────
# Controllers
ensurePackages() {
lines=()
listCfgValues lines 'packages.cfg'
for line in "${lines[@]}"; do
name=$(cut -d: -f1 <<<"$line")
package=$(cut -d: -f2 <<<"$line")
ensureDebPkg "$name" "$package"
done
}
ensureCargoBins() {
lines=()
listCfgValues lines 'cargo_bins.cfg'
for line in "${lines[@]}"; do
crateName=$(cut -d: -f1 <<<"$line")
# shellcheck disable=SC2178
fullCrate=$(cut -d: -f2- <<<"$line")
# shellcheck disable=SC2086,SC2128
verifyCargoBin "$crateName" $fullCrate
done
}
isInGitRepo() {
ldebug "Shell dir: $shell_dir"
if [ ! -d .git ]; then
ldebug "Script not in git dir"
return 0
fi
remoteURL=$(git config --get remote.origin.url)
if [[ $remoteURL != "$ENVIN_HTTPS_REPOSITORY" && $remoteURL != "$ENVIN_SSH_REPOSITORY" ]]; then
ldebug "Script not in git dir"
return 0
fi
ldebug "Script is in git dir"
return 1
}
ensureSelfInGitRepository() {
if ! isInGitRepo; then
lok "Script executed in repository. Continuing"
return 0
fi
linfo "Not in git repository. Retrieving it to have resources"
ldebug "to path: $EnvInDirPath"
git clone --recurse-submodule "$ENVIN_HTTPS_REPOSITORY" "$EnvInDirPath"
cd "$EnvInDirPath"
linfo "Setting push url to SSH URL"
git remote set-url origin "$ENVIN_SSH_REPOSITORY" --push
linfo "Relaunching EnvIn in git directory"
bash -c "$EnvInDirPath/envin"
# EnvIn runned in git repository, this instance can now exit without error
exit 0
}
installOhMyZSH() {
linfo "Oh My Zsh not installed. Installing..."
export RUNZSH='no'
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
lok "Installation successful: Oh My Zsh"
}
installCargo() {
linfo "cargo not installed. Installing rust env..."
curl https://sh.rustup.rs -sSf | sh -s -- -y
lok "Installation successful: rust env"
}
installStarship() {
linfo "starship not installed. Installing starship..."
curl -fsSL https://starship.rs/install.sh | sh -s -- -f
lok "Installation successful: starship"
}
setupDotfiles() {
linfo "Retrieving dotfiles repository..."
dot init "$DOTFILES_REPOSITORY"
cd "$HOME/.dotfiles"
linfo "Setting push url to SSH URL..."
git remote set-url origin "$DOTFILES_SSH_REPOSITORY" --push
linfo "Ensuring submodule presence..."
git submodule update --init # ensure that we retrieve submodule as well
cd "$shell_dir" &>/dev/null
lok "Dotfiles repository retrieved"
}
linkDotfiles() {
linfo "Linking dotfiles"
dot link
lok "Dotfiles linked"
}
installDSMNerdFont() {
linfo "Installing DroidSansMono Nerd font..."
mkdir -p "$HOME/.local/share/fonts"
cd "$HOME/.local/share/fonts"
curl -Lo "Droid Sans Mono for Powerline Nerd Font Complete.otf" https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DroidSansMono/complete/Droid%20Sans%20Mono%20Nerd%20Font%20Complete.otf
cd "$shell_dir" &>/dev/null
lok "Installation successful: DroidSansMono Nerd font"
}
ensureTilixConfiguration() {
dt='/com/gexperts/Tilix/'
dtv=("terminal-title-style:'small'" "use-tabs:true" "theme-variant:'dark'" "control-scroll-zoom:true" "new-instance-mode:'new-session'" "window-style:'disable-csd-hide-toolbar'")
dtk="${dt}keybindings/"
# dtkv=("app-shortcuts:'F1'" "app-preferences:'<Primary><Shift>Escape'" "win-switch-to-previous-session:['<Primary><Shift>Tab', '<Primary>Page_Up']" "win-switch-to-next-session:['<Primary>Tab', '<Primary>Page_Down']" "session-switch-to-previous-terminal:''" "session-switch-to-next-terminal:''")
# dtkv=("app-shortcuts:'F1'" "session-name:'F2'" "app-preferences:'<Primary><Shift>Escape'")
# dtkv=("app-shortcuts:'F1'" "session-name:'F2'" "win-switch-to-previous-session:['<Primary><Shift>Tab', '<Primary>Page_Up']" "app-preferences:'<Primary><Shift>Escape'" "win-switch-to-next-session:['<Primary>Tab', '<Primary>Page_Down']" "session-switch-to-previous-terminal:'disabled'" "session-switch-to-next-terminal:'disabled'")
dtkv=("app-shortcuts:'F1'" "session-name:'F2'" "win-switch-to-previous-session:'<Primary>Page_Up'" "app-preferences:'<Primary><Shift>Escape'" "win-switch-to-next-session:'<Primary>Page_Down'" "session-switch-to-previous-terminal:'disabled'" "session-switch-to-next-terminal:'disabled'" "session-switch-to-terminal-0:'disabled'" "session-switch-to-terminal-1:'disabled'" "session-switch-to-terminal-2:'disabled'" "session-switch-to-terminal-3:'disabled'" "session-switch-to-terminal-4:'disabled'" "session-switch-to-terminal-5:'disabled'" "session-switch-to-terminal-6:'disabled'" "session-switch-to-terminal-7:'disabled'" "session-switch-to-terminal-8:'disabled'" "session-switch-to-terminal-9:'disabled'")
dtpid=$(dconf list ${dt}profiles/ | head -n1)
dtp="${dt}profiles/$dtpid"
# dtpv=("background-color:'#2E2E34343636'" "palette:['#2E2E34343636', '#CCCC00000000', '#4E4E9A9A0606', '#C4C4A0A00000', '#34346565A4A4', '#ADAD4040DFDF', '#060698209A9A', '#D3D3D7D7CFCF', '#555557575353', '#EFEF29292929', '#8A8AE2E23434', '#FCFCE9E94F4F', '#72729F9FCFCF', '#ADAD7F7FA8A8', '#3434E2E2E2E2', '#EEEEEEEEECEC']" "use-theme-colors:false" "cursor-shape:'ibeam'" "text-blink-mode:'unfocused'" "use-system-font:false" "font:'DroidSansMono Nerd Font Mono 12'")
dtpv=("foreground-color:'#F3F3F3F3F3F3'" "text-blink-mode:'unfocused'" "visible-name:'Default'" "palette:['#252525', '#FF5252', '#C3D82C', '#FFC135', '#42A5F5', '#D81B60', '#00ACC1', '#F5F5F5', '#708284', '#FF5252', '#C3D82C', '#FFC135', '#42A5F5', '#D81B60', '#00ACC1', '#F5F5F5']" "badge-color-set:false" "cursor-background-color:'#EFEF29292929'" "cursor-shape:'ibeam'" "cursor-colors-set:true" "highlight-colors-set:false" "use-system-font:false" "bold-color-set:false" "font:'DroidSansMono Nerd Font 10'" "use-theme-colors:false" "highlight-background-color:'#72729F9FCFCF'" "background-color:'#263238'" "background-transparency-percent:0" "dim-transparency-percent:0")
ensureDconfDirValues "$dt" "${dtv[@]}"
ensureDconfDirValues "$dtk" "${dtkv[@]}"
ensureDconfDirValues "$dtp" "${dtpv[@]}"
}
cleanDefaultMediaKeybindings() {
linfo "cleaning default media keybindings..."
for i in {1..9}; do
v="$(gsettings get org.gnome.shell.keybindings "switch-to-application-$i")"
if [[ $v != '@as []' ]]; then
linfo "removing default keybinding for switch-to-application-$i"
gsettings set org.gnome.shell.keybindings "switch-to-application-$i" '[]'
lok "keybinding for switch-to-application-$i removed"
else
lok "keybinding for switch-to-application-$i already removed"
fi
done
lok "default media keybindings cleaned up"
}
ensureGnomeConfiguration() {
# keyboard layouts
inputsourcesPath='/org/gnome/desktop/input-sources/'
inputsourcesValues=("sources:[('xkb', 'us+intl'), ('xkb', 'fr')]" "mru-sources:[('xkb', 'us+intl'), ('xkb', 'fr')]" "xkb-options:@as []")
ensureDconfDirValues "$inputsourcesPath" "${inputsourcesValues[@]}"
# touchpad
touchpadPath='/org/gnome/desktop/peripherals/touchpad/'
touchpadValues=("natural-scroll:false" "tap-to-click:true")
ensureDconfDirValues "$touchpadPath" "${touchpadValues[@]}"
# mouse
mousePath='/org/gnome/desktop/peripherals/mouse/'
mouseValues=("natural-scroll:false" "accel-profile:'flat'")
ensureDconfDirValues "$mousePath" "${mouseValues[@]}"
# keybindings
keybindingsPath='/org/gnome/desktop/wm/keybindings/'
keybindingsValues=("move-to-workspace-up:['<Shift><Super>Up']" "move-to-workspace-1:['<Shift><Super>exclam']" "move-to-workspace-2:['<Shift><Super>at']" "move-to-workspace-3:['<Shift><Super>numbersign']" "move-to-workspace-4:['<Shift><Super>dollar']" "move-to-workspace-5:['<Shift><Super>percent']" "move-to-workspace-6:['<Shift><Super>dead_circumflex']" "move-to-workspace-7:['<Shift><Super>ampersand']" "move-to-workspace-8:['<Shift><Super>asterisk']" "move-to-workspace-9:['<Shift><Super>parenright']" "switch-to-workspace-1:['<Super>1']" "switch-to-workspace-2:['<Super>2']" "switch-to-workspace-3:['<Super>3']" "switch-to-workspace-4:['<Super>4']" "switch-to-workspace-5:['<Super>5']" "switch-to-workspace-6:['<Super>6']" "switch-to-workspace-7:['<Super>7']" "switch-to-workspace-8:['<Super>8']" "switch-to-workspace-9:['<Super>9']" "switch-to-workspace-down:['<Primary><Super>Down', '<Super>Page_Down']" "move-to-monitor-down:@as []" "move-to-workspace-down:['<Shift><Super>Down']" "toggle-on-all-workspaces:['<Super>Return']" "move-to-monitor-up:@as []" "switch-to-workspace-up:['<Primary><Super>Up', '<Super>Page_Up']")
ensureDconfDirValues "$keybindingsPath" "${keybindingsValues[@]}"
# keyboard conf
keyboardPath='/org/gnome/settings-daemon/peripherals/keyboard/'
keyboardValues=("numlock-state:'on'")
ensureDconfDirValues "$keyboardPath" "${keyboardValues[@]}"
# custom keybindings
mediakeysPath='/org/gnome/settings-daemon/plugins/media-keys/'
mediakeysValues=("custom-keybindings:['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/']")
ensureDconfDirValues "$mediakeysPath" "${mediakeysValues[@]}"
custom0Path='/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/'
custom0Values=("binding:'<Super>t'" "command:'kitty'" "name:'kitty'")
ensureDconfDirValues "$custom0Path" "${custom0Values[@]}"
custom1Path='/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/'
custom1Values=("binding:'<Primary>escape'" "command:'tilix --quake'" "name:'tilix quake'")
ensureDconfDirValues "$custom1Path" "${custom1Values[@]}"
cleanDefaultMediaKeybindings
# TODO: extract custom commands in a separate file to make it more generic
}
installDesktopTheme() {
linfo "Installing Desktop theme..."
mkdir -p "$SOFT_INSTALL_DIR"
cd "$SOFT_INSTALL_DIR"
git clone https://github.com/vinceliuice/Matcha-gtk-theme.git
cd Matcha-gtk-theme
./install.sh
cd "$shell_dir" &>/dev/null
lok "Installation successful: Desktop theme"
}
installIconTheme() {
linfo "Installing icon theme..."
mkdir -p "$HOME/.local/share/icons"
cd "$HOME/.local/share/icons"
git clone https://github.com/zayronxio/Zafiro-icons.git
cd "$shell_dir" &>/dev/null
lok "Installation successful: icon theme"
}
ensureGnomeStyle() {
ensureDconfValue '/org/gnome/shell/extensions/user-theme/name' "'Matcha-dark-azul'"
# ensureDconfValue '/org/gnome/desktop/interface/gtk-theme' "'Matcha-dark-azul'"
# ensureDconfValue '/org/gnome/desktop/interface/icon-theme' "'Zafiro-icons'"
interfacePath='/org/gnome/desktop/interface/'
interfaceValues=("show-battery-percentage:true" "gtk-im-module:'gtk-im-context-simple'" "icon-theme:'Zafiro-icons'" "gtk-theme:'Matcha-dark-azul'")
ensureDconfDirValues "$interfacePath" "${interfaceValues[@]}"
ensureDconfValue '/org/gnome/desktop/calendar/show-weekdate' "true"
}
installVSCode() {
linfo "Installing VSCode..."
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor >packages.microsoft.gpg
sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt update
sudo apt install code -y
lok "Installation successful: VSCode"
}
ensureVSCodeExtensions() {
extensions="$(code --list-extensions)"
cfgExtensions=()
listCfgValues cfgExtensions 'vscode_extensions.cfg'
for extension in "${cfgExtensions[@]}"; do
if grep -iq "^${extension}$" <<<"$extensions"; then
lok "Extension ${YELLOW}$extension${NC} is already installed"
else
linfo "Installing ${YELLOW}$extension${NC}"
code --install-extension "$extension"
lok "Extension ${YELLOW}$extension${NC} installed"
fi
done
}
installCheatSh() {
linfo "Installing cht.sh..."
PATH_DIR="$HOME/bin" # or another directory on your $PATH
mkdir -p "$PATH_DIR"
curl https://cht.sh/:cht.sh >"$PATH_DIR/cht.sh"
chmod +x "$PATH_DIR/cht.sh"
lok "Installation successful: cht.sh"
}
installBrew() {
linfo "Installing Brew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
lok "Installation successful: Brew"
# brew analytics off # to disable anonymous analytics
}
installEtcher() {
linfo "Installing Etcher..."
curl -1sLf \
'https://dl.cloudsmith.io/public/balena/etcher/setup.deb.sh' |
sudo -E bash
sudo apt update
sudo apt install -y balena-etcher-electron
lok "Installation successful: Etcher"
}
ensureBrewFormulaes() {
formulaes="$(brew list -1)"
cfgFormulaes=()
listCfgValues cfgFormulaes 'brew_formulaes.cfg'
for line in "${cfgFormulaes[@]}"; do
formulae="$(cut -d: -f1 <<<"$line")"
options="$(cut -d: -f2 <<<"$line")"
if grep -q "^${formulae}$" <<<"$formulaes"; then
lok "Formulae ${YELLOW}$formulae${NC} is already installed"
else
linfo "Installing ${YELLOW}$formulae${NC}..."
brew install "$options" "$formulae"
lok "Formulae ${YELLOW}$formulae${NC} installed successfully"
fi
done
}
installGo() {
linfo "Installing Go..."
dlPath="$(curl -s "https://golang.org/dl/" |
grep -P '<a class="download downloadBox" href="([^"]+)">' |
grep "linux-amd64" |
sed -E 's|<a class="download downloadBox" href="([^"]+)">|\1|')"
url="https://golang.org${dlPath}"
linfo "Installing go using: $url"
tmpDir="$(mktemp -d)"
ldebug "tmpDir: $tmpDir"
cd "$tmpDir"
linfo "Downloading go archive..."
curl -LOJs "$url"
linfo "archive downloaded..."
archiveName="$(ls)"
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf "$archiveName"
cd "$shell_dir" &>/dev/null
rm -rf "$tmpDir"
lok "Go installed"
}
ensureGoPackages() {
gp="${GOPATH:-$HOME/go}/src"
goPackages=()
listCfgValues goPackages 'go_packages.cfg'
for package in "${goPackages[@]}"; do
pBase=$(cut -d' ' -f1 <<<"$package" | awk -F '/' '{print $1"/"$2"/"$3}')
if test -d "$gp/$pBase"; then
lok "Go package $pBase is already installed"
else
linfo "Installing $pBase"
#shellcheck disable=SC2086
go install $package@latest
lok "Go package $pBase installed successfully"
fi
done
}
ensureGnomeShellExtensions() {
extensions=()
listCfgValues extensions 'gnome_extensions.cfg'
workingDir="$(mktemp -d)"
linfo "Checking gnome extensions..."
for line in "${extensions[@]}"; do
extensionID="$(cut -d':' -f1 <<<"$line")"
extensionName="$(cut -d':' -f2 <<<"$line")"
cd "$workingDir"
gsei="$shell_dir"/gnome-shell-extension-installer/gnome-shell-extension-installer
$gsei "$extensionID" --yes --no-install >/dev/null
extDirName="$(find . -name '*.zip' | sed 's|\.shell-extension\.zip||')"
rm -rf "${workingDir:?}"/*
if test -d "$HOME/.local/share/gnome-shell/extensions/$extDirName"; then
lok "Extension $(yellow "$extensionName") ($(yellow "$extensionID")) already installed"
else
linfo "Extension $(yellow "$extensionName") ($(yellow "$extensionID")) not installed yet. Installing..."
"$shell_dir"/gnome-shell-extension-installer/gnome-shell-extension-installer "$extensionID" --yes
lok "Extension $(yellow "$extensionName") ($(yellow "$extensionID")) installed"
fi
done
cd "$shell_dir" &>/dev/null
rm -rf "$workingDir"
lok "Gnome extensions checked"
}
ensureGitDirectories() {
gitDirs=()
listCfgValues gitDirs 'git_dirs.cfg'
linfo "Checking git repositories..."
for line in "${gitDirs[@]}"; do
fetchURL="$(cut -d'%' -f1 <<<"$line")"
# dirPath="$(cut -d'%' -f2 <<<"$line" | sed "s|^\$HOME|$HOME|" | sed "s|^~|$HOME|")"
dirPath="$(cut -d'%' -f2 <<<"$line")" # can still have variables: ~/$HOME/$ZSH_CUSTOM/...
dirPath="$(eval "echo $dirPath")"
name="$(cut -d'%' -f3 <<<"$line")"
pushURL="$(cut -d'%' -f4 <<<"$line")"
ensureGitRepositoryPresent "$fetchURL" "$dirPath" "$name" "$pushURL"
done
lok "Git repositories checked"
}
ensurePipPackages() {
installedPackages="$(pip3 list)"
pipPackages=()
listCfgValues pipPackages 'pip_packages.cfg'
linfo "Checking pip packages..."
for line in "${pipPackages[@]}"; do
ppackage="$(cut -d: -f1 <<<"$line")"
# options="$(cut -d: -f2 <<<"$line")"
if grep -Pq "^${ppackage}\s+" <<<"$installedPackages"; then
lok "Pip package ${YELLOW}$ppackage${NC} is already installed"
else
linfo "Installing ${YELLOW}$ppackage${NC}..."
pip3 install "$ppackage"
lok "Pip package ${YELLOW}$ppackage${NC} installed successfully"
fi
done
lok "Pip packages checked"
}
# installFont works only with url which download an archive atm
installFont() {
font=$1
url=$2
tempDir="$(mktemp -d)"
cd "$tempDir"
ldebug "retrieving font from url: $url"
curl -LOJs "$url"
ldebug "extracting archive"
extract "$(find ./* | head -n1)" # there should be only one downloaded file, but just in case
ldebug "moving fonts to the font dir"
find . -name '*.ttf' -exec mv "{}" "$FONT_DIR" \;
find . -name '*.otf' -exec mv "{}" "$FONT_DIR" \;
cd - >/dev/null
rm -rf "$tempDir"
}
ensureFontsInstalled() {
FONT_DIR="$HOME/.local/share/fonts"
fonts=()
listCfgValues fonts 'fonts.cfg'
linfo "Checking fonts..."
ldebug "ensuring font directory is present"
mkdir -p "$FONT_DIR"
for line in "${fonts[@]}"; do
font="$(cut -d% -f1 <<<"$line")"
url="$(cut -d% -f2 <<<"$line")"
if ls "$FONT_DIR/"*"${font}"* >/dev/null 2>&1; then
lok "Font ${YELLOW}$font${NC} is already installed"
else
linfo "Installing ${YELLOW}$font${NC}..."
installFont "$font" "$url"
lok "Font ${YELLOW}$font${NC} installed successfully"
fi
done
lok "Fonts checked"
}
ensureKittyInstalled() {
if test -f ~/.local/kitty.app/bin/kitty; then
lok "$(yellow kitty) already installed"
else
linfo "Installing $(yellow kitty)..."
curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin
lok "$(yellow kitty) installed"
fi
if ! test -f ~/.local/bin/kitty || ! test -f ~/.local/bin/kitten; then
linfo "Adding $(yellow kitty) to PATH..."
# Create symbolic links to add kitty and kitten to PATH
ln -sf ~/.local/kitty.app/bin/kitty ~/.local/kitty.app/bin/kitten ~/.local/bin/
lok "$(yellow kitty) added to PATH"
fi
if ! test -f ~/.local/share/applications/kitty.desktop; then
linfo "Adding $(yellow kitty) as desktop application..."
# Place the kitty.desktop file somewhere it can be found by the OS
cp ~/.local/kitty.app/share/applications/kitty.desktop ~/.local/share/applications/
# # If you want to open text files and images in kitty via your file manager also add the kitty-open.desktop file
# cp ~/.local/kitty.app/share/applications/kitty-open.desktop ~/.local/share/applications/
# Update the paths to the kitty and its icon in the kitty.desktop file(s)
sed -i "s|Icon=kitty|Icon=/home/$USER/.local/kitty.app/share/icons/hicolor/256x256/apps/kitty.png|g" ~/.local/share/applications/kitty*.desktop
sed -i "s|Exec=kitty|Exec=/home/$USER/.local/kitty.app/bin/kitty|g" ~/.local/share/applications/kitty*.desktop
lok "$(yellow kitty) added as desktop application"
fi
}
# ────────────────────────────────────────────────────────────────────────────────
# Main function & main workflows
cleanup() {
# WARN: exiting there
if [[ $? != 0 ]]; then
lfail "an error occured, aborting..."
exit 1
fi
}
trap cleanup 0
init() {
EnvInDirPath="$ENVIN_DEFAULT_PATH"
cd "$shell_dir" &>/dev/null
# TODO: verify envin is not launched as sudo
verify_admin
# update_system
}
full_install() {
# CLI utils
echo -e "\n─── ${BOLD}$(date --rfc-3339=second) - System ${NORM}────────────────────────────────────────────"
ensurePackages
# Rust CLI utils
echo -e "\n─── ${BOLD}$(date --rfc-3339=second) - Rust env & bins ${NORM}───────────────────────────────────"
cmdExists "cargo" && lok "cargo installed" || installCargo
ensureCargoBins
# Shell
echo -e "\n─── ${BOLD}$(date --rfc-3339=second) - Shell ${NORM}─────────────────────────────────────────────"
# fileExists "$HOME/.local/share/fonts/Droid Sans Mono Nerd Font Complete.otf" || installDSMNerdFont
fileExists "$HOME/.local/share/fonts/Droid Sans Mono for Powerline Nerd Font Complete.otf" && lok "Nerd font already installed" || installDSMNerdFont
ensureDebPkg "tilix"
ensureTilixConfiguration
ensureKittyInstalled
ensureDebPkg "zsh"
dirExists "$HOME/.oh-my-zsh" && lok "oh-my-zsh installed" || installOhMyZSH
# dirExists "$ZSH/custom/plugins/zsh-autosuggestions" && lok "oh-my-zsh installed" || installOMZAutoSuggest
dirExists "$ZSH/custom/plugins/zsh-autosuggestions" && lok "OMZ autosuggestions installed" || printNInstall "OMZ autosuggestions" 'git clone https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"/plugins/zsh-autosuggestions'
cmdExists "starship" && lok "starship installed" || installStarship
dirExists "$HOME/.dotfiles" && lok "Dotfiles directory present" || setupDotfiles
dot check && lok "dotfiles synced correctly" || linkDotfiles
# Desktop Environment
echo -e "\n─── ${BOLD}$(date --rfc-3339=second) - Desktop environment ${NORM}───────────────────────────────"
dirExists "$HOME/.themes/Matcha-dark-azul" || installDesktopTheme
dirExists "$HOME/.local/share/icons/Zafiro-icons" || installIconTheme
ensureFontsInstalled
ensureGnomeStyle
ensureGnomeConfiguration
# Gnome Shell extensions
echo -e "\n─── ${BOLD}$(date --rfc-3339=second) - Gnome Shell extensions ${NORM}────────────────────────────"
test -d ./gnome-shell-extension-installer && ensureGnomeShellExtensions
# Config
echo -e "\n─── ${BOLD}$(date --rfc-3339=second) - Configuration ${NORM}─────────────────────────────────────"
dirExists "$HOME/opt" && lok "local opt directory exists" || mkdir -p "$HOME/opt"
dirExists "$HOME/bin" && lok "local bin directory exists" || mkdir -p "$HOME/bin"
# cheat.sh
cmdExists "cht.sh" && lok "cht.sh already installed" || installCheatSh
# VSCode
echo -e "\n─── ${BOLD}$(date --rfc-3339=second) - VSCode ${NORM}────────────────────────────────────────────"
cmdExists "code" && lok "VSCode already installed" || installVSCode
ensureVSCodeExtensions
# Brew
echo -e "\n─── ${BOLD}$(date --rfc-3339=second) - Brew ${NORM}──────────────────────────────────────────────"
cmdExists "brew" && lok "brew already installed" || installBrew
ensureBrewFormulaes
# Golang
echo -e "\n─── ${BOLD}$(date --rfc-3339=second) - Golang ${NORM}────────────────────────────────────────────"
cmdExists "go" && lok "go already installed" || installGo
if ! command -v go &>/dev/null; then
lfail "Go is not installed on this system. Could not install go binaries (tools)"
else
ensureGoPackages
fi
# Python
echo -e "\n─── ${BOLD}$(date --rfc-3339=second) - Python3 - pip3 ${NORM}────────────────────────────────────"
ensurePipPackages
apt show balena-etcher-electron >/dev/null 2>/dev/null && lok "etcher already installed" || installEtcher
# Git repos
echo -e "\n─── ${BOLD}$(date --rfc-3339=second) - Git repositories ${NORM}──────────────────────────────────"
ensureGitDirectories
echo
lok "Envin finished successfully"
# TEST: git remote set-url origin [email protected]:Nephylhim/dotfiles.git --push
# TEST: dotfiles retrieve submodules
# TEST: go bins (panicparse) => go get -u github.com/charmbracelet/glow
# TEST: install OMZ full auto (auto change shell [maybe another step in the script]. But don't enter zsh, we want to finish setup) => ask if we want to change default shell
# TEST: install starship full auto (in /usr/local/bin or user land?)
# TEST: brew (full auto)
# TEST: ensure package build-essential is installed => refacto packages
# TEST: retrieve git submodule
# TODO: adapt for arch/manjaro
# TODO: --no-graphic mode (no gnome / vscode setup) / profils
# TODO: change arch to work with plugins?
}
main() {
debug=false
init
ensureDebPkg "git"
ensureSelfInGitRepository
full_install
sudoer_file_remove_user
}
main