-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_all.sh
executable file
·941 lines (822 loc) · 26.9 KB
/
setup_all.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
#!/usr/bin/env bash
gpg_primary_key=0x2B7340DB13C85766
gpg_encryption_subkey=0x79C70BBE4865D828
laptop_hostname="thinky"
desktop_hostname="shifty"
current_hostname=$(hostname)
tmp_path=/tmp/setup-"$current_hostname"
package_manager=/usr/bin/yay
pkglist_system_path=/etc/pkglist.txt
# bare minimum packages needed by this script in order to bootstrap
declare -a script_pkgs=(
gnupg
neovim
)
exit_setup() {
rv=$?
printf "\n\nExiting setup...\n"
exit $rv
}
set -euo pipefail
trap 'exit_setup' ERR INT
script_name=$(basename "$0")
help() {
printf "Sets up system packages and configurations.\n\nUsage: %s <%s|%s>\n" "$script_name" "$laptop_hostname" "$desktop_hostname"
}
prompt_exit() {
read -rp "$1 Continue or Abort? (y/N)" answer
case ${answer:0:1} in
y | Y)
return 0
;;
*)
exit_setup 0
;;
esac
}
update_paths() {
base_path=$PWD
data_path="$base_path"/data
system_config_path="$base_path"/system
git_submodule_path="$base_path"/.git_submodules
}
update_paths
if [[ "$current_hostname" != "$laptop_hostname" ]] && [[ "$current_hostname" != "$desktop_hostname" ]]; then
if [[ "$1" != "$laptop_hostname" ]] && [[ "$1" != "$desktop_hostname" ]]; then
echo "Unrecognised hostname! Please provide a valid one."
help
exit 1
else
echo "Unrecognised hostname. Falling back to provided parameter: \"${1}\"."
current_hostname="$1"
fi
else
echo "Using current hostname \"${current_hostname}\" for configuration."
fi
prompt_exit "This script will remove/change existing system settings."
if [[ -n ${DOTFILES+x} ]] && [[ "$base_path" != "$DOTFILES" ]]; then
echo "Changing directory to '${DOTFILES}'"
cd "$DOTFILES"
update_paths
fi
install_packages() {
"$package_manager" -S --noconfirm --needed --noredownload -- "${@}" || {
echo "failed to install:"
echo "${@}"
return 1
}
}
remove_package() {
if "$package_manager" -Qi "$1" >/dev/null; then
"$package_manager" -R --noconfirm -- "$1" >/dev/null || {
:
}
fi
}
rmrf() {
rm -rf "${1}" || {
echo "failed to recursively remove ${1}"
return 1
}
}
symlink() {
if [[ -e "${2}" ]]; then
if [[ ! -L "${2}" ]]; then
echo "${2} already exists and is an irregular type. Check manually whether this is safe to replace with ${1}."
return 1
fi
echo "Removing existing symlink at ${2}"
rmrf "${2}" || {
echo "failed to remove old symlink: ${2}"
return 1
}
fi
# Stow only supports relative symlinks
ln -rs "${1}" "${2}" || {
echo "failed to symlink: ${1} to ${2}"
return 1
}
}
rsync_system_config() {
local system_config_full_path="$system_config_path"/"${1}"
if [[ ! -d "$system_config_full_path" ]]; then
echo "The provided path '${system_config_full_path}' does not exist!"
return 1
fi
sudo rsync --chown=root:root --open-noatime --progress -ruacv -- "${system_config_full_path}"/* / || {
echo "failed to rsync system config from ${system_config_full_path} to root filesystem"
return 1
}
}
systemd_enable_start() {
local unit_path="${1}"
local unit_name
unit_name=$(basename "${1}")
if ! (systemctl -q is-enabled -- "${unit_name}"); then
echo "Enabling Systemd Unit ${unit_name}"
sudo systemctl enable -- "${unit_path}" || {
echo "failed to enable systemd unit ${unit_name}"
return 1
}
fi
if ! (systemctl -q is-active "${unit_name}"); then
echo "Starting Systemd Unit ${unit_name}"
sudo systemctl start -- "${unit_name}" || {
echo "failed to start systemd unit ${unit_name}"
return 1
}
fi
}
systemd_user_enable_start() {
local unit_path="${1}"
local unit_name
unit_name=$(basename "${1}")
if ! (systemctl --user -q is-enabled -- "${unit_name}"); then
echo "Enabling Systemd User Unit ${unit_name}"
systemctl --user enable -- "${unit_path}" || {
echo "failed to enable systemd user unit ${unit_name}"
return 1
}
fi
if ! (systemctl --user -q is-active -- "${unit_name}"); then
echo "Starting Systemd User Unit ${unit_name}"
systemctl --user start -- "${unit_name}" || {
echo "failed to start systemd user unit ${unit_name}"
return 1
}
fi
}
gpg_ssh_agent() {
systemctl --user restart gpg-agent
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
export SSH_AUTH_SOCK
fi
GPG_TTY="${TTY:-"$(tty)"}"
export GPG_TTY
gpg-connect-agent updatestartuptty /bye >/dev/null
}
diff_files() {
if [[ ! -f "$1" ]] && [[ ! -L "$1" ]]; then
echo "file ${1} does not exist"
return 1
fi
if [[ ! -f "$1" ]] && [[ ! -L "$1" ]]; then
echo "file ${2} does not exist"
return 1
fi
if (cmp -s "$1" "$2"); then
# If they are identical, then return
return 0
else
vimdiff -d "$1" "$2" || {
echo "vimdiff on ${1} <-> ${2}' exited with error"
return 1
}
fi
}
# gpg is used directly throughout this setup process
# to handle the non-deterministic nature of gpg encryption, checks/diffs are performed to prevent unwanted changes going un-noticed
gpg_decrypt_file() {
if [[ ! -f "$1" ]] && [[ ! -L "$1" ]]; then
echo "input file ${1} does not exist"
return 1
fi
local input_file_path="${1}"
local output_file_path="${2}"
local output_filename
output_filename=$(basename "${output_file_path}")
local tmp_output_file_path="${tmp_path}/${output_filename}"
echo "Decrypting ${input_file_path} to ${tmp_output_file_path}"
gpg --quiet --no-verbose --local-user "${gpg_encryption_subkey}" --armor --decrypt --yes --output "${tmp_output_file_path}" "${input_file_path}" >/dev/null || {
echo "failed to decrypt file ${input_file_path} to ${tmp_output_file_path}"
return 1
}
# if the file to replace already exists, perform a diff to check for changes
if [[ -f "$output_file_path" ]]; then
diff_files "$output_file_path" "$tmp_output_file_path"
fi
cp -f "$tmp_output_file_path" "$output_file_path" || {
echo "failed to copy '${tmp_output_file_path}' to '${output_file_path}'"
return 1
}
}
line_exists() {
case $(
grep -Fxq "${1}" "${2}" >/dev/null
echo $?
) in
0)
# Found
return 0
;;
1)
# Not found
return 1
;;
*)
exit 1
;;
esac
}
string_exists() {
case $(
grep -Fq "${1}" "${2}" >/dev/null
echo $?
) in
0)
# Found
return 0
;;
1)
# Not found
return 1
;;
*)
exit 1
;;
esac
}
add_group_user() {
sudo groupadd "${1}" || {
:
}
sudo usermod -a -G "${1}" "$(whoami)" || {
echo "Failed to add $(whoami) to group ${1}"
exit 1
}
}
set_default_kernel() {
local efi_loader_conf_path=/efi/loader/loader.conf
local kernel_suffix="${1}".conf
case $(
sudo grep -G -- '^default.*'"${kernel_suffix}"'$' "${efi_loader_conf_path}" >/dev/null
echo $?
) in
0)
echo "Linux ${kernel_suffix} kernel already default"
;;
1)
read -p "Make Linux ${kernel_suffix} kernel default (y/N)?" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
case $(
sudo grep -G -- '^default.*\*$' "${efi_loader_conf_path}" >/dev/null
echo $?
) in
0) ;;
1)
echo "Expected default kernel to be a wildcard (ending with *) in ${efi_loader_conf_path}"
exit 1
;;
*)
echo "Failed to check for wildcard suffix in ${efi_loader_conf_path}"
exit 1
;;
esac
sudo sed -i '/^default/s/$/'"${kernel_suffix}"'/' "${efi_loader_conf_path}"
fi
echo "Linux ${kernel_suffix} kernel set to default"
;;
*)
echo "Failed to check ${efi_loader_conf_path} for ${kernel_suffix} kernel"
exit 1
;;
esac
}
rm_if_not_stowed() {
if [[ -L "${1}" ]]; then
local symlink_path
symlink_path=$(readlink -f "${1}")
if [[ $symlink_path == *"${base_path}"* ]]; then
return 0
fi
fi
rm -rfv "${1}"
}
stow_config() {
stow -v "$1" || {
echo "Failed to stow ${1} config"
exit 1
}
}
mkdir -p "$tmp_path"
echo "Updating package databases & packages"
"$package_manager" -Syu || {
echo "failed to update package databases"
exit 1
}
# Install the bare minimum packages for this script to work
install_packages "${script_pkgs[@]}"
echo "Setting up GPG/SSH"
gpg --list-keys >/dev/null
echo "Removing broken symlinks in ${HOME}/.config"
find ~/.config/ -xtype l -print -delete || {
echo "Failed to remove broken symlinks"
exit 1
}
declare -a old_files=(
/etc/environment.d/qt5.conf
/etc/environment.d/java.conf
)
echo "Checking for old files to remove"
for old_file in "${old_files[@]}"; do
sudo rm -vf "$old_file" || {
echo "failed to remove ${old_file}"
exit 1
}
done
echo "Setting up user directory configs"
# Parent dirs that should not be symlinks from stow-ing
declare -a mk_dirs=(
~/.cargo
~/.continue
~/.config/bat/themes
~/.config/corectrl/profiles
~/.config/environment.d
~/.config/figma-linux
~/.config/khal
~/.config/Kvantum
~/.config/nvim
~/.config/pulse
~/.config/pulseaudio-ctl
~/.config/systemd/user
~/.config/Thunar
~/.config/tidal-hifi
~/.config/VSCodium/User/globalStorage
~/.config/xfce4/xfconf/xfce-perchannel-xml
~/.gnupg
~/.icons
~/.local/bin
~/.local/share/applications
~/.local/share/fonts/OTF
~/.local/share/fonts/TTF
~/.ssh
~/.themes
~/.vscode-oss
~/Pictures/Backgrounds
~/Pictures/Screenshots
)
for mk_dir in "${mk_dirs[@]}"; do
mkdir -p "${mk_dir}"
done
declare -a conflict_paths=(
~/.bashrc
~/.config/gtk-3.0
~/.config/gtk-3.0
~/.config/gtk-4.0
~/.config/mimeapps.list
~/.config/Thunar/uca.xml
~/.config/xfce4/xfconf/xfce-perchannel-xml/thunar.xml
~/.gnupg/common.conf
~/.gtkrc-2.0
~/.vscode-oss/argv.json
~/.zshenv
~/.zshrc
)
echo "Checking for files/directories that will conflict with stow"
for conflict_path in "${conflict_paths[@]}"; do
rm_if_not_stowed "${conflict_path}"
done
declare -a stow_dirs_setup=(
stow
bash
git
gpg
rust
ssh
yay
zsh
)
echo "Stowing setup configs"
for stow_dir in "${stow_dirs_setup[@]}"; do
stow_config "$stow_dir"
done
# shellcheck disable=SC1090
source ~/.bashrc || {
echo "failed to source .bashrc"
exit 1
}
systemd_user_enable_start "$base_path"/gpg/.config/systemd/user/gnupghome.service
systemd_user_enable_start "$base_path"/gpg/.config/systemd/user/ssh-auth-sock.service
systemd_user_enable_start /usr/lib/systemd/user/gpg-agent.service
gpg_ssh_agent
# If our primary GPG key is not yet imported, do that and
if [[ ! $(gpg --list-keys "$gpg_primary_key") ]]; then
gpg --import "$data_path"/gpg/2B7340DB13C85766.asc || {
echo "failed to import GPG pubkey"
exit 1
}
gpg --tofu-policy good "$gpg_primary_key" || {
echo "failed to set gpg tofu policy"
exit 1
}
fi
pass init "$gpg_primary_key" || {
echo "failed to init pass"
exit 1
}
pkglist_remove_path="$data_path"/pkgs/remove.txt
echo "Decrypting data"
declare -a decrypt_data_paths_tuples=(
"${data_path}/corectrl/${current_hostname}__global_.ccpro.asc.gpg ${base_path}/corectrl/.config/corectrl/profiles/_global_.ccpro"
"${data_path}/corectrl/${current_hostname}_codium.ccpro.asc.gpg ${base_path}/corectrl/.config/corectrl/profiles/codium.ccpro"
"${data_path}/corectrl/${current_hostname}_gyroflow.ccpro.asc.gpg ${base_path}/corectrl/.config/corectrl/profiles/gyroflow.ccpro"
"${data_path}/corectrl/${current_hostname}_gamemoded.ccpro.asc.gpg ${base_path}/corectrl/.config/corectrl/profiles/gamemoded.ccpro"
"${data_path}/cura/cura.cfg.asc.gpg ${base_path}/cura/.config/cura/5.7/cura.cfg"
"${data_path}/gallery-dl/config.json.asc.gpg ${base_path}/gallery-dl/.config/gallery-dl/config.json"
"${data_path}/gtk/bookmarks.asc.gpg ${base_path}/gtk/.config/gtk-3.0/bookmarks"
"${data_path}/khal/config.asc.gpg ${base_path}/khal/.config/khal/config"
"${data_path}/pkgs/remove.txt.asc.gpg ${pkglist_remove_path}"
"${data_path}/prusaslicer/PrusaSlicer.ini.asc.gpg ${base_path}/prusaslicer/.config/PrusaSlicer/PrusaSlicer.ini"
"${data_path}/ssh/config.asc.gpg ${base_path}/ssh/.ssh/config"
"${data_path}/tidal-hifi/config.json.asc.gpg ${base_path}/tidal-hifi/.config/tidal-hifi/config.json"
"${data_path}/vdirsyncer/config.asc.gpg ${base_path}/khal/.config/vdirsyncer/config"
"${data_path}/waybar/waybar-crypto/config.ini.asc.gpg ${base_path}/waybar/.config/waybar-crypto/config.ini"
"${data_path}/xdg/mimeapps.list.asc.gpg ${base_path}/xdg/.config/mimeapps.list"
)
for decrypt_data_paths_tuple in "${decrypt_data_paths_tuples[@]}"; do
read -ra decrypt_data_paths <<<"$decrypt_data_paths_tuple"
if [[ -f "${decrypt_data_paths[0]}" ]]; then
gpg_decrypt_file "${decrypt_data_paths[0]}" "${decrypt_data_paths[1]}"
fi
done
# check for packages to be removed
declare -a old_pkgs=()
readarray -t old_pkgs <"$pkglist_remove_path"
echo "Checking for old packages to remove"
for old_pkg in "${old_pkgs[@]}"; do
remove_package "$old_pkg"
done
# check for packages to be installed
pkglist_path="$data_path"/pkgs/"$current_hostname".txt
# If pkglist_system_path exists, it takes precedence over the backup
if [[ -f $pkglist_system_path ]]; then
# make sure pkglist_system_path is symlinked to pkglist_path_current
# if pkglist_path exists and is not symlinked to pkglist_system_path, then remove it
if [[ -f $pkglist_path ]]; then
pkglist_link_path=$(readlink -f "$pkglist_path")
if [[ ! "$pkglist_link_path" == "$pkglist_system_path" ]]; then
echo "removing ${pkglist_path} because it's not a symlink to ${pkglist_system_path}"
rm -f "$pkglist_path"
fi
fi
ln -fs "$pkglist_system_path" "$pkglist_path"
else
# restore from backup
gpg_decrypt_file "$data_path/pkgs/$current_hostname.txt.asc.gpg" "$pkglist_path"
fi
declare -a pkgs=()
readarray -t pkgs <"$pkglist_path"
install_packages "${pkgs[@]}"
# Add user to groups needed by various packages
declare -a user_groups=(
audio
gamemode
plugdev
ssh_login
docker
)
for user_group in "${user_groups[@]}"; do
echo "Adding user to group ${user_group}"
add_group_user "$user_group"
done
declare -a systemd_units=(
/usr/lib/systemd/system/bluetooth.service
/usr/lib/systemd/system/clamav-freshclam-once.timer
/usr/lib/systemd/system/ly.service
/usr/lib/systemd/system/ollama.service
/usr/lib/systemd/system/pcscd.socket
/usr/lib/systemd/system/smartd.service
/usr/lib/systemd/system/swayosd-libinput-backend.service
)
for systemd_unit in "${systemd_units[@]}"; do
systemd_enable_start "${systemd_unit}"
done
echo "Disabling GNOME Keyring SSH Agent (If it exists)"
sudo systemctl disable gcr-ssh-agent.socket || {
:
}
sudo systemctl disable gcr-ssh-agent.service || {
:
}
rustup default stable || {
echo "failed to setup rust stable toolchain"
exit 1
}
rustup update || {
echo "failed to update Rust toolchain"
exit 1
}
rustup component add clippy rustfmt || {
echo "failed to install Rust components"
exit 1
}
sudo update-smart-drivedb
declare -a ollama_models=(
llama3.2:latest
starcoder2:latest
qwen2.5-coder:latest
)
for ollama_model in "${ollama_models[@]}"; do
echo "Pulling ${ollama_model}"
ollama pull "${ollama_model}" || {
echo "failed to install ${ollama_model}"
exit 1
}
done
corectrl_rules_path=/etc/polkit-1/rules.d/90-corectrl.rules
if ! sudo test -f "${corectrl_rules_path}"; then
echo "Setting up polkit for Corectrl"
envsubst <"$data_path"/corectrl/90-corectrl.rules | sudo tee ${corectrl_rules_path} || {
echo "Failed to setup polkit for Corectrl"
exit 1
}
fi
# https://espanso.org/docs/install/linux/#adding-the-required-capabilities
sudo setcap "cap_dac_override+p" "$(which espanso)" || {
echo "failed to setcap for espanso"
exit 1
}
echo "Copying common system configuration"
rsync_system_config common/
if [[ "$current_hostname" == "$laptop_hostname" ]]; then
echo "Copying laptop system configuration"
rsync_system_config "$laptop_hostname"/
pam_rule="auth sufficient pam_fprintd.so max_tries=5 timeout=10"
read -p "Add PAM fprintd rules? (${pam_rule}) (y/N)?" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo vi /etc/pam.d/sudo
sudo vi /etc/pam.d/system-local-login
fi
declare -a systemd_units_laptop=(
/usr/lib/systemd/system/tlp.service
/usr/lib/systemd/system/acpid.service
/etc/systemd/system/powertop.service
)
for systemd_unit in "${systemd_units_laptop[@]}"; do
systemd_enable_start "${systemd_unit}"
done
systemctl --user daemon-reload || {
echo "failed to daemon-reload"
exit 1
}
declare -a systemd_user_units_laptop=(
"$base_path"/sway/.config/systemd/user/tablet-rotate.service
)
for systemd_user_unit_laptop in "${systemd_user_units_laptop[@]}"; do
systemd_user_enable_start "${systemd_user_unit_laptop}"
done
elif [[ "$current_hostname" == "$desktop_hostname" ]]; then
echo "Copying desktop system configuration"
rsync_system_config "$desktop_hostname"/
declare -a stow_dirs_desktop=(
liquidctl
)
echo "Stowing ${desktop_hostname} configs"
for stow_dir in "${stow_dirs_desktop[@]}"; do
stow_config "$stow_dir"
done
set_default_kernel zen
# Update amdgpu boot parameter
# https://wiki.archlinux.org/title/AMDGPU#Boot_parameter
amdgpu_key="amdgpu.ppfeaturemask"
cmd_line_file_path=/etc/kernel/cmdline
amdgpu_boot_parameter=$(printf '%s=0x%x\n' "$amdgpu_key" "$(($(cat /sys/module/amdgpu/parameters/ppfeaturemask) | 0x4000))")
if sudo test -f "$cmd_line_file_path"; then
if ! string_exists "$amdgpu_key" "$cmd_line_file_path"; then
echo "Appending boot parameter '$amdgpu_boot_parameter' to $cmd_line_file_path"
echo " $amdgpu_boot_parameter" | sudo tee -a "$cmd_line_file_path" >/dev/null
sudo reinstall-kernels | {
echo "failed to re-install kernels"
exit 1
}
else
echo "${amdgpu_key} already exists in ${cmd_line_file_path}. skipping."
fi
else
echo "${cmd_line_file_path} does not exist!"
exit 1
fi
declare -a systemd_units_desktop=(
/usr/lib/systemd/system/coolercontrol-liqctld.service
/usr/lib/systemd/system/coolercontrold.service
/usr/lib/systemd/system/logid.service
/usr/lib/systemd/system/power-profiles-daemon.service
)
for systemd_unit_desktop in "${systemd_units_desktop[@]}"; do
systemd_enable_start "${systemd_unit_desktop}"
done
systemctl --user daemon-reload || {
echo "failed to daemon-reload"
exit 1
}
declare -a systemd_user_units_desktop=(
"$base_path"/liquidctl/.config/systemd/user/liquidctl.service
"$base_path"/coolercontrol/.config/systemd/user/coolercontrol.service
)
for systemd_user_unit_desktop in "${systemd_user_units_desktop[@]}"; do
systemd_user_enable_start "${systemd_user_unit_desktop}"
done
fi
# Check if certain submodules get updated, so we don't build them uneccessarily
hackneyed_updated=false
hackneyed_hash_old=$(git -C "$git_submodule_path"/hackneyed-cursor rev-parse --short HEAD)
git submodule update --init --recursive --remote --progress || {
echo "failed to update git submodules"
exit 1
}
git submodule foreach --recursive git clean -xfd || {
echo "failed to clean git submodules"
exit 1
}
git submodule foreach --recursive git reset --hard || {
echo "failed to reset git submodules"
exit 1
}
hackneyed_hash_new=$(git -C "$git_submodule_path"/hackneyed-cursor rev-parse --short HEAD)
if [[ "$hackneyed_hash_old" != "$hackneyed_hash_new" ]]; then
hackneyed_updated=true
echo "hackneyed-cursor has been updated"
fi
if [[ ! -d ~/.oh-my-zsh ]]; then
read -p "Do you need to install ohmyzsh? (${git_submodule_path}/ohmyzsh/tools/install.sh) (y/N)?" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -r -p "Press enter once the the installation is finished... [enter]"
rm -f ~/.zshrc
fi
fi
echo "Copying themes from git repo to dotfiles locations"
# If Hackneyed Dark build does not exist, then build it
if [[ ! -d "$base_path"/gtk/.icons/hackneyed-dark ]] || [[ $hackneyed_updated == true ]]; then
echo "Building hackneyed cursor"
cd "$git_submodule_path"/hackneyed-cursor || {
echo "failed to cd to hackneyed-cursor"
exit 1
}
make clean distclean || {
echo "failed to clean hackneyed cursor"
exit 1
}
make -O DARK_THEME=1 dist || {
echo "failed to make hackneyed cursor"
exit 1
}
rmrf "$base_path"/gtk/.icons/hackneyed-dark
cp -rv "$git_submodule_path"/hackneyed-cursor/Hackneyed-Dark "$base_path"/gtk/.icons/hackneyed-dark # cp instead of ln because the build dir will get reset by git
make clean || {
echo "failed to clean hackneyed make files"
exit 1
}
rm -f ./*.tar.bz2
cd "$base_path" || {
echo "failed to cd to ${base_path}"
exit 1
}
else
echo "Skipping hackneyed cursor build"
fi
# Fix for spacing breaking the space delimited tuples
mv "${git_submodule_path}"/catppuccin-bat/themes/Catppuccin\ Mocha.tmTheme "${git_submodule_path}"/catppuccin-bat/themes/Catppuccin-Mocha.tmTheme || {
echo "failed to move catppuccin-bat theme"
exit 1
}
declare -a symlink_paths_tuples=(
"${git_submodule_path}/alacritty-theme/themes ${base_path}/alacritty/.config/alacritty/themes"
"${git_submodule_path}/catppuccin-bat/themes/Catppuccin-Mocha.tmTheme ${base_path}/bat/.config/bat/themes/Catppuccin-Mocha.tmTheme"
"${git_submodule_path}/catppuccin-helix/themes/default/catppuccin_mocha.toml ${base_path}/helix/.config/helix/themes/catppuccin_mocha.toml"
"${git_submodule_path}/catppuccin-hyprland/themes/mocha.conf ${base_path}/hyprland/.config/hypr/themes/colors.conf"
"${git_submodule_path}/catppuccin-kvantum/themes/catppuccin-mocha-mauve ${base_path}/qt/.config/Kvantum/catppuccin-mocha-mauve"
"${git_submodule_path}/catppuccin-waybar/themes/mocha.css ${base_path}/waybar/.config/waybar/theme.css"
"${git_submodule_path}/sweet-theme/assets ${base_path}/gtk/.themes/Sweet/assets"
"${git_submodule_path}/sweet-theme/gtk-2.0 ${base_path}/gtk/.themes/Sweet/gtk-2.0"
"${git_submodule_path}/sweet-theme/gtk-3.0 ${base_path}/gtk/.themes/Sweet/gtk-3.0"
"${git_submodule_path}/sweet-theme/gtk-4.0 ${base_path}/gtk/.themes/Sweet/gtk-4.0"
"${git_submodule_path}/sweet-theme/index.theme ${base_path}/gtk/.themes/Sweet/index.theme"
"${git_submodule_path}/waybar-crypto/.submodules/cryptofont/fonts/cryptofont.ttf ${base_path}/waybar/.local/share/fonts/TTF/cryptofont.ttf"
)
for symlink_paths_tuple in "${symlink_paths_tuples[@]}"; do
read -ra symlink_paths <<<"$symlink_paths_tuple"
symlink "${symlink_paths[0]}" "${symlink_paths[1]}"
done
declare -a stow_dirs_general=(
alacritty
android
bat
bemenu
cava
chromium
continue
coolercontrol
corectrl
cura
dunst
electron
espanso
fonts
freetube
fuzzel
gallery-dl
gamemode
gammastep
gtk
helix
hyprland
java
kde
khal
logseq
mangohud
mpv
nextcloud
nvim
omz
pass
prusaslicer
qt
ranger
scripts
sway
swww
systemd
thunar
tidal-hifi
ulauncher
vscodium
waybar
wlogout
xdg
yt-dlp
yubikey
)
echo "Stowing general configs"
for stow_dir in "${stow_dirs_general[@]}"; do
echo "Stowing ${stow_dir}"
stow_config "$stow_dir"
done
bat cache --build || {
echo "failed to build bat cache"
exit 1
}
echo "Enabling/Starting Systemd User Units"
systemctl --user daemon-reload || {
echo "failed to userspace systemd daemon-reload"
exit 1
}
declare -a systemd_user_targets=(
"$base_path"/sway/.config/systemd/user/sway-session.target
"$base_path"/hyprland/.config/systemd/user/hypr-session.target
)
for systemd_user_target in "${systemd_user_targets[@]}"; do
systemctl --user link "${systemd_user_target}" || {
echo "failed to enable target ${systemd_user_target}"
exit 1
}
done
declare -a systemd_user_units=(
"$base_path"/corectrl/.config/systemd/user/corectrl.service
"$base_path"/dunst/.config/systemd/user/dunst-wl.service
"$base_path"/espanso/.config/systemd/user/espanso.service
"$base_path"/gammastep/.config/systemd/user/gammastep-wayland.service
"$base_path"/gammastep/.config/systemd/user/geoclue-agent.service
"$base_path"/gtk/.config/systemd/user/xsettingsd.service
"$base_path"/hyprland/.config/systemd/user/hypridle.service
"$base_path"/khal/.config/systemd/user/vdirsyncer-sync.service
"$base_path"/khal/.config/systemd/user/vdirsyncer-sync.timer
"$base_path"/nextcloud/.config/systemd/user/nextcloud-client.service
"$base_path"/sway/.config/systemd/user/kanshi.service
"$base_path"/sway/.config/systemd/user/swayidle.service
"$base_path"/sway/.config/systemd/user/swayosd.service
"$base_path"/sway/.config/systemd/user/wlr-sunclock.service
"$base_path"/swww/.config/systemd/user/swww-daemon.service
"$base_path"/systemd/.config/systemd/user/clipse.service
"$base_path"/systemd/.config/systemd/user/enable-linger.service
"$base_path"/waybar/.config/systemd/user/setup-temps.service
"$base_path"/waybar/.config/systemd/user/waybar.service
/usr/lib/systemd/user/batsignal.service
/usr/lib/systemd/user/gnome-keyring-daemon.socket
/usr/lib/systemd/user/pipewire-pulse.service
/usr/lib/systemd/user/pipewire.service
/usr/lib/systemd/user/wireplumber.service
/usr/lib/systemd/user/yubikey-touch-detector.socket
# /usr/lib/systemd/user/swaync.service
)
for systemd_user_unit in "${systemd_user_units[@]}"; do
systemd_user_enable_start "${systemd_user_unit}"
done
echo "Reloading fonts"
fc-cache || {
echo "Failed to reload fonts"
exit 1
}
echo "Reloading udev rules"
sudo udevadm control --reload-rules || {
echo "Failed to reload udev rules"
exit 1
}
sudo udevadm trigger || {
echo "Failed to trigger udev rules"
exit 1
}