-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·3236 lines (2871 loc) · 122 KB
/
setup.sh
File metadata and controls
executable file
·3236 lines (2871 loc) · 122 KB
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
############################################################## Disabled Shellcheck Messages ##############################################################
# shellcheck disable=SC2012
# Use find instead of ls to better handle non-alphanumeric filenames.
# shellcheck disable=SC1091
# Not following: /etc/os-release: openBinaryFile: does not exist (No such file or directory)
##############################################################
# Hyprland Setup Script
# Based on your Start_system_setup.sh, this script installs
# Hyprland and its dependencies and configures Hyprland tools.
##############################################################
# Constants
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
CHECK_MARK=$'\e[1;32m\u2714\e[0m'
CROSS_MARK=$'\e[1;31m\u2718\e[0m'
CIRCLE=$'\u25CB'
LOG_FILE="${HOME}/Hyprland-Simple-Setup.log"
# Arrays to store update statuses
mirror_updates=()
package_updates=()
aur_updates=()
failed_packages=()
config_statuses=()
# Final summary tracking arrays
SUMMARY_HARD_FAILURES=()
SUMMARY_WARNINGS=()
SUMMARY_SOFT_ERRORS=()
SUMMARY_SKIPPED=()
declare -A _SEEN_RECOMMENDATIONS=()
SUMMARY_RECOMMENDATIONS=()
# Selected AUR helper (paru preferred if available)
AUR_HELPER=""
AUR_HELPER_CHECKED=""
# Initialize DRY_RUN_OPERATIONS array early for all functions
declare -a DRY_RUN_OPERATIONS=()
FISH_LANGUAGE_CHOICE=""
TERMINAL_CHOICE=""
BROWSER_CHOICE=""
SETUP_DIR=Hyprland-Simple-Setup
############################################################## Helper Functions ##############################################################
get_terminal_choice() {
if [ -z "$TERMINAL_CHOICE" ]; then
if [ "$NON_INTERACTIVE" = "true" ]; then
# default to 1 (kitty) if not provided in env
TERMINAL_CHOICE=${TERMINAL_CHOICE_OVERRIDE:-1}
print_verbose "Non-interactive mode: TERMINAL_CHOICE_OVERRIDE='$TERMINAL_CHOICE_OVERRIDE', using TERMINAL_CHOICE='$TERMINAL_CHOICE'"
return
fi
echo "Select your preferred terminal:"
echo "1) kitty (Default)"
echo "2) alacritty"
read -rp "Enter selection number (1-2): " TERMINAL_CHOICE
else
print_verbose "TERMINAL_CHOICE already set to: '$TERMINAL_CHOICE'"
fi
}
get_fish_language_choice() {
if [ -z "$FISH_LANGUAGE_CHOICE" ]; then
if [ "$NON_INTERACTIVE" = "true" ]; then
# default to 1 (de_CH) if not provided in env
FISH_LANGUAGE_CHOICE=${FISH_LANGUAGE_CHOICE_OVERRIDE:-1}
print_verbose "Non-interactive mode: FISH_LANGUAGE_CHOICE_OVERRIDE='$FISH_LANGUAGE_CHOICE_OVERRIDE', using FISH_LANGUAGE_CHOICE='$FISH_LANGUAGE_CHOICE'"
return
fi
echo "Select your preferred language setting for Fish Shell:"
echo "1) de_CH (Default: LANG=de_CH.UTF-8, LANGUAGE=de_CH:en_US)"
echo "2) de (German: LANG=de_DE.UTF-8, LANGUAGE=de_DE:en_US)"
echo "3) us (US English: LANG=en_US.UTF-8, LANGUAGE=en_US:de_CH)"
read -rp "Enter selection number (1-3): " FISH_LANGUAGE_CHOICE
else
print_verbose "FISH_LANGUAGE_CHOICE already set to: '$FISH_LANGUAGE_CHOICE'"
fi
}
get_browser_choice() {
if [ -z "$BROWSER_CHOICE" ]; then
if [ "$NON_INTERACTIVE" = "true" ]; then
# default to 1 (zen-browser) if not provided in env
BROWSER_CHOICE=${BROWSER_CHOICE_OVERRIDE:-1}
print_verbose "Non-interactive mode: BROWSER_CHOICE_OVERRIDE='$BROWSER_CHOICE_OVERRIDE', using BROWSER_CHOICE='$BROWSER_CHOICE'"
return
fi
echo "Select your preferred browser:"
echo "1) zen-browser (Default)"
echo "2) vivaldi"
read -rp "Enter selection number (1-2): " BROWSER_CHOICE
else
print_verbose "BROWSER_CHOICE already set to: '$BROWSER_CHOICE'"
fi
}
is_windows() {
case "$(uname -s)" in
*CYGWIN*|*MINGW*|*MSYS*|*Windows_NT*) return 0 ;;
*) return 1 ;;
esac
}
is_dry_run() {
if is_windows; then
print_warning "Running on Windows - forcing dry-run mode"
return 0
fi
[[ "$DRY_RUN" == "true" ]]
}
log_dry_run_operation() {
local function_name="$1"
local operation="$2"
DRY_RUN_OPERATIONS+=("[$function_name] $operation")
}
should_init_dotfiles_git_repo() {
# 1) Explicit CLI flag wins
if [ "${INIT_DOTFILES_GIT_REPO:-false}" = "true" ]; then
return 0
fi
# 2) Environment variable override (useful for non-interactive runs)
case "${DOTFILES_GIT_INIT:-}" in
1|true|yes|y|Y) return 0 ;;
0|false|no|n|N) return 1 ;;
esac
# 3) Interactive prompt (default yes); non-interactive defaults to no
if [ "${NON_INTERACTIVE:-false}" = "true" ]; then
return 1
fi
if prompt_yes_no "Initialize a local git repo in \$HOME/dotfiles (no remote) after setup?"; then
return 0
fi
return 1
}
init_dotfiles_git_repo() {
local dotfiles_dir="$HOME/dotfiles"
local repo_git_dir="$dotfiles_dir/.git"
if ! should_init_dotfiles_git_repo; then
print_verbose "Dotfiles git init skipped (not enabled)"
return 0
fi
if [ ! -d "$dotfiles_dir" ]; then
print_warning "Dotfiles directory not found at $dotfiles_dir; skipping git init."
return 0
fi
if [ -d "$repo_git_dir" ]; then
print_message "Dotfiles already have a git repo at $repo_git_dir; skipping git init."
return 0
fi
if ! command -v git >/dev/null 2>&1; then
print_warning "git not found; skipping dotfiles git repo initialization."
return 0
fi
if is_dry_run; then
log_dry_run_operation "init_dotfiles_git_repo" "Would init local git repo in $dotfiles_dir and create initial commit"
return 0
fi
print_message "Initializing local git repo in $dotfiles_dir"
if ! (cd "$dotfiles_dir" && git init -q); then
print_warning "Failed to init git repo in $dotfiles_dir"
return 1
fi
# Ensure local identity is set (avoid touching global git config)
local existing_name existing_email
existing_name=$(git -C "$dotfiles_dir" config --get user.name || true)
existing_email=$(git -C "$dotfiles_dir" config --get user.email || true)
if [ -z "$existing_name" ]; then
git -C "$dotfiles_dir" config user.name "$USER" || true
fi
if [ -z "$existing_email" ]; then
local host
host="$(hostname 2>/dev/null || echo "localhost")"
git -C "$dotfiles_dir" config user.email "${USER}@${host}" || true
fi
# Initial snapshot commit
if ! (cd "$dotfiles_dir" && git add -A); then
print_warning "Failed to stage dotfiles in $dotfiles_dir"
return 1
fi
if git -C "$dotfiles_dir" diff --cached --quiet; then
print_message "Dotfiles repo has nothing to commit (already clean)."
return 0
fi
if ! (cd "$dotfiles_dir" && git commit -q -m "Initial dotfiles snapshot"); then
print_warning "Failed to create initial commit in $dotfiles_dir"
return 1
fi
print_message "Local dotfiles git repo created at $repo_git_dir"
}
execute_command() {
local cmd="$1"
local description="$2"
local caller_function="${FUNCNAME[1]}"
print_verbose "About to execute: $cmd (Description: $description)"
# Regular command handling
if is_dry_run; then
echo -e "${YELLOW}[DRY-RUN]${NC} Would execute: $cmd"
echo -e "${YELLOW}[DRY-RUN]${NC} Description: $description"
log_dry_run_operation "$caller_function" "$description"
sleep 0.05
return 0
else
# Prefer using provided SUDO_PASSWORD to avoid prompts; fallback to -n in NON_INTERACTIVE
local adjusted_cmd="$cmd"
if [ -n "$SUDO_PASSWORD" ]; then
# Define a shell sudo() that feeds the password to sudo -S
bash -c 'sudo() { echo -n "$SUDO_PASSWORD" | command sudo -S "$@"; }; '"$adjusted_cmd"
else
if [ "$NON_INTERACTIVE" = "true" ]; then
adjusted_cmd="${adjusted_cmd//sudo /sudo -n }"
fi
bash -c "$adjusted_cmd"
fi
local exit_code=$?
print_verbose "Command executed: ${adjusted_cmd} (Exit code: $exit_code)"
if [ $exit_code -ne 0 ]; then
print_warning "Command for '$description' failed."
record_soft_error "$caller_function" "$description"
fi
# Throttle UI output similarly to dry-run
sleep 0.05
return $exit_code
fi
}
prompt_yes_no() {
local prompt="$1"
# Non-interactive shortcut: default to PROMPT_DEFAULT_YN (defaults to 'y')
if [ "$NON_INTERACTIVE" = "true" ]; then
case "${PROMPT_DEFAULT_YN:-y}" in
[Yy]*) return 0 ;;
*) return 1 ;;
esac
fi
while true; do
read -rp "$prompt (y/n): " yn
# Default to 'Yy' if nothing is entered
if [[ -z "$yn" ]]; then
yn="y"
fi
case $yn in
[Yy]*) return 0 ;;
[Nn]*) return 1 ;;
*) echo "Please answer yes or no." ;;
esac
done
}
# Global confirmation gate (auto-accept in non-interactive mode)
user_confirmation() {
if [ "$NON_INTERACTIVE" = "true" ]; then
print_message "Non-interactive mode: auto-confirmed."
return 0
fi
if prompt_yes_no "Proceed with Hyprland setup?"; then
return 0
else
print_error "Setup aborted by user"
exit 1
fi
}
# Capture or validate sudo password once; in NON_INTERACTIVE mode a password must be provided via SUDO_PASSWORD
setup_sudo_password() {
if [ -z "$SUDO_PASSWORD" ]; then
if [ "$NON_INTERACTIVE" = "true" ]; then
handle_error "SUDO_PASSWORD not provided in non-interactive mode."
fi
read -rsp "Enter sudo password (used for this setup only): " SUDO_PASSWORD
echo ""
export SUDO_PASSWORD
fi
}
announce_step() {
local step="$1"
echo -e "\n${GREEN}=== $step ===${NC}\n"
}
extended_announce_step() {
local step="$1"
echo -e "\n${GREEN}========= $step =========${NC}\n"
}
print_dry_run_summary() {
if [ ${#DRY_RUN_OPERATIONS[@]} -eq 0 ]; then
echo -e "\n${YELLOW}[DRY-RUN SUMMARY]${NC} No operations were recorded."
return
fi
echo -e "\n${YELLOW}[DRY-RUN SUMMARY]${NC} The following operations would have been performed:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
local current_function=""
local count=0
for operation in "${DRY_RUN_OPERATIONS[@]}"; do
# Extract function name from the operation string
local function_name
function_name=$(echo "$operation" | cut -d']' -f1 | sed 's/\[//')
local op_description
op_description=$(echo "$operation" | cut -d']' -f2- | sed 's/^ //')
# Print function header when we move to a new function
if [[ "$function_name" != "$current_function" ]]; then
if [[ -n "$current_function" ]]; then
echo " Total: $count operation(s)"
echo ""
fi
echo -e "${GREEN}▶ $function_name${NC}"
current_function="$function_name"
count=0
fi
# Print the operation description
echo " • $op_description"
((count++))
done
# Print the count for the last function
if [[ -n "$current_function" ]]; then
echo " Total: $count operation(s)"
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "${YELLOW}[DRY-RUN]${NC} No actual changes were made to your system."
}
distro_install() {
local -a packages
packages=("$@")
case "$DISTRO" in
debian|ubuntu)
execute_command "sudo apt install -y ${packages[*]}" "Install packages: ${packages[*]}"
;;
fedora)
execute_command "sudo dnf install -y ${packages[*]}" "Install packages: ${packages[*]}"
;;
arch|endeavouros|cachyos)
if ! execute_command "sudo pacman -S --needed --noconfirm ${packages[*]}" "Install packages: ${packages[*]}"; then
check_yay
print_warning "pacman failed, trying ${AUR_HELPER:-AUR helper} as fallback for: ${packages[*]}"
if [ -n "$AUR_HELPER" ] && execute_command "$AUR_HELPER -S --needed --noconfirm ${packages[*]}" "Install packages with $AUR_HELPER: ${packages[*]}"; then
print_message "$AUR_HELPER fallback install succeeded for: ${packages[*]}"
fi
fi
;;
*)
print_warning "Distro '$DISTRO' not supported for package installation."
return 1
;;
esac
}
# Check if all packages of a pacman group are installed (e.g., base-devel)
is_pacman_group_installed() {
local group="$1"
# Only applicable on Arch-based systems with pacman
if ! command -v pacman >/dev/null 2>&1; then
return 1
fi
# Get group members
local pkgs
pkgs=$(pacman -Sgq "$group" 2>/dev/null) || return 1
# If no packages found for the group, treat as not installed
[ -z "$pkgs" ] && return 1
# Verify each package is installed
local pkg
for pkg in $pkgs; do
if ! pacman -Qq "$pkg" &>/dev/null; then
return 1
fi
done
return 0
}
# Detect first Hyprland monitor name from `hyprctl monitors`
get_first_hypr_monitor() {
command -v hyprctl >/dev/null 2>&1 || return 1
# Be tolerant to any leading whitespace in hyprctl output
hyprctl monitors 2>/dev/null | awk '/^[[:space:]]*Monitor /{print $2; exit}'
}
# Ensure MONITORS is set in wallpaper config; if missing/placeholder, set to first monitor.
# Accepts an optional path to a change_wallpaper.conf; defaults to the runtime config under ~/.config.
ensure_wallpaper_monitors() {
local wallpaper_conf="${1:-$HOME/.config/hypr/sources_specific/change_wallpaper.conf}"
[ -f "$wallpaper_conf" ] || return 0
# Read existing MONITORS line if any
local current_line
current_line=$(grep -E '^[[:space:]]*MONITORS=' "$wallpaper_conf" 2>/dev/null || true)
# Decide if we need to set/update (no line, empty array, or contains placeholder MONITOR_N)
local need_set=false
if [ -z "$current_line" ]; then
need_set=true
elif echo "$current_line" | grep -qE 'MONITORS=\(\)'; then
need_set=true
elif echo "$current_line" | grep -qE 'MONITOR_[0-9]'; then
need_set=true
fi
if [ "$need_set" = true ]; then
local first_mon
first_mon=$(get_first_hypr_monitor || true)
if [ -z "$first_mon" ]; then
print_warning "Could not auto-detect a monitor via hyprctl; leaving MONITORS unchanged."
return 0
fi
print_message "Auto-detected monitor: $first_mon"
if echo "$current_line" | grep -q 'MONITORS='; then
execute_command "sed -i --follow-symlinks -E 's|^MONITORS=.*$|MONITORS=(\"$first_mon\")|' '$wallpaper_conf'" "Set MONITORS to first detected monitor"
else
execute_command "printf '%s\n' 'MONITORS=(\"$first_mon\")' >> '$wallpaper_conf'" "Append MONITORS to wallpaper config"
fi
fi
}
# Get ALL Hyprland monitor names (one per line).
get_all_hypr_monitors() {
command -v hyprctl >/dev/null 2>&1 || return 1
hyprctl monitors 2>/dev/null | awk '/^[[:space:]]*Monitor /{print $2}'
}
# Auto-populate monitors.conf when it contains no active (uncommented) monitor= lines.
# Generates a basic monitor=NAME,preferred,auto,1 entry for each detected monitor.
ensure_monitors_conf() {
local monitors_conf="${1:-$HOME/.config/hypr/sources_specific/monitors.conf}"
[ -f "$monitors_conf" ] || return 0
# Check if there are already active monitor= lines
if grep -qE '^[[:space:]]*monitor=' "$monitors_conf" 2>/dev/null; then
return 0
fi
local monitor_names
monitor_names=$(get_all_hypr_monitors || true)
if [ -z "$monitor_names" ]; then
print_warning "Could not auto-detect monitors via hyprctl; leaving monitors.conf unchanged."
return 0
fi
print_message "Auto-populating monitors.conf with detected monitors..."
local all_names=()
local monitor_lines=()
local x_offset=0
while IFS= read -r mon_name; do
[ -z "$mon_name" ] && continue
all_names+=("$mon_name")
local width
width=$(hyprctl monitors 2>/dev/null | awk -v name="$mon_name" '
/^[[:space:]]*Monitor /{found=($2==name)}
found && /^[[:space:]]*[0-9]+x[0-9]+@/{split($1,a,"x"); split(a[2],b,"@"); print a[1]; exit}
')
if ! [[ "${width:-}" =~ ^[0-9]+$ ]]; then
width=0
fi
local pos="${x_offset}x0"
monitor_lines+=("monitor=${mon_name},preferred,${pos},1")
print_message " Added monitor=${mon_name},preferred,${pos},1"
x_offset=$((x_offset + width))
done <<< "$monitor_names"
# Append in detected order (avoid reversing via repeated "insert at top").
if [ "${#monitor_lines[@]}" -gt 0 ]; then
{
echo
printf '%s\n' "${monitor_lines[@]}"
} >> "$monitors_conf"
fi
# Add workspace assignments for detected monitors
if [ "${#all_names[@]}" -gt 0 ]; then
local primary="${all_names[0]}"
local secondary="${all_names[1]:-$primary}"
printf '\nworkspace=1,monitor:%s,default:true\n' "$primary" >> "$monitors_conf"
if [ "${#all_names[@]}" -gt 1 ]; then
printf 'workspace=2,monitor:%s\n' "$secondary" >> "$monitors_conf"
fi
fi
}
# Apply MONITOR_CONFIG directly (name:resolution:scale;...) without requiring
# a live Hyprland session. This is primarily used by non-interactive/TUI runs.
apply_monitor_config_from_env() {
local monitor_config="${MONITOR_CONFIG:-}"
[ -n "$monitor_config" ] || return 1
local hyprland_setup_dir=""
hyprland_setup_dir="$(find_hyprland_setup_dir || true)"
local monitor_targets=(
"$HOME/.config/hypr/sources_specific/monitors.conf"
"$HOME/dotfiles/.config/hypr/sources_specific/monitors.conf"
)
local wallpaper_targets=(
"$HOME/.config/hypr/sources_specific/change_wallpaper.conf"
"$HOME/dotfiles/.config/hypr/sources_specific/change_wallpaper.conf"
)
if [ -n "$hyprland_setup_dir" ]; then
monitor_targets+=("$hyprland_setup_dir/dotfiles/.config/hypr/sources_specific/monitors.conf")
wallpaper_targets+=("$hyprland_setup_dir/dotfiles/.config/hypr/sources_specific/change_wallpaper.conf")
fi
local entry
local parsed_any=false
local x_offset=0
local monitor_lines=()
local monitor_names=()
IFS=';' read -ra entries <<< "$monitor_config"
for entry in "${entries[@]}"; do
[ -z "$entry" ] && continue
local nm cfg sc
nm="${entry%%:*}"
cfg="${entry#*:}"
sc="${cfg##*:}"
cfg="${cfg%:*}"
if [ -z "$nm" ] || [ -z "$cfg" ] || [ -z "$sc" ]; then
continue
fi
local width="${cfg%%x*}"
if ! [[ "$width" =~ ^[0-9]+$ ]]; then
width=0
fi
local offset="${x_offset}x0"
monitor_lines+=("monitor=${nm},${cfg},${offset},${sc}")
monitor_names+=("$nm")
parsed_any=true
x_offset=$((x_offset + width))
done
if [ "$parsed_any" != true ]; then
print_warning "MONITOR_CONFIG is set but could not be parsed: $monitor_config"
return 1
fi
local workspace_lines=()
if [ "${#monitor_names[@]}" -gt 0 ]; then
workspace_lines+=("workspace=1,monitor:${monitor_names[0]},default:true")
fi
if [ "${#monitor_names[@]}" -gt 1 ]; then
workspace_lines+=("workspace=2,monitor:${monitor_names[1]}")
fi
local mt
for mt in "${monitor_targets[@]}"; do
mkdir -p "$(dirname "$mt")"
{
echo "# Check monitor names (e.g. DP-1, HDMI-A-1) with: \`hyprctl monitors\`"
for line in "${monitor_lines[@]}"; do
echo "$line"
done
if [ "${#workspace_lines[@]}" -gt 0 ]; then
echo
for line in "${workspace_lines[@]}"; do
echo "$line"
done
fi
} > "$mt"
print_message "Applied MONITOR_CONFIG to $(basename "$mt")"
done
local monitors_str=""
local m
for m in "${monitor_names[@]}"; do
monitors_str+="\"$m\" "
done
monitors_str=$(echo "$monitors_str")
local wt
for wt in "${wallpaper_targets[@]}"; do
[ -f "$wt" ] || continue
if grep -q "^MONITORS=" "$wt"; then
sed -i --follow-symlinks "s|^MONITORS=.*|MONITORS=($monitors_str)|" "$wt"
else
echo "MONITORS=($monitors_str)" >> "$wt"
fi
print_message "Applied MONITORS to $(basename "$wt"): MONITORS=($monitors_str)"
done
return 0
}
############################################################## Verbosity and Error Handling Functions ##############################################################
print_verbose() {
if [[ "$VERBOSE" == "true" ]]; then
echo -e "${YELLOW}[VERBOSE]${NC} $1"
fi
}
handle_error() {
local msg="$1"
log_message "ERROR" "$msg"
echo -e "${RED}[ERROR]${NC} $msg"
exit 1
}
log_message() {
local log_level=$1
local message=$2
local timestamp
timestamp=$(date +"%Y-%m-%d %T")
echo "[$timestamp] [$log_level] $message" >> "$LOG_FILE"
}
# Function to print colored messages
print_message() {
log_message "DEBUG" "$1" # Log the debug message
echo -e "${GREEN}[*] $1${NC}"
}
print_warning() {
log_message "WARNING" "$1" # Log the warning message
echo -e "${YELLOW}[!] $1${NC}"
}
print_error() {
log_message "ERROR" "$1" # Log the error message
echo -e "${RED}[ERROR] $1${NC}"
}
print_status_summary() {
echo -e "\n${GREEN}========= Installation Summary =========${NC}"
echo "Log file: $LOG_FILE"
# Package installation results
if [ ${#failed_packages[@]} -gt 0 ]; then
echo -e "${RED}Failed packages:${NC}"
for pkg in "${failed_packages[@]}"; do
echo " - $pkg"
done
else
echo -e "${GREEN}All packages installed successfully!${NC}"
fi
# Configuration results
if [ ${#config_statuses[@]} -gt 0 ]; then
echo -e "\n${YELLOW}Configuration Status:${NC}"
for status in "${config_statuses[@]}"; do
echo -e " $status"
done
# Count failed configurations
local failed_count=0
for status in "${config_statuses[@]}"; do
if [[ "$status" == *"$CROSS_MARK"* ]]; then
((failed_count++))
fi
done
if [ "$failed_count" -gt 0 ]; then
print_warning "Total failed configurations: $failed_count"
else
print_message "All configurations completed successfully!"
fi
else
print_message "No configurations were processed"
fi
# Package verification
echo -e "\n${GREEN}Package Verification:${NC}"
verify_installed_packages
}
track_config_status() {
local config_name="$1"
local status="$2"
config_statuses+=("$config_name: $status")
}
record_hard_failure() {
local step="$1" detail="$2"
SUMMARY_HARD_FAILURES+=("[$step] $detail")
}
record_warning() {
local step="$1" detail="$2"
SUMMARY_WARNINGS+=("[$step] $detail")
}
record_soft_error() {
local step="$1" detail="$2"
SUMMARY_SOFT_ERRORS+=("[$step] $detail")
}
record_skipped() {
local step="$1" detail="$2"
SUMMARY_SKIPPED+=("[$step] $detail")
}
add_recommendation_once() {
local msg="$1"
if [[ -z "${_SEEN_RECOMMENDATIONS[$msg]+_}" ]]; then
_SEEN_RECOMMENDATIONS[$msg]=1
SUMMARY_RECOMMENDATIONS+=("$msg")
fi
}
build_summary_recommendations() {
local entry
for entry in "${SUMMARY_HARD_FAILURES[@]}"; do
case "$entry" in
*"install_pacman_packages"*)
add_recommendation_once "Re-run failed pacman installs: sudo pacman -S --needed <package>"
;;
*"install_aur_extras"*)
add_recommendation_once "Re-run failed AUR installs: ${AUR_HELPER:-paru} -S --needed <package>"
;;
*"update_arch_mirrors"*)
add_recommendation_once "Update mirrors manually: sudo reflector --verbose --protocol https --sort rate --latest 20 --save /etc/pacman.d/mirrorlist"
;;
*"configure_bluetooth"*)
add_recommendation_once "Check bluetooth: sudo systemctl status bluetooth && sudo systemctl enable --now bluetooth"
;;
*"configure_fish"*)
add_recommendation_once "Set shell manually: sudo chsh -s /usr/bin/fish \$USER"
;;
*"configure_network_manager"*)
add_recommendation_once "Enable NetworkManager: sudo systemctl enable --now NetworkManager"
;;
*"configure_environment"*"Neovim"*)
add_recommendation_once "Install Neovim manually: sudo pacman -S neovim"
;;
*"configure_timeshift"*)
add_recommendation_once "Set up Timeshift manually: sudo pacman -S timeshift && sudo systemctl enable --now cronie.service"
;;
esac
done
for entry in "${SUMMARY_SOFT_ERRORS[@]}"; do
case "$entry" in
*"update_arch_mirrors"*)
add_recommendation_once "Retry mirror update: sudo reflector --verbose --protocol https --sort rate --latest 20 --save /etc/pacman.d/mirrorlist"
;;
*"update_pacman"*)
add_recommendation_once "Retry system update: sudo pacman -Syyu"
;;
*"update_yay"*)
add_recommendation_once "Retry AUR update: ${AUR_HELPER:-paru} -Sua"
;;
*"enable_sddm"*)
add_recommendation_once "Enable SDDM manually: sudo systemctl enable sddm"
;;
*"EDITOR"*)
add_recommendation_once "Set EDITOR manually: systemctl --user set-environment EDITOR=nvim"
;;
*"configure_timeshift"*)
add_recommendation_once "Create Timeshift snapshot manually: sudo timeshift --create --tags D"
;;
esac
done
for entry in "${SUMMARY_WARNINGS[@]}"; do
case "$entry" in
*"wallpaper"*|*"Wallpaper"*)
add_recommendation_once "Verify wallpaper directory exists and contains images for swww/hyprpaper"
;;
*"backup"*|*"Backup"*)
add_recommendation_once "Create a manual backup of ~/.config before making further changes"
;;
*"workspace 11"*)
add_recommendation_once "Remove workspace 11 entries from Hyprland/Waybar configs to avoid phantom workspaces"
;;
*"PAM"*|*"gnome-keyring"*)
add_recommendation_once "Verify PAM config: check /etc/pam.d/system-local-login for pam_gnome_keyring.so entries"
;;
*"xdg-user-dirs"*)
add_recommendation_once "Run xdg-user-dirs-update manually to create standard user directories"
;;
esac
done
if [ ${#SUMMARY_HARD_FAILURES[@]} -gt 0 ]; then
add_recommendation_once "Review the full log for details: $LOG_FILE"
fi
}
print_final_recommendation_summary() {
local total=$(( ${#SUMMARY_HARD_FAILURES[@]} + ${#SUMMARY_WARNINGS[@]} + ${#SUMMARY_SOFT_ERRORS[@]} + ${#SUMMARY_SKIPPED[@]} ))
echo ""
echo -e "${GREEN}╔══════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ Final Setup Report ║${NC}"
echo -e "${GREEN}╚══════════════════════════════════════════════════════════╝${NC}"
if [ "$total" -eq 0 ]; then
echo -e "${GREEN}Everything completed without issues.${NC}"
echo ""
return
fi
if [ ${#SUMMARY_HARD_FAILURES[@]} -gt 0 ]; then
echo ""
echo -e "${RED}Hard Failures (${#SUMMARY_HARD_FAILURES[@]}):${NC}"
for entry in "${SUMMARY_HARD_FAILURES[@]}"; do
echo -e " ${RED}$CROSS_MARK${NC} $entry"
done
fi
if [ ${#SUMMARY_SOFT_ERRORS[@]} -gt 0 ]; then
echo ""
echo -e "${YELLOW}Soft Errors (${#SUMMARY_SOFT_ERRORS[@]}):${NC}"
for entry in "${SUMMARY_SOFT_ERRORS[@]}"; do
echo -e " ${YELLOW}!${NC} $entry"
done
fi
if [ ${#SUMMARY_WARNINGS[@]} -gt 0 ]; then
echo ""
echo -e "${YELLOW}Warnings (${#SUMMARY_WARNINGS[@]}):${NC}"
for entry in "${SUMMARY_WARNINGS[@]}"; do
echo -e " ${YELLOW}~${NC} $entry"
done
fi
if [ ${#SUMMARY_SKIPPED[@]} -gt 0 ]; then
echo ""
echo -e "Skipped Steps (${#SUMMARY_SKIPPED[@]}):"
for entry in "${SUMMARY_SKIPPED[@]}"; do
echo " $CIRCLE $entry"
done
fi
build_summary_recommendations
if [ ${#SUMMARY_RECOMMENDATIONS[@]} -gt 0 ]; then
echo ""
echo -e "${GREEN}Recommendations:${NC}"
local i=1
for rec in "${SUMMARY_RECOMMENDATIONS[@]}"; do
echo -e " ${i}. $rec"
((i++))
done
fi
echo ""
echo "Log file: $LOG_FILE"
echo ""
}
list_packages() {
announce_step "Generating Package Lists"
local date_suffix packages_file aur_file is_endeavouros is_debian_based
date_suffix=$(date +%Y-%m-%d)
packages_file="$HOME/user_installed_packages_${date_suffix}.txt"
aur_file="$HOME/aur_packages_${date_suffix}.txt"
is_endeavouros=false
is_debian_based=false
if command -v eos-packagelist &> /dev/null && grep -q "EndeavourOS" /etc/os-release; then
is_endeavouros=true
print_message "EndeavourOS detected - will exclude default EndeavourOS packages."
elif grep -q "CachyOS" /etc/os-release; then
is_endeavouros=true
print_message "CachyOS detected - will exclude default CachyOS packages."
elif command -v apt &> /dev/null && (grep -q "Debian\\|Ubuntu\\|Mint" /etc/os-release || [ -f /etc/debian_version ]); then
is_debian_based=true
print_message "Debian-based system detected - will list manually installed packages."
else
print_message "Arch Linux detected - will list all explicitly installed packages."
fi
print_message "This utility will generate:"
print_message " 1. A list of manually installed packages"
if [ "$is_endeavouros" = true ]; then
print_message " (excluding EndeavourOS default packages)"
elif [ "$is_debian_based" = true ]; then
print_message " (using apt-mark showmanual)"
fi
print_message " 2. A separate list of AUR packages"
if [ "$is_debian_based" = true ]; then
print_message " (not applicable on Debian-based systems)"
fi
print_message "Generating package lists..."
if [ "$is_endeavouros" = true ]; then
echo -e "# User installed packages (excluding EndeavourOS defaults)" > "$packages_file"
elif [ "$is_debian_based" = true ]; then
echo -e "# Manually installed packages on Debian-based system" > "$packages_file"
else
echo -e "# User installed packages on Arch Linux" > "$packages_file"
fi
echo -e "# Generated on: $(date)\n" >> "$packages_file"
if [ "$is_debian_based" = false ]; then
echo -e "# AUR packages installed on the system" > "$aur_file"
echo -e "# Generated on: $(date)\n" >> "$aur_file"
fi
print_message "Processing main package list..."
if [ "$is_endeavouros" = true ]; then
execute_command "comm -23 <(pacman -Qqet | sort) <(eos-packagelist KDE-Desktop 'EndeavourOS applications' 'Recommended applications selection' 'Spell Checker and language package' 'Firewall' 'LTS kernel in addition' 'Printing support' 'HP printer/scanner support' | sort) >> '$packages_file'" "List user packages (EndeavourOS)"
elif [ "$is_debian_based" = true ]; then
execute_command "apt-mark showmanual >> '$packages_file'" "List manually installed packages (Debian)"
else
execute_command "pacman -Qqet >> '$packages_file'" "List explicitly installed packages (Arch)"
fi
print_message "Main package list done."
if [ "$is_debian_based" = false ]; then
print_message "Processing AUR package list..."
execute_command "pacman -Qqm >> '$aur_file'" "List AUR packages"
print_message "AUR package list done."
fi
print_message "Package lists have been saved to:"
print_message " Main package list: $packages_file"
print_message " AUR package list: $aur_file"
print_message "Total packages found: $(grep -v '^#' "$packages_file" | wc -l)"
print_message "Total AUR packages found: $(grep -v '^#' "$aur_file" | wc -l)"
print_message "Thank you for using the Package Installation History Utility!"
}
verify_installed_packages() {
extended_announce_step "Verifying installed packages"
# In dry-run, skip verification entirely (execute_command would always succeed)
if is_dry_run; then
log_dry_run_operation "verify_installed_packages" "Would verify installed packages via pacman/AUR helper"
print_message "Dry-run: skipping package verification"
return 0
fi
# Find the newest package list files
local user_pkg_file
user_pkg_file=$(ls -t "$HOME"/user_installed_packages_* 2>/dev/null | head -n1)
local aur_pkg_file
aur_pkg_file=$(ls -t "$HOME"/aur_packages_* 2>/dev/null | head -n1)
if [ -z "$user_pkg_file" ] && [ -z "$aur_pkg_file" ]; then
print_message "No package list files found in $HOME. Generating new package lists..."
list_packages
# Re-find the files after generation
user_pkg_file=$(ls -t "$HOME"/user_installed_packages_* 2>/dev/null | head -n1)
aur_pkg_file=$(ls -t "$HOME"/aur_packages_* 2>/dev/null | head -n1)
if [ -z "$user_pkg_file" ] && [ -z "$aur_pkg_file" ]; then
print_error "Failed to generate package list files."
track_config_status "Package Verification" "$CROSS_MARK"
return 1
fi
fi
local missing_packages=()
local missing_pacman=()
local missing_aur=()
local total_checked=0
# Check standard packages
if [ -n "$user_pkg_file" ]; then
print_message "Checking packages from: $(basename "$user_pkg_file")"
while IFS= read -r package; do
# Skip empty lines and comments
[[ -z "$package" || "$package" =~ ^[[:space:]]*# ]] && continue
((total_checked++))
if ! execute_command "pacman -Qi '$package' >/dev/null 2>&1" "Check installed: $package"; then
missing_packages+=("$package (Pacman)")
missing_pacman+=("$package")
fi
done < "$user_pkg_file"
fi
# Check AUR packages
if [ -n "$aur_pkg_file" ]; then
print_message "Checking packages from: $(basename "$aur_pkg_file")"
while IFS= read -r package; do
# Skip empty lines and comments
[[ -z "$package" || "$package" =~ ^[[:space:]]*# ]] && continue
((total_checked++))
if ! execute_command "pacman -Qi '$package' >/dev/null 2>&1" "Check installed: $package (AUR)"; then
missing_packages+=("$package (AUR)")
missing_aur+=("$package")
fi