-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·1563 lines (1346 loc) · 51.5 KB
/
install.sh
File metadata and controls
executable file
·1563 lines (1346 loc) · 51.5 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
# CVH Linux Installer
# Run from live environment to install CVH Linux to disk
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m'
# Progress tracking
TOTAL_STEPS=10
CURRENT_STEP=0
# Global variables
DISK=""
BOOT_MODE=""
EFI_PART=""
ROOT_PART=""
USERNAME="cvh"
HOSTNAME="cvh-linux"
TIMEZONE="Asia/Jerusalem"
LOCALE="en_US.UTF-8"
KEYMAP="us"
COMPOSITOR="" # Will be "niri" or "hyprland"
# ─────────────────────────────────────────────────────────────────
# Usage / Help
# ─────────────────────────────────────────────────────────────────
usage() {
echo -e "${BOLD}${CYAN}CVH Linux Installer${NC}"
echo
echo -e "${BOLD}USAGE:${NC}"
echo -e " sudo bash install.sh [OPTIONS]"
echo
echo -e "${BOLD}OPTIONS:${NC}"
echo -e " ${GREEN}-h, --help${NC} Show this help message and exit"
echo -e " ${GREEN}-v, --version${NC} Show installer version and exit"
echo -e " ${GREEN}--disk <device>${NC} Pre-select target disk (e.g. /dev/sda)"
echo -e " ${GREEN}--user <name>${NC} Pre-set username (default: cvh)"
echo -e " ${GREEN}--hostname <name>${NC} Pre-set hostname (default: cvh-linux)"
echo -e " ${GREEN}--timezone <tz>${NC} Pre-set timezone (e.g. Europe/Istanbul)"
echo -e " ${GREEN}--compositor <wm>${NC} Pre-select compositor: ${CYAN}niri${NC} or ${CYAN}hyprland${NC}"
echo -e " ${GREEN}--keymap <map>${NC} Pre-set keyboard layout (e.g. us, de, fr)"
echo
echo -e "${BOLD}EXAMPLES:${NC}"
echo -e " ${DIM}# Interactive install (recommended)${NC}"
echo -e " sudo bash install.sh"
echo
echo -e " ${DIM}# Pre-select disk and compositor${NC}"
echo -e " sudo bash install.sh --disk /dev/sda --compositor niri"
echo
echo -e " ${DIM}# Fully pre-configured install${NC}"
echo -e " sudo bash install.sh --disk /dev/nvme0n1 --user john \\"
echo -e " --hostname my-cvh --timezone Europe/Istanbul \\"
echo -e " --compositor hyprland --keymap us"
echo
echo -e "${BOLD}NOTES:${NC}"
echo -e " ${YELLOW}⚠${NC} Must be run as ${BOLD}root${NC} from a live environment"
echo -e " ${YELLOW}⚠${NC} The selected disk will be ${RED}completely erased${NC}"
echo -e " ${YELLOW}⚠${NC} Network connection is required for package installation"
echo
echo -e "${BOLD}COMPOSITORS:${NC}"
echo -e " ${CYAN}niri${NC} Scrollable-tiling Wayland compositor"
echo -e " ${CYAN}hyprland${NC} Dynamic tiling Wayland compositor"
echo
}
show_version() {
echo -e "${BOLD}CVH Linux Installer${NC} v1.0.0"
echo -e "CodeVerse Hub Linux Distribution"
}
# ─────────────────────────────────────────────────────────────────
# Argument Parsing
# ─────────────────────────────────────────────────────────────────
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-v|--version)
show_version
exit 0
;;
--disk)
if [[ -z "${2:-}" ]]; then
echo -e "${RED}[ERROR]${NC} --disk requires a device path (e.g. /dev/sda)"
echo -e " Run ${CYAN}sudo bash install.sh --help${NC} for usage."
exit 1
fi
if [[ ! -b "$2" ]]; then
echo -e "${RED}[ERROR]${NC} '$2' is not a valid block device."
echo -e " Available disks:"
lsblk -dno NAME,SIZE,MODEL | grep -vE "^(loop|sr|rom|fd|zram)" | \
awk '{printf " /dev/%-10s %s\n", $1, $2}'
echo -e " Run ${CYAN}sudo bash install.sh --help${NC} for usage."
exit 1
fi
# Block partitions ,only allow whole disks
if [[ "$2" =~ [0-9]$ ]] && [[ -n "$(lsblk -dno PKNAME "$2" 2>/dev/null)" ]]; then
echo -e "${RED}[ERROR]${NC} '$2' appears to be a partition, not a whole disk."
echo -e " Please specify the parent disk instead (e.g. /dev/sda, /dev/nvme0n1)."
echo -e " Available disks :-"
lsblk -dno NAME,SIZE,MODEL | grep -vE "^(loop|sr|rom|fd|zram)" | \
awk '{printf " /dev/%-10s %s\n", $1, $2}'
exit 1
fi
# Block selecting the live boot disk
if is_live_boot_disk "$2"; then
echo -e "${RED}[ERROR]${NC} '$2' is the live boot medium! You cannot install to it."
echo -e "-Select a different disk."
exit 1
fi
DISK="$2"
shift 2
;;
--user)
if [[ -z "${2:-}" ]]; then
echo -e "${RED}[ERROR]${NC} --user requires a username."
echo -e " Run ${CYAN}sudo bash install.sh --help${NC} for usage."
exit 1
fi
if [[ ! "$2" =~ ^[a-z_][a-z0-9_-]*$ ]]; then
echo -e "${RED}[ERROR]${NC} Invalid username '${2}'."
echo -e " Usernames must start with a letter or underscore,"
echo -e " and contain only lowercase letters, digits, - or _."
exit 1
fi
USERNAME="$2"
shift 2
;;
--hostname)
if [[ -z "${2:-}" ]]; then
echo -e "${RED}[ERROR]${NC} --hostname requires a name."
echo -e " Run ${CYAN}sudo bash install.sh --help${NC} for usage."
exit 1
fi
if [[ ! "$2" =~ ^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$ ]]; then
echo -e "${RED}[ERROR]${NC} Invalid hostname '${2}'."
echo -e " Hostnames may only contain letters, digits, and hyphens,"
echo -e " and must not start or end with a hyphen."
exit 1
fi
HOSTNAME="$2"
shift 2
;;
--timezone)
if [[ -z "${2:-}" ]]; then
echo -e "${RED}[ERROR]${NC} --timezone requires a timezone string (e.g. Europe/Istanbul)."
echo -e " Run ${CYAN}sudo bash install.sh --help${NC} for usage."
exit 1
fi
if [[ ! -f "/usr/share/zoneinfo/$2" ]]; then
echo -e "${RED}[ERROR]${NC} Unknown timezone '${2}'."
echo -e " Valid examples: UTC, Europe/Istanbul, America/New_York, Asia/Jerusalem"
echo -e " Full list: ${CYAN}ls /usr/share/zoneinfo/${NC}"
exit 1
fi
TIMEZONE="$2"
shift 2
;;
--compositor)
if [[ -z "${2:-}" ]]; then
echo -e "${RED}[ERROR]${NC} --compositor requires a value: ${CYAN}niri${NC} or ${CYAN}hyprland${NC}."
echo -e " Run ${CYAN}sudo bash install.sh --help${NC} for usage."
exit 1
fi
if [[ "$2" != "niri" && "$2" != "hyprland" ]]; then
echo -e "${RED}[ERROR]${NC} Unknown compositor '${2}'."
echo -e " Valid options: ${CYAN}niri${NC}, ${CYAN}hyprland${NC}"
echo -e " Run ${CYAN}sudo bash install.sh --help${NC} for usage."
exit 1
fi
COMPOSITOR="$2"
shift 2
;;
--keymap)
if [[ -z "${2:-}" ]]; then
echo -e "${RED}[ERROR]${NC} --keymap requires a keymap name (e.g. us, de, fr)."
echo -e " Run ${CYAN}sudo bash install.sh --help${NC} for usage."
exit 1
fi
KEYMAP="$2"
shift 2
;;
-*)
echo -e "${RED}[ERROR]${NC} Unknown option: '$1'"
echo -e " Run ${CYAN}sudo bash install.sh --help${NC} for usage."
exit 1
;;
*)
echo -e "${RED}[ERROR]${NC} Unexpected argument: '$1'"
echo -e " This installer does not take positional arguments."
echo -e " Run ${CYAN}sudo bash install.sh --help${NC} for usage."
exit 1
;;
esac
done
}
# Logging functions
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[OK]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# Progress bar function
# Usage: progress_bar <current> <total> <label>
progress_bar() {
local current=$1
local total=$2
local label=${3:-"Progress"}
local width=40
local percent=$((current * 100 / total))
local filled=$((current * width / total))
local empty=$((width - filled))
# Build the bar
local bar=""
for ((i=0; i<filled; i++)); do bar+="█"; done
for ((i=0; i<empty; i++)); do bar+="░"; done
printf "\r${CYAN}%s${NC} [${GREEN}%s${NC}] ${BOLD}%3d%%${NC}" "$label" "$bar" "$percent"
}
# Spinner function for background tasks
# Usage: run_with_spinner "message" command args...
run_with_spinner() {
local message="$1"
shift
local spin_chars='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
local pid
# Run command in background
"$@" &>/dev/null &
pid=$!
# Show spinner while command runs
local i=0
while kill -0 $pid 2>/dev/null; do
local char="${spin_chars:i++%${#spin_chars}:1}"
printf "\r${CYAN}%s${NC} %s" "$char" "$message"
sleep 0.1
done
# Check exit status
wait $pid
local status=$?
if [[ $status -eq 0 ]]; then
printf "\r${GREEN}✓${NC} %s\n" "$message"
else
printf "\r${RED}✗${NC} %s\n" "$message"
return $status
fi
}
# Step header with progress
step_header() {
((CURRENT_STEP++))
echo
echo -e "${BOLD}${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD} Step ${CURRENT_STEP}/${TOTAL_STEPS}: $1${NC}"
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo
}
# Overall progress indicator
show_overall_progress() {
local width=60
local filled=$((CURRENT_STEP * width / TOTAL_STEPS))
local empty=$((width - filled))
local percent=$((CURRENT_STEP * 100 / TOTAL_STEPS))
echo
echo -ne "${DIM}Overall Progress: ${NC}"
echo -ne "${GREEN}"
for ((i=0; i<filled; i++)); do echo -n "▓"; done
echo -ne "${NC}${DIM}"
for ((i=0; i<empty; i++)); do echo -n "░"; done
echo -e "${NC} ${BOLD}${percent}%${NC}"
}
# Detect if a disk is the live boot medium
# Returns 0, if the disk should be excluded, 1
is_live_boot_disk() {
local dev="$1"
local dev_basename
dev_basename=$(basename "$dev")
# Check if any partition on this disk is mounted as the live filesystem
if findmnt -n -o SOURCE /run/archiso/bootmnt 2>/dev/null | grep -q "$dev_basename"; then
return 0
fi
# Check if the disk holds the archiso label
if lsblk -no LABEL "$dev" 2>/dev/null | grep -qiE "(archiso|cvh|codeverse)"; then
return 0
fi
# Check if any partition on this disk is used by the live overlay
local disk_parts
disk_parts=$(lsblk -lno NAME "$dev" 2>/dev/null | tail -n +2)
for part in $disk_parts; do
if findmnt -n -o SOURCE / 2>/dev/null | grep -q "$part"; then
return 0
fi
done
return 1
}
# list of installable disks
get_installable_disks() {
local disks_raw
disks_raw=$(lsblk -dno NAME | grep -vE "^(loop|sr|rom|fd|zram)")
local result=()
for d in $disks_raw; do
if ! is_live_boot_disk "/dev/$d"; then
result+=("$d")
fi
done
echo "${result[@]}"
}
# Check if running as root
check_root() {
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}[ERROR]${NC} This installer must be run as root."
echo
echo -e " Please re-run with sudo:"
echo -e " ${CYAN}sudo bash install.sh${NC}"
echo
echo -e " Run ${CYAN}bash install.sh --help${NC} for full usage information."
exit 1
fi
}
# Display welcome banner
show_welcome() {
clear
echo
echo -e "${BOLD}${CYAN}"
cat << 'EOF'
██████╗██╗ ██╗██╗ ██╗ ██╗ ██╗███╗ ██╗██╗ ██╗██╗ ██╗
██╔════╝██║ ██║██║ ██║ ██║ ██║████╗ ██║██║ ██║╚██╗██╔╝
██║ ██║ ██║███████║ ██║ ██║██╔██╗ ██║██║ ██║ ╚███╔╝
██║ ╚██╗ ██╔╝██╔══██║ ██║ ██║██║╚██╗██║██║ ██║ ██╔██╗
╚██████╗ ╚████╔╝ ██║ ██║ ███████╗██║██║ ╚████║╚██████╔╝██╔╝ ██╗
╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝
EOF
echo -e "${NC}"
echo -e "${DIM} CodeVerse Hub Linux Distribution${NC}"
echo
echo -e " ${BOLD}Features:${NC}"
echo -e " ${GREEN}●${NC} Niri or Hyprland Wayland compositor"
echo -e " ${GREEN}●${NC} Ly display manager"
echo -e " ${GREEN}●${NC} Zsh + Oh My Zsh"
echo -e " ${GREEN}●${NC} Custom fuzzy finder & icon system"
echo -e " ${GREEN}●${NC} Minimal & lightweight"
echo
echo -e " ${YELLOW}⚠${NC} ${BOLD}WARNING:${NC} This will ERASE all data on the selected disk!"
echo
read -r -p " Press Enter to begin installation or Ctrl+C to cancel..." _ || true
}
# Detect boot mode (UEFI or BIOS)
detect_boot_mode() {
step_header "Detecting System"
echo -n " Checking boot mode... "
if [[ -d /sys/firmware/efi/efivars ]]; then
BOOT_MODE="uefi"
echo -e "${GREEN}UEFI${NC}"
else
BOOT_MODE="bios"
echo -e "${YELLOW}BIOS/Legacy${NC}"
fi
}
# Select keyboard layout
select_keyboard() {
# Skip if already set via --keymap
if [[ -n "$KEYMAP" && "$KEYMAP" != "us" ]]; then
step_header "Keyboard Layout"
echo -e " ${GREEN}✓${NC} Keyboard pre-set: ${BOLD}$KEYMAP${NC}"
loadkeys "$KEYMAP" 2>/dev/null || log_warn "Could not apply keymap '$KEYMAP' — continuing anyway."
return
fi
step_header "Keyboard Layout"
echo " Available layouts:"
echo -e " ${BOLD}1)${NC} us - US English ${DIM}[default]${NC}"
echo -e " ${BOLD}2)${NC} uk - UK English"
echo -e " ${BOLD}3)${NC} de - German"
echo -e " ${BOLD}4)${NC} fr - French"
echo -e " ${BOLD}5)${NC} es - Spanish"
echo -e " ${BOLD}6)${NC} il - Hebrew"
echo -e " ${BOLD}7)${NC} Other"
echo
read -r -p " Select layout [1]: " kb_choice
kb_choice=${kb_choice:-1}
case $kb_choice in
1) KEYMAP="us" ;;
2) KEYMAP="uk" ;;
3) KEYMAP="de" ;;
4) KEYMAP="fr" ;;
5) KEYMAP="es" ;;
6) KEYMAP="il" ;;
7) read -r -p " Enter keymap name: " KEYMAP ;;
*) log_warn "Invalid selection, defaulting to: us"; KEYMAP="us" ;;
esac
loadkeys "$KEYMAP" 2>/dev/null || log_warn "Could not apply keymap '$KEYMAP' — continuing anyway."
echo -e "\n ${GREEN}✓${NC} Keyboard: ${BOLD}$KEYMAP${NC}"
}
# Select timezone
select_timezone() {
# Skip if already set via --timezone
if [[ "$TIMEZONE" != "Asia/Jerusalem" ]]; then
step_header "Timezone"
echo -e " ${GREEN}✓${NC} Timezone pre-set: ${BOLD}$TIMEZONE${NC}"
return
fi
step_header "Timezone"
echo " Common timezones:"
echo -e " ${BOLD}1)${NC} Asia/Jerusalem ${DIM}[default]${NC}"
echo -e " ${BOLD}2)${NC} UTC"
echo -e " ${BOLD}3)${NC} America/New_York"
echo -e " ${BOLD}4)${NC} America/Los_Angeles"
echo -e " ${BOLD}5)${NC} Europe/London"
echo -e " ${BOLD}6)${NC} Europe/Berlin"
echo -e " ${BOLD}7)${NC} Other"
echo
read -r -p " Select timezone [1]: " tz_choice
tz_choice=${tz_choice:-1}
case $tz_choice in
1) TIMEZONE="Asia/Jerusalem" ;;
2) TIMEZONE="UTC" ;;
3) TIMEZONE="America/New_York" ;;
4) TIMEZONE="America/Los_Angeles" ;;
5) TIMEZONE="Europe/London" ;;
6) TIMEZONE="Europe/Berlin" ;;
7)
read -r -p " Enter timezone (Region/City): " TIMEZONE
if [[ ! -f "/usr/share/zoneinfo/$TIMEZONE" ]]; then
log_warn "Timezone '$TIMEZONE' not found. Defaulting to Asia/Jerusalem."
TIMEZONE="Asia/Jerusalem"
fi
;;
*) log_warn "Invalid selection, defaulting to: Asia/Jerusalem"; TIMEZONE="Asia/Jerusalem" ;;
esac
echo -e "\n ${GREEN}✓${NC} Timezone: ${BOLD}$TIMEZONE${NC}"
}
# Select compositor
select_compositor() {
# Skip if already set via --compositor
if [[ -n "$COMPOSITOR" ]]; then
step_header "Compositor Selection"
echo -e " ${GREEN}✓${NC} Compositor pre-set: ${BOLD}$COMPOSITOR${NC}"
return
fi
step_header "Compositor Selection"
echo " Available Wayland compositors:"
echo -e " ${BOLD}1)${NC} Niri - Scrollable-tiling compositor ${DIM}[default]${NC}"
echo -e " ${BOLD}2)${NC} Hyprland - Dynamic tiling compositor"
echo
read -r -p " Select compositor [1]: " comp_choice
comp_choice=${comp_choice:-1}
case $comp_choice in
1) COMPOSITOR="niri" ;;
2) COMPOSITOR="hyprland" ;;
*) log_warn "Invalid selection, defaulting to: niri"; COMPOSITOR="niri" ;;
esac
echo -e "\n ${GREEN}✓${NC} Compositor: ${BOLD}$COMPOSITOR${NC}"
}
# Select disk for installation
select_disk() {
step_header "Disk Selection"
# If disk was pre-set via --disk, show full details and confirm
if [[ -n "$DISK" ]]; then
local pre_size pre_model
pre_size=$(lsblk -dno SIZE "$DISK" 2>/dev/null | xargs)
pre_model=$(lsblk -dno MODEL "$DISK" 2>/dev/null | xargs)
echo -e " ${YELLOW}┌──────────────────────────────────────────────┐${NC}"
echo -e " ${YELLOW}│${NC} ${RED}${BOLD}⚠ WARNING: DESTRUCTIVE OPERATION${NC} ${YELLOW}│${NC}"
echo -e " ${YELLOW}├──────────────────────────────────────────────┤${NC}"
echo -e " ${YELLOW}│${NC} Disk: ${BOLD}$DISK${NC}"
echo -e " ${YELLOW}│${NC} Size: ${CYAN}${pre_size:-unknown}${NC}"
echo -e " ${YELLOW}│${NC} Model: ${pre_model:-unknown}"
echo -e " ${YELLOW}│${NC}"
echo -e " ${YELLOW}│${NC} ${RED}ALL DATA ON THIS DISK WILL BE PERMANENTLY ERASED!${NC}"
echo -e " ${YELLOW}└──────────────────────────────────────────────┘${NC}"
echo
read -r -p " Type 'yes' to confirm: " confirm
if [[ "$confirm" != "yes" ]]; then
log_error "Installation cancelled by user."
exit 1
fi
echo -e "\n ${GREEN}✓${NC} Disk: ${BOLD}$DISK${NC}"
return
fi
# list of installable disks
local disks
read -ra disks <<< "$(get_installable_disks)"
if [[ ${#disks[@]} -eq 0 ]]; then
log_error "No suitable disks found!"
echo -e " ${YELLOW}All detected disks are either the live boot medium or unsupported.${NC}"
exit 1
fi
# Interactive selection with retry (max 3 attempts)
local disk_num
local max_attempts=3
local attempt=0
while true; do
((attempt++))
if [[ $attempt -gt $max_attempts ]]; then
log_error "Too many invalid attempts ($max_attempts). Aborting."
exit 1
fi
echo " Available disks:"
echo
local i=1
for d in "${disks[@]}"; do
local size model
size=$(lsblk -dno SIZE "/dev/$d" 2>/dev/null | xargs)
model=$(lsblk -dno MODEL "/dev/$d" 2>/dev/null | xargs)
printf " ${BOLD}%d)${NC} /dev/%-8s ${CYAN}%8s${NC} %s\n" "$i" "$d" "${size:-??}" "${model:-}"
((i++))
done
echo
read -r -p " Enter disk number [1-${#disks[@]}]: " disk_num
# Validate input
if [[ ! "$disk_num" =~ ^[0-9]+$ ]]; then
log_warn "Please enter a number. (Attempt $attempt/$max_attempts)"
echo
continue
fi
if [[ $disk_num -lt 1 ]] || [[ $disk_num -gt ${#disks[@]} ]]; then
log_warn "Invalid selection. Enter a number between 1 and ${#disks[@]}. (Attempt $attempt/$max_attempts)"
echo
continue
fi
# Valid selection
break
done
DISK="/dev/${disks[$((disk_num-1))]}"
# Show whole confirmation with disk info
local sel_size sel_model
sel_size=$(lsblk -dno SIZE "$DISK" 2>/dev/null | xargs)
sel_model=$(lsblk -dno MODEL "$DISK" 2>/dev/null | xargs)
echo
echo -e " ${YELLOW}┌──────────────────────────────────────────────┐${NC}"
echo -e " ${YELLOW}│${NC} ${RED}${BOLD}⚠ WARNING: DESTRUCTIVE OPERATION${NC} ${YELLOW}│${NC}"
echo -e " ${YELLOW}├──────────────────────────────────────────────┤${NC}"
echo -e " ${YELLOW}│${NC} Disk: ${BOLD}$DISK${NC}"
echo -e " ${YELLOW}│${NC} Size: ${CYAN}${sel_size:-unknown}${NC}"
echo -e " ${YELLOW}│${NC} Model: ${sel_model:-unknown}"
echo -e " ${YELLOW}│${NC}"
echo -e " ${YELLOW}│${NC} ${RED}ALL DATA ON THIS DISK WILL BE PERMANENTLY ERASED!${NC}"
echo -e " ${YELLOW}└──────────────────────────────────────────────┘${NC}"
echo
read -r -p " Type 'yes' to confirm: " confirm
if [[ "$confirm" != "yes" ]]; then
log_error "Installation cancelled by user."
exit 1
fi
echo -e "\n ${GREEN}✓${NC} Disk: ${BOLD}$DISK${NC}"
}
# Set hostname
set_hostname() {
step_header "System Configuration"
# Skip if already set via --hostname
if [[ "$HOSTNAME" != "cvh-linux" ]]; then
echo -e " ${GREEN}✓${NC} Hostname pre-set: ${BOLD}$HOSTNAME${NC}"
else
local max_attempts=3
local attempt=0
while true; do
((attempt++))
if [[ $attempt -gt $max_attempts ]]; then
log_warn "Too many invalid attempts. Using default: cvh-linux"
HOSTNAME="cvh-linux"
break
fi
read -r -p " Enter hostname [cvh-linux]: " input_hostname
HOSTNAME=${input_hostname:-cvh-linux}
if [[ "$HOSTNAME" =~ ^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$ ]]; then
break
fi
log_warn "Invalid hostname '$HOSTNAME'. (Attempt $attempt/$max_attempts)"
echo -e " ${DIM}Hostnames may only contain letters, digits, and hyphens,${NC}"
echo -e " ${DIM}and must not start or end with a hyphen.${NC}"
echo
done
echo -e " ${GREEN}✓${NC} Hostname: ${BOLD}$HOSTNAME${NC}"
fi
}
# Create user account
create_user_config() {
echo
# Skip if already set via --user
if [[ "$USERNAME" != "cvh" ]]; then
echo -e " ${GREEN}✓${NC} Username pre-set: ${BOLD}$USERNAME${NC}"
return
fi
local max_attempts=3
local attempt=0
while true; do
((attempt++))
if [[ $attempt -gt $max_attempts ]]; then
log_warn "Too many invalid attempts. Using default: cvh"
USERNAME="cvh"
break
fi
read -r -p " Enter username [cvh]: " input_username
USERNAME=${input_username:-cvh}
if [[ "$USERNAME" =~ ^[a-z_][a-z0-9_-]*$ ]]; then
break
fi
log_warn "Invalid username '$USERNAME'. (Attempt $attempt/$max_attempts)"
echo -e " ${DIM}Usernames must start with a letter or underscore,${NC}"
echo -e " ${DIM}and contain only lowercase letters, digits, - or _.${NC}"
echo
done
echo -e " ${GREEN}✓${NC} Username: ${BOLD}$USERNAME${NC}"
}
# Partition the disk
partition_disk() {
step_header "Partitioning Disk"
echo " Preparing disk..."
# Wipe existing partition table
wipefs -af "$DISK" >/dev/null 2>&1 || true
sgdisk -Z "$DISK" >/dev/null 2>&1 || true
if [[ "$BOOT_MODE" == "uefi" ]]; then
echo -e " ${BLUE}●${NC} Creating GPT partition table (UEFI)"
parted -s "$DISK" mklabel gpt
progress_bar 1 5 " Partitioning"
parted -s "$DISK" mkpart primary fat32 1MiB 513MiB
parted -s "$DISK" set 1 esp on
progress_bar 2 5 " Partitioning"
parted -s "$DISK" mkpart primary ext4 513MiB 100%
progress_bar 3 5 " Partitioning"
if [[ "$DISK" == *"nvme"* ]] || [[ "$DISK" == *"mmcblk"* ]]; then
EFI_PART="${DISK}p1"
ROOT_PART="${DISK}p2"
else
EFI_PART="${DISK}1"
ROOT_PART="${DISK}2"
fi
sleep 1 # Wait for kernel to recognize partitions
echo -e "\n ${BLUE}●${NC} Formatting EFI partition (FAT32)"
mkfs.fat -F32 "$EFI_PART" >/dev/null 2>&1
progress_bar 4 5 " Formatting "
echo -e "\n ${BLUE}●${NC} Formatting root partition (ext4)"
mkfs.ext4 -F "$ROOT_PART" >/dev/null 2>&1
progress_bar 5 5 " Formatting "
echo -e "\n\n ${BLUE}●${NC} Mounting partitions"
mount "$ROOT_PART" /mnt
mkdir -p /mnt/boot/efi
mount "$EFI_PART" /mnt/boot/efi
else
echo -e " ${BLUE}●${NC} Creating MBR partition table (BIOS)"
parted -s "$DISK" mklabel msdos
progress_bar 1 4 " Partitioning"
parted -s "$DISK" mkpart primary ext4 1MiB 100%
parted -s "$DISK" set 1 boot on
progress_bar 2 4 " Partitioning"
if [[ "$DISK" == *"nvme"* ]] || [[ "$DISK" == *"mmcblk"* ]]; then
ROOT_PART="${DISK}p1"
else
ROOT_PART="${DISK}1"
fi
sleep 1
echo -e "\n ${BLUE}●${NC} Formatting root partition (ext4)"
mkfs.ext4 -F "$ROOT_PART" >/dev/null 2>&1
progress_bar 3 4 " Formatting "
echo -e "\n\n ${BLUE}●${NC} Mounting partition"
mount "$ROOT_PART" /mnt
progress_bar 4 4 " Mounting "
fi
echo -e "\n\n ${GREEN}✓${NC} Disk prepared successfully"
}
# Install base system
install_base() {
step_header "Installing Base System"
# Check network connectivity
echo -n " Checking network... "
if ! ping -c 1 -W 5 archlinux.org &>/dev/null; then
echo -e "${YELLOW}not connected${NC}"
echo " Attempting to connect..."
systemctl start NetworkManager 2>/dev/null || true
sleep 3
for iface in $(ip -o link show | awk -F': ' '{print $2}' | grep -v lo); do
dhcpcd "$iface" 2>/dev/null &
done
sleep 5
if ! ping -c 1 -W 5 archlinux.org &>/dev/null; then
echo -e " ${RED}✗${NC} No network connection"
echo
echo -e " ${YELLOW}To connect manually:${NC}"
echo -e " ${CYAN}nmtui${NC} — graphical network manager"
echo -e " ${CYAN}nmcli device wifi list${NC} — list WiFi networks"
echo -e " ${CYAN}nmcli device wifi connect <SSID> password <PW>${NC}"
echo
echo -e " Re-run the installer after connecting:"
echo -e " ${CYAN}sudo bash install.sh${NC}"
exit 1
fi
fi
echo -e "${GREEN}connected${NC}"
# Initialize pacman keyring
echo -e " ${BLUE}●${NC} Initializing package keyring..."
pacman-key --init >/dev/null 2>&1
pacman-key --populate archlinux >/dev/null 2>&1
echo -e " ${GREEN}✓${NC} Keyring initialized"
# Base packages (always installed)
local base_packages=(
base base-devel
linux linux-firmware linux-headers
grub efibootmgr
networkmanager
zsh zsh-completions git
pipewire pipewire-pulse wireplumber
noto-fonts noto-fonts-emoji ttf-dejavu ttf-liberation ttf-fira-code
sudo nano vim
seatd
ly
gcc pkgconf
)
# Shell utilities
local shell_utils=(
gum zoxide fd ripgrep bat eza
)
# System utilities
local system_utils=(
htop btop tree fastfetch nnn
)
# Sandboxing (required for cvh-icons)
local sandbox_packages=(
bubblewrap libseccomp
)
# Compositor-specific packages
local compositor_packages=()
if [[ "$COMPOSITOR" == "niri" ]]; then
compositor_packages=(
niri
xdg-desktop-portal-gnome
xdg-desktop-portal-gtk
)
elif [[ "$COMPOSITOR" == "hyprland" ]]; then
compositor_packages=(
hyprland
xdg-desktop-portal-wlr
polkit-gnome
)
fi
# Shared Wayland utilities
local wayland_packages=(
foot mako fuzzel
grim slurp wl-clipboard
wayland wayland-protocols xorg-xwayland
brightnessctl
)
# Combine all packages
local packages=(
"${base_packages[@]}"
"${shell_utils[@]}"
"${system_utils[@]}"
"${sandbox_packages[@]}"
"${compositor_packages[@]}"
"${wayland_packages[@]}"
)
echo
echo -e " ${BLUE}●${NC} Installing packages (this may take a while)..."
echo -e " ${DIM}────────────────────────────────────────────────────────${NC}"
echo
# Run pacstrap - show output directly
if pacstrap -K /mnt "${packages[@]}"; then
echo
echo -e " ${DIM}────────────────────────────────────────────────────────${NC}"
echo -e " ${GREEN}✓${NC} Base system installed"
else
echo
echo -e " ${RED}✗${NC} Package installation failed!"
echo
echo -e " ${YELLOW}Possible causes:${NC}"
echo -e " • Network dropped during download"
echo -e " • Pacman keyring issue — try: ${CYAN}pacman-key --refresh-keys${NC}"
echo -e " • Disk full or mount error"
echo
echo -e " Re-run after fixing: ${CYAN}sudo bash install.sh${NC}"
exit 1
fi
}
# Generate fstab
generate_fstab() {
step_header "Generating Filesystem Table"
echo -n " Creating /etc/fstab... "
genfstab -U /mnt >> /mnt/etc/fstab
echo -e "${GREEN}done${NC}"
echo -e "\n ${GREEN}✓${NC} Filesystem table generated"
}
# Configure the installed system
configure_system() {
step_header "Configuring System"
local tasks=(
"Setting timezone"
"Generating locales"
"Setting hostname"
"Enabling services"
"Installing bootloader"
"Creating user account"
"Setting up shell"
"Configuring desktop"
)
local total=${#tasks[@]}
local current=0
# Create a configuration script to run in chroot
# Use /mnt/root/ which always exists after pacstrap
cat > /mnt/root/configure.sh << CONFIGURE_SCRIPT
#!/bin/bash
# Don't use set -e as some commands may fail non-fatally
# Timezone
ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
hwclock --systohc
# Locale
echo "$LOCALE UTF-8" > /etc/locale.gen
locale-gen >/dev/null 2>&1
echo "LANG=$LOCALE" > /etc/locale.conf
# Keymap
echo "KEYMAP=$KEYMAP" > /etc/vconsole.conf
# Hostname
echo "$HOSTNAME" > /etc/hostname
cat > /etc/hosts << EOF
127.0.0.1 localhost
::1 localhost
127.0.1.1 $HOSTNAME.localdomain $HOSTNAME
EOF
# Configure Ly display manager
mkdir -p /etc/ly
cat > /etc/ly/config.ini << 'LY_EOF'
# CVH Linux Ly Configuration
animation = 0
hide_borders = 0
# Run on tty1 (default boot experience)
tty = 1
waylandsessions = /usr/share/wayland-sessions
# Save last session and user
save = 1
save_file = /var/cache/ly/save
LY_EOF
mkdir -p /var/cache/ly
chmod 755 /var/cache/ly
# Enable services
systemctl enable NetworkManager >/dev/null 2>&1
systemctl enable systemd-timesyncd >/dev/null 2>&1
systemctl enable seatd >/dev/null 2>&1
systemctl enable ly.service >/dev/null 2>&1
# Install CVH custom packages from local cache
echo "Installing CVH custom packages..."
if ls /var/cache/pacman/cvh-packages/*.pkg.tar.zst >/dev/null 2>&1; then
pacman -U --noconfirm /var/cache/pacman/cvh-packages/*.pkg.tar.zst >/dev/null 2>&1 || true
# Verify installation
echo "Verifying CVH packages:"
for pkg in cvh-fuzzy cvh-icons cvh-branding; do
if pacman -Q \$pkg >/dev/null 2>&1; then
echo " ✓ \$pkg installed"
else
echo " ✗ \$pkg not installed (optional)"
fi
done
else
echo " ⚠ CVH packages not found, skipping"
fi
# Create os-release for proper branding (GRUB uses this)
cat > /etc/os-release << EOF
NAME="CVH Linux"
PRETTY_NAME="CVH Linux"
ID=cvh
ID_LIKE=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://cvhlinux.org"
DOCUMENTATION_URL="https://wiki.cvhlinux.org"
LOGO=cvh-logo
EOF
# Set GRUB distributor name
sed -i 's/^GRUB_DISTRIBUTOR=.*/GRUB_DISTRIBUTOR="CVH Linux"/' /etc/default/grub 2>/dev/null || \
echo 'GRUB_DISTRIBUTOR="CVH Linux"' >> /etc/default/grub
# Ensure zsh is in /etc/shells
echo "/usr/bin/zsh" >> /etc/shells
echo "/bin/zsh" >> /etc/shells
# Create seat group if it doesn't exist (for seatd)
getent group seat >/dev/null || groupadd seat