-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbootstrap-lib.sh
1475 lines (1322 loc) · 56.9 KB
/
bootstrap-lib.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
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
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# Basic library functions for my dotfiles
#
_ERRORS=()
_MACHINE_ARCH=$(uname -m)
if [[ ${_MACHINE_ARCH} == "x86_64" ]]; then
_GOLANG_ARCH="amd64"
fi
if [[ ${_MACHINE_ARCH} == "aarch64" ]]; then
_GOLANG_ARCH="arm64"
fi
fn_log_error() {
_ERRORS+=("${@}")
}
fn_print_errors() {
if [[ -n "${_ERRORS[*]}" ]]; then
printf "\n\nERRORS:\n"
for error in "${_ERRORS[@]}"; do
printf "%s\n" "${error}"
done
fi
}
# Ensure the needed dirs exist
fn_mkdir_if_needed() {
if [[ ! -d "${1}" ]]; then
mkdir -p "${1}"
fi
}
fn_system_install_chrome() {
# Chrome is stilly and special because $reasons
if ! rpm -q google-chrome-stable &>/dev/null; then
sudo dnf install -y https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm \
|| fn_log_error "${FUNCNAME[0]}: failed to dnf install google-chrome-stable"
fi
###########################################################################
# FIXME: This does not behave well on RHEL9 so we'll wait for now ...
#
# For some reason this messes up the scaling of the display, font
# preferences, and accessability settings.
###########################################################################
# # force wayland for chrome
# chrome_desktop_file_path="/usr/share/applications/google-chrome.desktop"
# chrome_desktop_local_path="${HOME}/.local/share/applications/google-chrome.desktop"
# if [[ -f ${chrome_desktop_file_path} ]]; then
# if [[ ! -f ${chrome_desktop_local_path} ]]; then
# printf "Forcing wayland for google-chrome...\n"
# cp "${chrome_desktop_file_path}" "${chrome_desktop_local_path}"
#
# sed -i \
# 's|Exec=/usr/bin/google-chrome-stable|Exec=google-chrome-stable --enable-features=UseOzonePlatform --ozone-platform=wayland|'
# "${chrome_desktop_local_path}"
# update-desktop-database ~/.local/share/applications/
# fi
# elif [[ -f ${chrome_desktop_local_path} ]]; then
# printf "Removing local google-chrome desktop file...\n"
# rm "${chrome_desktop_local_path}"
# fi
}
fn_setup_rhel_csb() {
source /etc/os-release
local repofile="/etc/yum.repos.d/billings-csb.repo"
# Use Billings' COPR
if [[ "${ID}" == "rhel" ]] || [[ "${ID}" == "redhat" ]]; then
sudo tee ${repofile} &>/dev/null << "EOF"
[copr:copr.devel.redhat.com:jbilling:unoffical-rhel9]
name=Copr repo for unoffical-rhel9 owned by jbilling
baseurl=https://coprbe.devel.redhat.com/results/jbilling/unoffical-rhel9/rhel-9-$basearch/
type=rpm-md
skip_if_unavailable=True
gpgcheck=0
gpgkey=https://coprbe.devel.redhat.com/results/jbilling/unoffical-rhel9/pubkey.gpg
repo_gpgcheck=0
enabled=1
enabled_metadata=1
EOF
fi
if ! [[ -f ${repofile} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to setup copr"
fi
# if [[ "${ID}" == "rhel" ]] || [[ "${ID}" == "redhat" ]]; then
# sudo tee /etc/yum.repos.d/redhat-csb.repo &>/dev/null << EOF
# [rhel-csb]
# name=RHEL CSB packages
# baseurl=http://hdn.corp.redhat.com/rhel8-csb
# enabled=1
# gpgcheck=1
# gpgkey=http://hdn.corp.redhat.com/rhel8-csb/RPM-GPG-KEY-helpdesk
# skip_if_unavailable=yes
# includepkgs=redhat-internal-*,oneplay-gstreamer-codecs-pack,zoom,ffmpeg-libs,xvidcore
# EOF
# fi
}
# Symlink the conf files
fn_symlink_if_needed() {
if [[ -f ${2} ]] && [[ ! -L ${2} ]]; then
printf "File found: %s ... backing up\n" "$2"
# if the destination file exists and isn't a symlink, back it up
mv "${2}" "${2}.old$(date +%Y%m%d)" || fn_log_error "${FUNCNAME[0]}: failed to back up ${2}"
fi
if [[ ! -f ${2} ]] && [[ ! -L ${2} ]]; then
printf "Symlinking: %s -> %s\n" "$1" "$2"
if [[ ! -d "$(dirname "${2}")" ]]; then
mkdir -p "$(dirname "${2}")" || fn_log_error "${FUNCNAME[0]}: failed to mkdir $(dirname "${2}")"
fi
ln -s "${1}" "${2}"
fi
}
fn_rm_on_update_if_needed() {
#
# Arguments:
# $1 - str: path to local installed executable
# $2 - str: latest upstream release
# $3 - str: string representation of the current locally installed version
# $4 - array: list of files to remove
local uninstall_paths
uninstall_paths=("$@")
# drop the first three strings
unset "uninstall_paths[0]"
unset "uninstall_paths[1]"
unset "uninstall_paths[2]"
if [[ -f ${1} ]]; then
if [[ ${2} != "${3}" ]]; then
rm -f "${uninstall_paths[@]}" || fn_log_error "${FUNCNAME[0]}: failed to rm ${1}"
fi
fi
}
fn_system_polkit_libvirt_nonroot_user() {
local polkit_file_path="/etc/polkit-1/rules.d/50-org.libvirt.unix.manage.rules"
if ! sudo test -f "${polkit_file_path}"; then
printf "Setting polkit libvirt non-root user...\n"
sudo tee "${polkit_file_path}" &>/dev/null << EOF
polkit.addRule(function(action, subject) {
if (action.id == "org.libvirt.unix.manage" &&
subject.user == "${USER}") {
return polkit.Result.YES;
polkit.log("action=" + action);
polkit.log("subject=" + subject);
}
});
EOF
fi
if ! sudo test -f ${polkit_file_path}; then
fn_log_error "${FUNCNAME[0]}: failed to set polkit libvirt non-root user"
fi
}
fn_system_install_tailscale() {
source /etc/os-release
if [[ "${ID}" == "debian" ]]; then
# tailscale
local tailscale_keyring="/usr/share/keyrings/tailscale-archive-keyring.gpg"
local tailscale_aptlist="/etc/apt/sources.list.d/tailscale.list"
if ! dpkg -l tailscale > /dev/null 2>&1; then
curl -fsSL "https://pkgs.tailscale.com/stable/debian/${VERSION_CODENAME}.noarmor.gpg" | sudo tee ${tailscale_keyring} >/dev/null
if ! [[ -f ${tailscale_keyring} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to download ${tailscale_keyring}"
fi
curl -fsSL "https://pkgs.tailscale.com/stable/debian/${VERSION_CODENAME}.tailscale-keyring.list" | sudo tee ${tailscale_aptlist}
if ! [[ -f ${tailscale_aptlist} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to download ${tailscale_aptlist}"
fi
sudo apt update
sudo apt install -y tailscale || fn_log_error "${FUNCNAME[0]}: failed to install tailscale"
fi
fi
if [[ "${ID}" == "rhel" || "${ID}" == "redhat" || "${ID}" == "centos" ]]; then
if ! rpm -q tailscale &>/dev/null; then
local el_major_version
el_major_version=$(rpm -E %rhel)
sudo dnf config-manager --add-repo "https://pkgs.tailscale.com/stable/rhel/${el_major_version}/tailscale.repo"
sudo dnf install -y tailscale || fn_log_error "${FUNCNAME[0]}: failed to install tailscale"
sudo systemctl enable --now tailscaled || fn_log_error "${FUNCNAME[0]}: failed to enable tailscale.service"
fi
fi
if [[ "${ID}" == "fedora" ]]; then
if ! rpm -q tailscale &>/dev/null; then
sudo dnf config-manager --add-repo https://pkgs.tailscale.com/stable/fedora/tailscale.repo
sudo dnf install -y tailscale || fn_log_error "${FUNCNAME[0]}: failed to install tailscale"
sudo systemctl enable --now tailscaled || fn_log_error "${FUNCNAME[0]}: failed to enable tailscale.service"
fi
fi
}
fn_system_install_packages() {
# accept a list of packages and install them
source /etc/os-release
local pending_install_pkgs=()
for pkg in "${@}"; do
if [[ "${ID}" == "debian" ]]; then
if ! dpkg -s "${pkg}" | grep "Status: install ok installed" > /dev/null 2>&1; then
pending_install_pkgs+=("${pkg}")
fi
fi
if [[ "${ID}" == "rhel" || "${ID}" == "redhat" || "${ID}" == "centos" || "${ID}" == "fedora" ]]; then
if ! rpm -q "${pkg}" &>/dev/null; then
pending_install_pkgs+=("${pkg}")
fi
fi
done
if [[ -n "${pending_install_pkgs[*]}" ]]; then
printf "Installing packages... %s\n" "${pending_install_pkgs[@]}"
if [[ "${ID}" == "debian" ]]; then
sudo apt install -y "${pending_install_pkgs[@]}" || fn_log_error "${FUNCNAME[0]}: failed to install packages: ${pending_install_pkgs[*]}"
fi
if [[ "${ID}" == "rhel" || "${ID}" == "redhat" || "${ID}" == "centos" || "${ID}" == "fedora" ]]; then
# intentionally want word splitting so don't quote
sudo dnf install -y --allowerasing "${pending_install_pkgs[@]}" || fn_log_error "${FUNCNAME[0]}: failed to install packages: ${pending_install_pkgs[*]}"
fi
fi
}
fn_flatpak_overrides() {
# Chrome
local chrome_override_file="${HOME}/.local/share/flatpak/overrides/com.google.Chrome"
fn_mkdir_if_needed "$(dirname "${chrome_override_file}")"
cat > "${chrome_override_file}" << "EOF"
[Context]
filesystems=~/.local/share/icons/;~/.local/share/applications/
EOF
if ! [[ -f "${chrome_override_file}" ]]; then
fn_log_error "${FUNCNAME[0]}: failed to create flatpak override file: ${chrome_override_file}"
fi
# Slack
local slack_override_file="${HOME}/.local/share/flatpak/overrides/com.slack.Slack"
fn_mkdir_if_needed "$(dirname "${slack_override_file}")"
cat > "${slack_override_file}" << "EOF"
[Context]
filesystems=~/Pictures/Screenshots/
EOF
if ! [[ -f "${slack_override_file}" ]]; then
fn_log_error "${FUNCNAME[0]}: failed to create flatpak override file: ${slack_override_file}"
fi
}
fn_flathub_install() {
fn_flatpak_overrides
local flatpak_pkgs
flatpak_pkgs=(
"hu.irl.cameractrls"
"com.slack.Slack"
"im.riot.Riot"
"org.onlyoffice.desktopeditors"
"io.podman_desktop.PodmanDesktop"
"com.google.Chrome"
)
if ! flatpak remotes --user | grep flathub &>/dev/null; then
flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo \
|| fn_log_error "${FUNCNAME[0]}: failed to add flathub remote"
fi
for flatpak_pkg in "${flatpak_pkgs[@]}"; do
if ! flatpak list | grep "${flatpak_pkg}" &>/dev/null; then
flatpak install --user -y flathub "${flatpak_pkg}" \
|| fn_log_error "${FUNCNAME[0]}: failed to install flatpak ${flatpak_pkg}"
fi
done
}
fn_system_gnome_settings() {
# key remap because fuck the capslock key
local current_xkb_options
local new_xkb_options
if dconf help &>/dev/null; then
current_xkb_options=$(dconf read /org/gnome/desktop/input-sources/xkb-options 2>/dev/null)
if [[ -z "${current_xkb_options}" ]] || [[ "${current_xkb_options}" == "@as []" ]]; then
# if current_xkb_options is empty, set it
new_xkb_options="['caps:escape']"
else
# if current_xkb_options is empty, modify it
new_xkb_options=${current_xkb_options//\[/\[\'caps:escape\', }
fi
if ! [[ "${current_xkb_options}" =~ "caps:escape" ]]; then
dconf write /org/gnome/desktop/input-sources/xkb-options "${new_xkb_options}" \
|| fn_log_error "${FUNCNAME[0]}: failed to set xkb-options"
fi
fi
if gsettings help &>/dev/null; then
# set alt-tab behavior for sanity
gsettings set org.gnome.desktop.wm.keybindings switch-applications "[]" \
|| fn_log_error "${FUNCNAME[0]}: failed to set gsettings switch-applications"
gsettings set org.gnome.desktop.wm.keybindings switch-applications-backward "[]" \
|| fn_log_error "${FUNCNAME[0]}: failed to set gsettings switch-applications-backward"
gsettings set org.gnome.desktop.wm.keybindings switch-windows "['<Alt>Tab']" \
|| fn_log_error "${FUNCNAME[0]}: failed to set gsettings switch-windows"
gsettings set org.gnome.desktop.wm.keybindings switch-windows-backward "['<Shift><Alt>Tab']" \
|| fn_log_error "${FUNCNAME[0]}: failed to set gsettings switch-windows-backward"
# enable GNOME Fractional Scaling
# gsettings set org.gnome.mutter experimental-features "['scale-monitor-framebuffer']" \
# || fn_log_error "${FUNCNAME[0]}: failed to set gsettings scale-monitor-framebuffer for fractional scaling"
fi
}
fn_system_docker_crostini() {
# https://docs.docker.com/engine/install/debian/
# fucking docker ...
if ! dpkg -l docker-ce | grep "${_GOLANG_ARCH}" > /dev/null 2>&1; then
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc
do
sudo apt remove "${pkg}" || fn_log_error "${FUNCNAME[0]}: failed to remove package ${pkg}"
done
sudo apt install -y ca-certificates curl gnupg || fn_log_error "${FUNCNAME[0]}: failed to install packages ca-certificates curl gnupg"
sudo install -m 0755 -d /etc/apt/keyrings || fn_log_error "${FUNCNAME[0]}: failed to create /etc/apt/keyrings"
curl -fsSL https://download.docker.com/linux/debian/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg || fn_log_error "${FUNCNAME[0]}: failed to download docker gpg key"
sudo chmod a+r /etc/apt/keyrings/docker.gpg || fn_log_error "${FUNCNAME[0]}: failed to set docker gpg key permission"
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
"$(. /etc/os-release && echo "${VERSION_CODENAME}")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin \
|| fn_log_error "${FUNCNAME[0]}: failed to install packages: docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"
if ! grep docker /etc/group >/dev/null; then
sudo groupadd docker || fn_log_error "${FUNCNAME[0]}: failed to add group docker"
fi
if ! id -nG admiller | grep docker >/dev/null; then
sudo usermod -aG docker "${USER}" || fn_log_error "${FUNCNAME[0]}: failed to add user ${USER} to group docker"
fi
fi
}
fn_system_setup_crostini() {
fn_system_install_tailscale
local nodejs_keyring="/etc/apt/keyrings/nodesource.gpg"
local nodejs_aptfile="/etc/apt/sources.list.d/nodesource.list"
# nodejs LTS
NODE_MAJOR=20
if ! dpkg -l nodejs | grep ${NODE_MAJOR}\. > /dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg || fn_log_error "${FUNCNAME[0]}: failed to install ca-certificates curl gnupg"
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o "${nodejs_keyring}"
if ! [[ -f "${nodejs_keyring}" ]]; then
fn_log_error "${FUNCNAME[0]}: failed to download ${nodejs_keyring}"
fi
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | sudo tee "${nodejs_aptfile}"
if ! [[ -f ${nodejs_aptfile} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to download ${nodejs_aptfile}"
fi
sudo apt update
sudo apt install -y nodejs || fn_log_error "${FUNCNAME[0]}: failed to install nodejs"
fi
fn_system_docker_crostini
# random dev stuff
local pkglist
pkglist=(
"vim-nox"
"apt-file"
"debsums"
"python3"
"python3-pip"
"python3-venv"
"python3-q"
"python3-pylsp"
"python3-virtualenvwrapper"
"python-is-python3"
"git"
"tig"
"tmux"
"htop"
"iotop"
"strace"
"tree"
"pipx"
"libonig-dev"
"firefox-esr"
"debian-goodies"
"flatpak"
"bubblewrap"
"tshark"
"termshark"
"nmap"
"jq"
"podman"
"skopeo"
"buildah"
"luarocks"
"cmake"
"ninja-build"
"gettext"
"unzip"
"curl"
"fd-find"
"shellcheck"
"ripgrep"
"git-crypt"
"wl-clipboard"
"rlwrap"
"mosh"
)
fn_system_install_packages "${pkglist[@]}"
# golang
golang_version="1.23.3"
if dpkg -l golang > /dev/null 2>&1; then
sudo apt remove -y golang
fi
if ! go version | grep "$golang_version" > /dev/null 2>&1; then
sudo rm -fr /usr/local/go
fi
if [[ ! -d /usr/local/go ]]; then
printf "Installing golang...\n"
sudo curl -o "/usr/local/go-${golang_version}.tar.gz" "https://dl.google.com/go/go${golang_version}.linux-$(dpkg --print-architecture).tar.gz" \
|| fn_log_error "${FUNCNAME[0]}: failed to download /usr/local/go-${golang_version}.tar.gz"
sudo tar -zxvf /usr/local/go-${golang_version}.tar.gz --directory=/usr/local/ \
|| fn_log_error "${FUNCNAME[0]}: failed to extract /usr/local/go-${golang_version}.tar.gz"
sudo rm /usr/local/go-${golang_version}.tar.gz \
|| fn_log_error "${FUNCNAME[0]}: failed to remove /usr/local/go-${golang_version}.tar.gz"
fi
# podman subuid/subgid
podman_system_migrate=""
if ! grep -q "${USER}:10000:65536" /etc/subuid; then
sudo sh -c "echo ${USER}:10000:65536 >> /etc/subuid"
podman_system_migrate="true"
fi
if ! grep -q "${USER}:10000:65536" /etc/subgid; then
sudo sh -c "echo ${USER}:10000:65536 >> /etc/subgid"
podman_system_migrate="true"
fi
if [[ ${podman_system_migrate} == "true" ]]; then
printf "Migrating podman system...\n"
podman system migrate
fi
# Force wayland for firefox-esr
firefox_esr_desktop_file_path="/usr/share/applications/firefox-esr.desktop"
firefox_esr_desktop_local_path="${HOME}/.local/share/applications/firefox-esr.desktop"
if [[ -f ${firefox_esr_desktop_file_path} ]]; then
if [[ ! -f ${firefox_esr_desktop_local_path} ]]; then
printf "Forcing wayland for firefox-esr...\n"
cp "${firefox_esr_desktop_file_path}" "${firefox_esr_desktop_local_path}"
sed -i \
's|Exec=/usr/lib/firefox-esr/firefox-esr %u|Exec=env MOZ_ENABLE_WAYLAND=1 /usr/lib/firefox-esr/firefox-esr %u|' \
"${firefox_esr_desktop_local_path}"
fi
if [[ ! -f ${firefox_esr_desktop_local_path} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to set local firefox-esr desktop file"
fi
elif [[ -f ${firefox_esr_desktop_local_path} ]]; then
printf "Removing local firefox-esr desktop file...\n"
rm "${firefox_esr_desktop_local_path}"
fi
vscode_desktop_file_path="/usr/share/applications/code.desktop"
vscode_local_file_path="${HOME}/.local/share/applications/code.desktop"
if [[ -f ${vscode_desktop_file_path} ]]; then
if [[ ! -f ${vscode_local_file_path} ]]; then
printf "Forcing wayland for vscode...\n"
cp "${vscode_desktop_file_path}" "${vscode_local_file_path}"
sed -i \
's|Exec=/usr/share/code/code|Exec=/usr/share/code/code --enable-features=UseOzonePlatform --ozone-platform=wayland|g' \
"${vscode_local_file_path}"
fi
if [[ ! -f ${vscode_local_file_path} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to set local vscode desktop file"
fi
elif [[ -f "${vscode_local_file_path}" ]]; then
printf "Removing local vscode desktop file...\n"
rm "${vscode_local_file_path}"
fi
}
fn_system_install_epel(){
# Install EPEL
local el_major_version
el_major_version=$(rpm -E %rhel)
if ! rpm -q epel-release &>/dev/null; then
if [[ -f /etc/centos-release ]]; then
sudo dnf config-manager --enable crb || fn_log_error "${FUNCNAME[0]}: failed to enable crb"
sudo dnf -y install epel-release || fn_log_error "${FUNCNAME[0]}: failed to install epel-release"
else
sudo subscription-manager repos --enable "codeready-builder-for-rhel-${el_major_version}-$(arch)-rpms" \
|| fn_log_error "${FUNCNAME[0]}: failed to enable codeready-builder-for-rhel-${el_major_version}-$(arch)-rpms"
sudo dnf install -y "https://dl.fedoraproject.org/pub/epel/epel-release-latest-${el_major_version}.noarch.rpm" \
|| fn_log_error "${FUNCNAME[0]}: failed to install epel-release"
fi
fi
}
fn_system_setup_fedora_el() {
# Setup for Fedora/RHEL/CentOS-Stream
#
fn_mkdir_if_needed ~/.local/bin/
fn_mkdir_if_needed ~/.local/share/bash-completion/completions/
if [[ "${ID}" == "rhel" || "${ID}" == "redhat" || "${ID}" == "centos" ]]; then
fn_system_install_epel
fi
# Tailscale
fn_system_install_tailscale
# random dev stuff
local fedora_el_pkglist
fedora_el_pkglist=(
"vim-enhanced"
"python3"
"python3-pip"
"nodejs"
"git"
"tig"
"tmux"
"htop"
"strace"
"tree"
"pipx"
"flatpak"
"wireshark-cli"
"nmap"
"jq"
"podman"
"skopeo"
"buildah"
"luarocks"
"cmake"
"gcc"
"gcc-c++"
"golang"
"rust"
"cargo"
"gettext"
"unzip"
"curl"
"fd-find"
"ShellCheck"
"dconf"
"xsel"
"ripgrep"
"epson-inkjet-printer-escpr"
"epson-inkjet-printer-escpr2"
"centpkg"
"centpkg-sig"
"subscription-manager"
"git-crypt"
"wl-clipboard"
"rlwrap"
"mosh"
"lm_sensors"
)
if [[ "${ID}" == "rhel" || "${ID}" == "redhat" || "${ID}" == "centos" ]]; then
fedora_el_pkglist+=(
"python3.12"
"python3.12-pip"
"iotop"
"npm"
)
fi
if [[ "${ID}" == "fedora" ]]; then
fedora_el_pkglist+=(
"iotop-c"
"nodejs-npm"
"python3-devel"
"python3-torch"
"python3-ramalama"
"fedpkg"
"ninja-build"
"neovim"
"fedora-review"
)
if grep "AMD Ryzen" /proc/cpuinfo &>/dev/null; then
fedora_el_pkglist+=(
"rocminfo"
"rocm-runtime"
"nvtop"
)
fi
fi
sudo usermod "${USER}" -a -G mock
fn_system_install_packages "${fedora_el_pkglist[@]}"
fn_system_polkit_libvirt_nonroot_user
fn_flathub_install
fn_system_gnome_settings
}
fn_local_install_virtualenvwrapper(){
# virtualenvwrapper
if ! pip list | grep virtualenvwrapper &>/dev/null; then
pip install --user virtualenvwrapper || fn_log_error "${FUNCNAME[0]}: failed to install virtualenvwrapper"
fi
}
fn_local_user_ssh_agent() {
# ssh-agent systemd user unit
local ssh_agent_unit="${HOME}/.config/systemd/user/ssh-agent.service"
fn_mkdir_if_needed ~/.config/systemd/user
if [[ ! -f ${ssh_agent_unit} ]]; then
cat > ${ssh_agent_unit} << "EOF"
[Unit]
Description=SSH key agent
[Service]
Type=simple
Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket
ExecStart=/usr/bin/ssh-agent -D -a $SSH_AUTH_SOCK
[Install]
WantedBy=default.target
EOF
if [[ ! -f ${ssh_agent_unit} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to create ${ssh_agent_unit}"
fi
systemctl --user daemon-reload
systemctl --user enable ssh-agent.service || fn_log_error "${FUNCNAME[0]}: failed to enable ssh-agent.service"
systemctl --user start ssh-agent.service || fn_log_error "${FUNCNAME[0]}: failed to start ssh-agent.service"
fi
}
fn_local_install_distrobox() {
local install_path="${HOME}/.local/bin/distrobox"
local latest_release
local currently_installed_version
latest_release="$(curl -s 'https://api.github.com/repos/89luca89/distrobox/tags' | jq -r '.[0].name')"
if [[ ${1} == "update" ]]; then
if [[ -f ${install_path} ]]; then
currently_installed_version=$(distrobox version | awk -F: '/^distrobox/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }')
local uninstall_paths=("${install_path}" "${install_path}-*")
fn_rm_on_update_if_needed "${install_path}" "${latest_release}" "${currently_installed_version}" "${uninstall_paths[@]}"
fi
fi
if [[ ! -f ${install_path} ]]; then
curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sh -s -- --prefix ~/.local
if [[ ! -f ${install_path} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to install distrobox"
fi
fi
}
fn_local_install_opa() {
local install_path="${HOME}/.local/bin/opa"
local latest_release
local currently_installed_version
latest_release="$(curl -s 'https://api.github.com/repos/open-policy-agent/opa/tags' | jq -r '.[0].name')"
if [[ ${1} == "update" ]]; then
if [[ -f ${install_path} ]]; then
currently_installed_version=$(opa version | awk -F: '/^Version/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }')
local uninstall_paths=("${install_path}")
fn_rm_on_update_if_needed "${install_path}" "${latest_release}" "v${currently_installed_version}" "${uninstall_paths[@]}"
fi
fi
if [[ ! -f ${install_path} ]]; then
if [[ ${_MACHINE_ARCH} == "x86_64" ]]; then
curl -L -o "${install_path}" "https://openpolicyagent.org/downloads/${latest_release}/opa_linux_amd64_static"
fi
if [[ ${_MACHINE_ARCH} == "aarch64" ]]; then
curl -L -o "${install_path}" "https://openpolicyagent.org/downloads/${latest_release}/opa_linux_arm64_static"
fi
if [[ ! -f ${install_path} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to install ${install_path}"
fi
chmod +x "${install_path}"
fi
}
fn_local_install_minikube() {
local install_path="${HOME}/.local/bin/minikube"
local completions_install_path="${HOME}/.local/share/bash-completion/completions/minikube"
local latest_release
local currently_installed_version
latest_release="$(curl -s 'https://api.github.com/repos/kubernetes/minikube/tags' | jq -r '.[0].name')"
if [[ ${1} == "update" ]]; then
if [[ -f ${install_path} ]]; then
currently_installed_version=$(minikube version | awk -F: '/^minikube version/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }')
local uninstall_paths=("${install_path}" "${completions_install_path}")
fn_rm_on_update_if_needed "${install_path}" "${latest_release}" "${currently_installed_version}" "${uninstall_paths[@]}"
fi
fi
# minikube install
if [[ ! -f ${install_path} ]]; then
printf "Installing minikube...\n"
curl -LO "https://storage.googleapis.com/minikube/releases/latest/minikube-linux-${_GOLANG_ARCH}"
chmod +x "./minikube-linux-${_GOLANG_ARCH}"
cp "./minikube-linux-${_GOLANG_ARCH}" "${install_path}"
rm "./minikube-linux-${_GOLANG_ARCH}"
${install_path} completion bash > "${completions_install_path}"
fi
if [[ ! -f ${install_path} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to install ${install_path}"
fi
}
fn_local_install_kind() {
local install_path="${HOME}/.local/bin/kind"
local completions_install_path="${HOME}/.local/share/bash-completion/completions/kind"
local latest_release
local currently_installed_version
# kind tags alpha and stable, if it's alpha, use the latest stable - query with jq
latest_release="$(curl -s 'https://api.github.com/repos/kubernetes-sigs/kind/tags' | jq -r '.[] | select(.name | contains("alpha") | not ).name' | head -1)"
if [[ ${1} == "update" ]]; then
if [[ -f ${install_path} ]]; then
currently_installed_version=$(kind version | awk '/^kind/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }')
local uninstall_paths=("${install_path}" "${completions_install_path}")
fn_rm_on_update_if_needed "${install_path}" "${latest_release}" "${currently_installed_version}" "${uninstall_paths[@]}"
fi
fi
kind_numerical_version="${latest_release#v*}"
# kind install
if [[ ! -f ${install_path} ]]; then
printf "Installing kind...\n"
curl -Lo ./kind "https://kind.sigs.k8s.io/dl/${latest_release}/kind-linux-${_GOLANG_ARCH}"
chmod +x ./kind
cp ./kind "${install_path}"
rm ./kind
${install_path} completion bash > "${completions_install_path}"
fi
if [[ ! -f ${install_path} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to install ${install_path}"
fi
}
fn_local_install_kubectl() {
local install_path="${HOME}/.local/bin/kubectl"
local completions_install_path="${HOME}/.local/share/bash-completion/completions/kubectl"
local latest_release
local currently_installed_version
latest_release=$(curl -L -s https://dl.k8s.io/release/stable.txt)
if [[ ${1} == "update" ]]; then
if [[ -f ${install_path} ]]; then
currently_installed_version=$(kubectl version 2>/dev/null | awk -F: '/^Client Version/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }')
local uninstall_paths=("${install_path}" "${completions_install_path}")
fn_rm_on_update_if_needed "${install_path}" "${latest_release}" "${currently_installed_version}" "${uninstall_paths[@]}"
fi
fi
# kubectl install
if [[ ! -f ${install_path} ]]; then
printf "Installing kubectl...\n"
curl -LO "https://dl.k8s.io/release/${latest_release}/bin/linux/${_GOLANG_ARCH}/kubectl"
chmod +x ./kubectl
cp ./kubectl "${install_path}"
rm ./kubectl
${install_path} completion bash > "${completions_install_path}"
fi
if [[ ! -f ${install_path} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to install ${install_path}"
fi
}
fn_local_install_rosa() {
local install_path="${HOME}/.local/bin/rosa"
local completions_install_path="${HOME}/.local/share/bash-completion/completions/rosa"
local latest_release
local currently_installed_version
latest_release=$(curl -s 'https://api.github.com/repos/openshift/rosa/tags' | jq -r '.[] | select(.name | contains("-rc") | not).name' | head -1)
latest_numerical_version="${latest_release#v*}"
if [[ ${1} == "update" ]]; then
if [[ -f ${install_path} ]]; then
currently_installed_version=$(rosa version 2>/dev/null | grep "${latest_numerical_version}" | td -d 'INFO: ')
local uninstall_paths=("${install_path}" "${completions_install_path}")
fn_rm_on_update_if_needed "${install_path}" "${latest_release}" "${currently_installed_version}" "${uninstall_paths[@]}"
fi
fi
# rosa install
if [[ ! -f ${install_path} ]]; then
pushd /tmp/ || return
printf "Installing rosa...\n"
if [[ "${_MACHINE_ARCH}" == "x86_64" ]]; then
wget -c "/~https://github.com/openshift/rosa/releases/download/${latest_release}/rosa_Linux_${_MACHINE_ARCH}.tar.gz"
tar zxvf "rosa_Linux_${_MACHINE_ARCH}.tar.gz"
elif [[ "${_MACHINE_ARCH}" == "aarch64" ]]; then
wget -c "/~https://github.com/openshift/rosa/releases/download/${latest_release}/rosa_Linux_${_GOLANG_ARCH}.tar.gz"
tar zxvf "rosa_Linux_${_GOLANG_ARCH}.tar.gz"
else
printf "ERROR: Unsupported ROSA architecture: ${_MACHINE_ARCH}\n"
return
fi
cp rosa "${install_path}"
${install_path} completion bash > "${completions_install_path}"
popd || return
fi
if [[ ! -f ${install_path} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to install ${install_path}"
fi
}
fn_local_install_terraform() {
local install_path="${HOME}/.local/bin/terraform"
local latest_release
local currently_installed_version
# terraform tags alpha, beta, and rc ... don't get those
latest_release="$(
curl -s 'https://api.github.com/repos/hashicorp/terraform/tags' \
| jq -r '.[] | select(.name | contains("alpha") | not )| select(.name | contains("beta") | not ) | select(.name | contains("rc") | not).name' \
| head -1 \
)"
if [[ ${1} == "update" ]]; then
if [[ -f ${install_path} ]]; then
currently_installed_version=$(terraform version | awk '/^Terraform/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }')
local uninstall_paths=("${install_path}")
fn_rm_on_update_if_needed "${install_path}" "${latest_release}" "${currently_installed_version}" "${uninstall_paths[@]}"
fi
fi
local terraform_version="${latest_release#v*}"
if [[ ! -f ${install_path} ]]; then
printf "Installing terraform...\n"
pushd /tmp/ || return
rm -f terraform terraform.zip # just to make sure the zip command doesn't complain
curl -Lo terraform.zip \
"https://releases.hashicorp.com/terraform/${terraform_version}/terraform_${terraform_version}_linux_${_GOLANG_ARCH}.zip"
unzip terraform.zip
cp terraform "${install_path}"
popd || return
chmod +x "${install_path}"
fi
if [[ ! -f ${install_path} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to install ${install_path}"
fi
}
fn_local_install_rustup() {
local install_path="${HOME}/.cargo/bin/rustup"
local latest_release
local currently_installed_version
latest_release="$(curl -s 'https://api.github.com/repos/rust-lang/rustup/tags' | jq -r '.[0].name')"
if [[ ${1} == "update" ]]; then
if [[ -f ${install_path} ]]; then
currently_installed_version=$(rustup --version 2>/dev/null| awk '/^rustup/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }')
local uninstall_paths=("${install_path}")
fn_rm_on_update_if_needed "${install_path}" "${latest_release}" "${currently_installed_version}" "${uninstall_paths[@]}"
fi
fi
if [[ ! -f ${install_path} ]]; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path
fi
if [[ ! -f ${install_path} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to install ${install_path}"
fi
}
fn_local_install_gh() {
local install_path="${HOME}/.local/bin/gh"
local latest_release
local currently_installed_version
local completions_install_path="${HOME}/.local/share/bash-completion/completions/gh"
latest_release="$(curl -s 'https://api.github.com/repos/cli/cli/tags' | jq -r '.[0].name')"
if [[ ${1} == "update" ]]; then
if [[ -f ${install_path} ]]; then
currently_installed_version=$(gh version| awk '/^gh version/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $3 }')
local uninstall_paths=("${install_path}" "${completions_install_path}")
fn_rm_on_update_if_needed "${install_path}" "${latest_release}" "v${currently_installed_version}" "${uninstall_paths[@]}"
fi
fi
local gh_numerical_version="${latest_release#v*}"
if [[ ! -f ${install_path} ]]; then
printf "Installing gh...\n"
curl -Lo /tmp/gh.tar.gz "/~https://github.com/cli/cli/releases/download/${latest_release}/gh_${gh_numerical_version}_linux_${_GOLANG_ARCH}.tar.gz"
tar -zxvf /tmp/gh.tar.gz -C /tmp/
cp "/tmp/gh_${gh_numerical_version}_linux_${_GOLANG_ARCH}/bin/gh" "${install_path}"
${install_path} completion -s bash > "${completions_install_path}"
fi
if [[ ! -f ${install_path} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to install ${install_path}"
fi
}
fn_local_install_neovim() {
local install_path="${HOME}/.local/bin/nvim"
local latest_release
local currently_installed_version
latest_release="$(curl -s 'https://api.github.com/repos/neovim/neovim/tags' | jq -r '.[0].name')"
if [[ ${1} == "update" ]]; then
if [[ -f ${install_path} ]]; then
currently_installed_version=$(nvim --version| awk '/^NVIM/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }')
local uninstall_paths=("${install_path}")
fn_rm_on_update_if_needed "${install_path}" "${latest_release}" "${currently_installed_version}" "${uninstall_paths[@]}"
fi
fi
local neovim_numerical_version="${latest_release#v*}"
if [[ ! -f ${install_path} ]]; then
printf "Installing neovim from source ... \n"
pushd /tmp/ || return
wget -c "/~https://github.com/neovim/neovim/archive/refs/tags/${latest_release}.tar.gz"
tar -zxvf "${latest_release}.tar.gz"
pushd "neovim-${neovim_numerical_version}/" || return
make CMAKE_BUILD_TYPE=Release CMAKE_INSTALL_PREFIX="${HOME}/.local/"
make install
popd || return
rm -fr "neovim-${latest_release}/"
popd || return
fi
if [[ ! -f ${install_path} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to install ${install_path}"
fi
}
fn_local_install_task() {
local install_path="${HOME}/.local/bin/task"
local completions_install_path="${HOME}/.local/share/bash-completion/completions/task"
local latest_release
latest_release="$(curl -s 'https://api.github.com/repos/go-task/task/tags' | jq -r '.[0].name')"
if [[ ${1} == "update" ]]; then
if [[ -f ${install_path} ]]; then
currently_installed_version=$(nvim --version| awk '/^NVIM/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }')
local uninstall_paths=("${install_path}" "${completions_install_path}")
fn_rm_on_update_if_needed "${install_path}" "${latest_release}" "${currently_installed_version}" "${uninstall_paths[@]}"
fi
fi
if [[ ! -f ${install_path} ]]; then
printf "Installing task...\n"
pushd /tmp/ || return
wget -c "/~https://github.com/go-task/task/releases/download/${latest_release}/task_linux_${_GOLANG_ARCH}.tar.gz"
tar -zxvf "task_linux_${_GOLANG_ARCH}.tar.gz"
cp task "${install_path}"
cp completion/bash/task.bash "${completions_install_path}"
# cleanup the tarball artifacts
for file in $(tar --list --file "task_linux_${_GOLANG_ARCH}.tar.gz"); do
rm -f "${file}"
done
rm -fr completion
popd || return
fi
if [[ ! -f ${install_path} ]]; then
fn_log_error "${FUNCNAME[0]}: failed to install ${install_path}"
fi
}
fn_local_install_yq() {
local install_path="${HOME}/.local/bin/yq"
local latest_release
local completions_install_path="${HOME}/.local/share/bash-completion/completions/yq"
latest_release="$(
curl -s 'https://api.github.com/repos/mikefarah/yq/tags' \
| jq -r '.[] | select(.name | contains("Test") | not).name' \
| head -1
)"
if [[ ${1} == "update" ]]; then
if [[ -f ${install_path} ]]; then
currently_installed_version=$(yq --version | awk '{ print $4 }')
local uninstall_paths=("${install_path}" "${completions_install_path}")
fn_rm_on_update_if_needed "${install_path}" "${latest_release}" "${currently_installed_version}" "${uninstall_paths[@]}"