-
Notifications
You must be signed in to change notification settings - Fork 0
/
saki.sh
executable file
·708 lines (581 loc) · 25.5 KB
/
saki.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
#!/bin/bash
# Simple Arch KDE Installer
# Configuration
#################################################
# HD Configuration
# Run "lsblk" to determine HD device name
# To check for TRIM support, run "lsblk --discard". If DISC-GRAN && DISC-MAX are > 0, your HD supports TRIM.
# If running as VM, you'll need to double check if TRIM is supported. Newer KVM/Qemu VMs should support TRIM.
HD_DEVICE="" # /dev/sda /dev/nvme0n1 /dev/vda
TRIM_SUPPORT="true" # typically set to true if HD is an SSD, see notes above
SWAPFILE_SIZE="2048" # 4096 8912 (in MiB)
# CPU Configuration
# Note: if installing in a VM leave both set to 'false'
AMD_CPU="false"
INTEL_CPU="false"
# GPU Configuration
AMD_GPU="false"
INTEL_GPU="false"
NVIDIA_GPU="false"
# Hostname to ping to check network connection
PING_HOSTNAME="www.google.com"
# Hostname Configuration
HOSTNAME="saki"
# Locale Configuration
# To list out all timezones in a given region run "ls -l /usr/share/zoneinfo/{region}" e.g. "ls -l /usr/share/zoneinfo/America"
# To list out all timezones run "timedatectl list-timezones"
# To examine available locales look in /etc/locale.gen, first column is used for LANG, both columns together are used for LOCALE
KEYS="us"
TIMEZONE="/usr/share/zoneinfo/America/Denver"
LOCALE="en_US.UTF-8 UTF-8"
LANG="en_US.UTF-8"
# TTY Font (Default: Terminus 24px bold)
TTY_FONT="ter-124b" #ter-124n #ter-128b #ter-128n #ter-132b #ter-132n
# Reflector Configuration
REFLECTOR_COUNTRY="United States"
# User Configuration
ROOT_PASSWORD=""
USER_NAME=""
USER_PASSWORD=""
# Additional Linux Command Line Params
CMDLINE_LINUX="" #"msr.allow_writes=on"
# Uncomment to enable the installation log
#LOG_FILE="saki.log"
# Installation Scripts
#################################################
function main() {
check_critical_prereqs
check_variables
check_conflicts
check_network
loadkeys $KEYS
confirm_install
install
}
function install() {
echo_to_log "=========================================="
echo_to_log "1. System clock and initial reflector pass"
echo_to_log "=========================================="
# Update system clock
timedatectl set-ntp true
# Select the fastest pacman mirrors
reflector --verbose --country "$REFLECTOR_COUNTRY" --latest 25 --sort rate --save /etc/pacman.d/mirrorlist
echo_to_log "================================="
echo_to_log "2. HD partitioning and formatting"
echo_to_log "================================="
# Partion the drive with a single 512 MB ESP partition, and the rest of the drive as the root partition
parted -s $HD_DEVICE mklabel gpt mkpart ESP fat32 1MiB 512MiB mkpart root ext4 512MiB 100% set 1 esp on
# Is the the hard drive an NVME SSD?
if [[ -n "$(echo $HD_DEVICE | grep "^/dev/nvme")" ]]; then
local BOOT_PARTITION="${HD_DEVICE}p1"
local ROOTFS_PARTITION="${HD_DEVICE}p2"
else
local BOOT_PARTITION="${HD_DEVICE}1"
local ROOTFS_PARTITION="${HD_DEVICE}2"
fi
# Create the filesystem for the ESP partition
mkfs.fat -n ESP -F32 $BOOT_PARTITION
# Create the filesystem for the root partition
yes | mkfs.ext4 -L ROOT $ROOTFS_PARTITION
# Mount the root partition
mount -o defaults,noatime $ROOTFS_PARTITION /mnt
# Create directory to support mounting ESP
mkdir /mnt/boot
# Mount the ESP partition
mount -o defaults,noatime $BOOT_PARTITION /mnt/boot
# Build out swapfile
local SWAPFILE="/swapfile"
fallocate --length ${SWAPFILE_SIZE}MiB /mnt"$SWAPFILE"
chown root /mnt"$SWAPFILE"
chmod 600 /mnt"$SWAPFILE"
mkswap /mnt"$SWAPFILE"
echo_to_log "====================================="
echo_to_log "3. Initial pacstrap and core packages"
echo_to_log "====================================="
# Force a refresh of the archlinux-keyring package for the arch installation environment
pacman -Sy --noconfirm --noprogressbar archlinux-keyring | tee -a "$LOG_FILE"
# Bootstrap new environment (base)
pacstrap /mnt
# Install essential packages
arch-chroot /mnt pacman -S --noconfirm --needed --noprogressbar \
base-devel `# Core development libraries (gcc, etc.)` \
linux linux-headers `# Linux kernel and headers` \
linux-firmware `# Linux firmawre` \
fwupd `# Support for updating firmware from Linux Vendor Firmware Service [https://fwupd.org/]` \
man-db man-pages `# man pages` \
texinfo `# GUN documentation format` \
dosfstools exfatprogs `# Tools and utilities for FAT and exFAT filesystems` \
e2fsprogs `# Tools and utiltiies for ext filesystems` \
networkmanager `# Networkmanager` \
git `# Git` \
vim `# Text editor` \
cpupower `# Tool for managing your CPU frequency and governor` \
reflector `# Utility to manage pacman mirrors` \
terminus-font `# Terminus font for tty` \
pacman-contrib `# Additional pacman utilities (paccache, etc.)` \
| tee -a "$LOG_FILE"
# Install additional firmware and uCode
if [[ "$AMD_CPU" == "true" ]]; then
arch-chroot /mnt pacman -S --noconfirm --needed --noprogressbar linux-firmware amd-ucode | tee -a "$LOG_FILE"
local MICROCODE="amd-ucode.img"
elif [[ "$INTEL_CPU" == "true" ]]; then
arch-chroot /mnt pacman -S --noconfirm --needed --noprogressbar linux-firmware intel-ucode | tee -a "$LOG_FILE"
local MICROCODE="intel-ucode.img"
fi
echo_to_log "============================"
echo_to_log "4. Core system configuration"
echo_to_log "============================"
# Enable systemd-resolved local caching DNS provider
# Note: NetworkManager uses systemd-resolved by default
arch-chroot /mnt systemctl enable systemd-resolved.service
# Enable NetworkManager.service
# Note: NetworkManager will handle DHCP
arch-chroot /mnt systemctl enable NetworkManager.service
# Enable bluetooth.service
arch-chroot /mnt systemctl enable bluetooth.service
# Configure color support for pacman
arch-chroot /mnt sed -i 's/#Color/Color/' /etc/pacman.conf
# Enable multilib
arch-chroot /mnt sed -i "/\[multilib\]/,/Include/"'s/^#//' /etc/pacman.conf
arch-chroot /mnt pacman -Syyu --noprogressbar | tee -a "$LOG_FILE"
# Generate initial fstab using UUIDs
genfstab -U /mnt > /mnt/etc/fstab
# Create a dedicated entry for swapfile
echo "# swapfile" >> /mnt/etc/fstab
echo "$SWAPFILE none swap defaults 0 0" >> /mnt/etc/fstab
echo "" >> /mnt/etc/fstab
# Configure swappiness paramater (default=60) to improve system responsiveness
echo "vm.swappiness=10" > /mnt/etc/sysctl.d/99-sysctl.conf
# Enable periodic trim if the HD supports TRIM
if [[ "$TRIM_SUPPORT" == "true" ]]; then
arch-chroot /mnt systemctl enable fstrim.timer
fi
# Configure timezone and system clock
arch-chroot /mnt ln -s -f $TIMEZONE /etc/localtime
arch-chroot /mnt hwclock --systohc
# Configure locale
arch-chroot /mnt sed -i "s/#$LOCALE/$LOCALE/" /etc/locale.gen
arch-chroot /mnt locale-gen
echo -e "LANG=$LANG" >> /mnt/etc/locale.conf
# Configure keymap and font for virtual console (tty)
echo -e "KEYMAP=$KEYS" > /mnt/etc/vconsole.conf
echo -e "FONT=$TTY_FONT" >> /mnt/etc/vconsole.conf
# Configure hostname and hosts files
echo $HOSTNAME > /mnt/etc/hostname
echo "127.0.0.1 localhost" >> /mnt/etc/hosts
echo "::1 localhost" >> /mnt/etc/hosts
echo "127.0.0.1 ${HOSTNAME}.localdomain $HOSTNAME" >> /mnt/etc/hosts
# Configure root password
printf "$ROOT_PASSWORD\n$ROOT_PASSWORD" | arch-chroot /mnt passwd
# Configure reflector
echo "--save /etc/pacman.d/mirrorlist" > /mnt/etc/xdg/reflector/reflector.conf
echo "--country \"$REFLECTOR_COUNTRY\"" >> /mnt/etc/xdg/reflector/reflector.conf
echo "--protocol https" >> /mnt/etc/xdg/reflector/reflector.conf
echo "--latest 15" >> /mnt/etc/xdg/reflector/reflector.conf
echo "--sort rate" >> /mnt/etc/xdg/reflector/reflector.conf
echo_to_log "=========================================="
echo_to_log "5. Bootloader configuration (systemd-boot)"
echo_to_log "=========================================="
# Add KMS if using a NVIDIA GPU
if [[ "$NVIDIA_GPU" == "true" ]]; then
CMDLINE_LINUX="$CMDLINE_LINUX nvidia-drm.modeset=1"
fi
CMDLINE_LINUX=$(trim_variable "$CMDLINE_LINUX")
# Standard hooks for /etc/mkinitcpio.conf with systemd boot support
local MKINITCPIO_HOOKS="base systemd autodetect keyboard sd-vconsole modconf block fsck filesystems"
# Modules for /etc/mkinitcpio.conf based on GPU
if [[ "$INTEL_GPU" == "true" ]]; then
local MKINITCPIO_MODULES="i915"
fi
if [[ "$AMD_GPU" == "true" ]]; then
local MKINITCPIO_MODULES="amdgpu"
fi
if [[ "$NVIDIA_GPU" == "true" ]]; then
local MKINITCPIO_MODULES="nvidia nvidia_modeset nvidia_uvm nvidia_drm"
fi
# Update /etc/mkinitcpio.conf with hooks and modules
arch-chroot /mnt sed -i "s/^HOOKS=(.*)$/HOOKS=($MKINITCPIO_HOOKS)/" /etc/mkinitcpio.conf
arch-chroot /mnt sed -i "s/^MODULES=(.*)$/MODULES=($MKINITCPIO_MODULES)/" /etc/mkinitcpio.conf
# Need to rebuild the initramfs after updating hooks and modules
arch-chroot /mnt mkinitcpio -P
# Get the UUID for the root partition
local UUID_ROOTFS_PARTITION=$(blkid -s UUID -o value "$ROOTFS_PARTITION")
local CMDLINE_LINUX_ROOT="root=UUID=$UUID_ROOTFS_PARTITION"
arch-chroot /mnt systemd-machine-id-setup
arch-chroot /mnt bootctl install
arch-chroot /mnt mkdir -p /boot/loader
arch-chroot /mnt mkdir -p /boot/loader/entries
# Main systemd-boot config
echo "timeout 5" >> "/mnt/boot/loader/loader.conf"
echo "default archlinux.conf" >> "/mnt/boot/loader/loader.conf"
echo "editor 1" >> "/mnt/boot/loader/loader.conf"
# Config for normal boot
echo "title Arch Linux" >> "/mnt/boot/loader/entries/archlinux.conf"
echo "efi /vmlinuz-linux" >> "/mnt/boot/loader/entries/archlinux.conf"
if [ -n "$MICROCODE" ]; then
echo "initrd /$MICROCODE" >> "/mnt/boot/loader/entries/archlinux.conf"
fi
echo "initrd /initramfs-linux.img" >> "/mnt/boot/loader/entries/archlinux.conf"
echo "options initrd=initramfs-linux.img $CMDLINE_LINUX_ROOT rw $CMDLINE_LINUX" >> "/mnt/boot/loader/entries/archlinux.conf"
# Config for booting into terminal only
echo "title Arch Linux (terminal)" >> "/mnt/boot/loader/entries/archlinux-terminal.conf"
echo "efi /vmlinuz-linux" >> "/mnt/boot/loader/entries/archlinux-terminal.conf"
if [ -n "$MICROCODE" ]; then
echo "initrd /$MICROCODE" >> "/mnt/boot/loader/entries/archlinux-terminal.conf"
fi
echo "initrd /initramfs-linux.img" >> "/mnt/boot/loader/entries/archlinux-terminal.conf"
echo "options initrd=initramfs-linux.img $CMDLINE_LINUX_ROOT rw $CMDLINE_LINUX systemd.unit=multi-user.target" >> "/mnt/boot/loader/entries/archlinux-terminal.conf"
# Config for fallback boot (uses old initramfs)
echo "title Arch Linux (fallback)" >> "/mnt/boot/loader/entries/archlinux-fallback.conf"
echo "efi /vmlinuz-linux" >> "/mnt/boot/loader/entries/archlinux-fallback.conf"
if [ -n "$MICROCODE" ]; then
echo "initrd /$MICROCODE" >> "/mnt/boot/loader/entries/archlinux-fallback.conf"
fi
echo "initrd /initramfs-linux-fallback.img" >> "/mnt/boot/loader/entries/archlinux-fallback.conf"
echo "options initrd=initramfs-linux-fallback.img $CMDLINE_LINUX_ROOT rw $CMDLINE_LINUX" >> "/mnt/boot/loader/entries/archlinux-fallback.conf"
echo "======================"
echo "6. User configuration"
echo "======================"
# Setup user and allow user to use "sudo"
arch-chroot /mnt useradd -m -G wheel,storage,optical -s /bin/bash $USER_NAME
printf "$USER_PASSWORD\n$USER_PASSWORD" | arch-chroot /mnt passwd $USER_NAME
arch-chroot /mnt sed -i 's/# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
echo_to_log "=================================="
echo_to_log "7. Compositor & audio system configuration"
echo_to_log "=================================="
# Install KDE
arch-chroot /mnt pacman -S --noconfirm --needed --noprogressbar \
plasma plasma-wayland-session `# KDE Plasma + Wayland Support` \
power-profiles-daemon powerdevil `# Power profile switching (powersave, balanced, performance) in "Batteries & Power" widget` \
plasma-nm `# NetworkManager applet` \
kwallet kwallet-pam kwalletmanager `# KWallet subsystem` \
konsole `# Terminal application` \
dolphin dolphin-plugins ark `# File manager and file preview plugins` \
kdenetwork-filesharing \
kdegraphics-thumbnailers \
kimageformats qt5-imageformats \
ffmpegthumbs taglib \
okular gwenview kwrite kcalc `# Image and PDF viewer, text editor, and calculator` \
kcharselect `# Character map` \
partitionmanager `# Partition and disk manager` \
ksystemlog `# System log viewer` \
pipewire wireplumber `# Pipewire and wireplumber session manager` \
pipewire-pulse `# Pipewire drop in replacement for PulseAudio` \
pipewire-jack `# Pipewire JACK support` \
xdg-desktop-portal `# Support for screensharing in pipewire for KDE` \
xdg-desktop-portal-kde \
noto-fonts noto-fonts-emoji `# Noto fonts to support emojis` \
ttf-liberation `# Liberation fonts` \
phonon-qt5-gstreamer `# GStreamer backend for QT5 phonon` \
gst-plugin-pipewire `# Additional GStreamer plugins` \
gst-libav \
gst-plugins-base \
gst-plugins-good \
gst-plugins-bad \
gst-plugins-ugly \
gstreamer-vaapi \
rust `# Rust for paru AUR helper` \
| tee -a "$LOG_FILE"
# Enable SDDM as the default Display Manager
arch-chroot /mnt systemctl enable sddm.service
# Configure SDDM to use a sane theme (breeze)
configure_sddm
echo_to_log "===================="
echo_to_log "8. GPU Configuration"
echo_to_log "===================="
# Install GPU Drivers
COMMON_VULKAN_PACKAGES="vulkan-icd-loader lib32-vulkan-icd-loader vulkan-tools"
# Drivers for VM guest installations
if [[ "$INTEL_GPU" == "false" && "$AMD_GPU" == "false" && "$NVIDIA_GPU" == "false" ]]; then
arch-chroot /mnt pacman -S --noconfirm --needed --noprogressbar $COMMON_VULKAN_PACKAGES mesa lib32-mesa | tee -a "$LOG_FILE"
fi
if [[ "$INTEL_GPU" == "true" ]]; then
# Note: installing newer intel-media-driver (iHD) instead of libva-intel-driver (i965)
# Intel drivers only supports VA-API
arch-chroot /mnt pacman -S --noconfirm --needed --noprogressbar $COMMON_VULKAN_PACKAGES mesa lib32-mesa vulkan-intel lib32-vulkan-intel intel-media-driver libva-utils | tee -a "$LOG_FILE"
echo "LIBVA_DRIVER_NAME=iHD" >> /mnt/etc/environment
fi
if [[ "$AMD_GPU" == "true" ]]; then
# AMDGPU supports both VA-API and VDPAU, but we're only installing support for VA-API
arch-chroot /mnt pacman -S --noconfirm --needed --noprogressbar $COMMON_VULKAN_PACKAGES mesa lib32-mesa vulkan-radeon lib32-vulkan-radeon libva-mesa-driver lib32-libva-mesa-driver libva-utils | tee -a "$LOG_FILE"
echo "LIBVA_DRIVER_NAME=radeonsi" >> /mnt/etc/environment
fi
if [[ "$NVIDIA_GPU" == "true" ]]; then
arch-chroot /mnt pacman -S --noconfirm --needed --noprogressbar $COMMON_VULKAN_PACKAGES nvidia-dkms nvidia-utils lib32-nvidia-utils nvidia-settings | tee -a "$LOG_FILE"
# Configure pacman to rebuild the initramfs each time the nvidia package is updated
configure_pacman_nvidia_hook
fi
echo_to_log "===================="
echo_to_log "9. AUR configuration"
echo_to_log "===================="
# Install AUR helper
install_aur_helper
# Install AUR packages
# exec_as_user "paru -S --noconfirm --needed --noprogressbar xxx | tee -a $LOG_FILE"
echo_to_log "==========================="
echo_to_log "10. Additional pacman hooks"
echo_to_log "==========================="
# Configure pacman hook for upgrading pacman-mirrorlist package
configure_pacman_mirror_upgrade_hook
# Configure pacman hook for cleaning pacman cache
configure_pacman_clean_cache_hook
# Configure pacman hook for updating systemd-boot when systemd is updated
configure_pacman_systemd_boot_hook
echo_to_log "========================================="
echo_to_log "11. Clone repo for additional ingredients"
echo_to_log "========================================="
# Clone saki git repo so that user can run post-install recipe
arch-chroot -u $USER_NAME /mnt git clone --recursive https://github.com/rstrube/saki.git /home/${USER_NAME}/saki
if [ -n "$LOG_FILE" ]; then
cp ./${LOG_FILE} /mnt/home/${USER_NAME}/
fi
echo -e "${LBLUE}Installation has completed! Run 'reboot' to reboot your machine.${NC}"
}
function echo_to_log()
{
echo "$@"
echo "$@" >> "$LOG_FILE"
}
function check_critical_prereqs() {
check_variables_value "HD_DEVICE" "$HD_DEVICE"
if [[ ! -e "$HD_DEVICE" ]]; then
echo -e "${RED}Error: HD_DEVICE="$HD_DEVICE" does not exist.${NC}"
exit 1
fi
if [[ ! -d /sys/firmware/efi ]]; then
echo -e "${RED}Error: installation can only be run on UEFI systems.${NC}"
echo "If running in a VM, make sure the VM is configured to use UEFI instead of BIOS."
exit 1
fi
}
function check_variables() {
check_variables_value "HD_DEVICE" "$HD_DEVICE"
check_variables_boolean "TRIM_SUPPORT" "$TRIM_SUPPORT"
check_variables_value "SWAPFILE_SIZE" "$SWAPFILE_SIZE"
check_variables_boolean "AMD_CPU" "$AMD_CPU"
check_variables_boolean "INTEL_CPU" "$INTEL_CPU"
check_variables_boolean "AMD_GPU" "$AMD_GPU"
check_variables_boolean "INTEL_GPU" "$INTEL_GPU"
check_variables_boolean "NVIDIA_GPU" "$NVIDIA_GPU"
check_variables_value "PING_HOSTNAME" "$PING_HOSTNAME"
check_variables_value "HOSTNAME" "$HOSTNAME"
check_variables_value "TIMEZONE" "$TIMEZONE"
check_variables_value "KEYS" "$KEYS"
check_variables_value "LOCALE" "$LOCALE"
check_variables_value "LANG" "$LANG"
check_variables_value "REFLECTOR_COUNTRY" "$REFLECTOR_COUNTRY"
check_variables_value "ROOT_PASSWORD" "$ROOT_PASSWORD"
check_variables_value "USER_NAME" "$USER_NAME"
check_variables_value "USER_PASSWORD" "$USER_PASSWORD"
}
ERROR_VARS_MESSAGE="${RED}Error: you must edit saki.sh (e.g. with vim) and configure the required variables.${NC}"
function check_variables_value() {
local NAME=$1
local VALUE=$2
if [[ -z "$VALUE" ]]; then
echo -e $ERROR_VARS_MESSAGE
echo "$NAME must have a value."
exit 1
fi
}
function check_variables_boolean() {
local NAME=$1
local VALUE=$2
case $VALUE in
true )
;;
false )
;;
* )
echo -e $ERROR_VARS_MESSAGE
echo "$NAME must be {true|false}."
exit 1
;;
esac
}
function trim_variable() {
local VARIABLE="$1"
local VARIABLE=$(echo "$VARIABLE" | sed 's/^[[:space:]]*//') # trim leading
local VARIABLE=$(echo "$VARIABLE" | sed 's/[[:space:]]*$//') # trim trailing
echo "$VARIABLE"
}
function print_variables_value() {
local NAME=$1
local VALUE=$2
echo -e "$NAME = ${WHITE}${VALUE}${NC}"
}
function print_variables_boolean() {
local NAME=$1
local VALUE=$2
if [[ "$VALUE" == "true" ]]; then
echo -e "$NAME = ${GREEN}${VALUE}${NC}"
else
echo -e "$NAME = ${RED}${VALUE}${NC}"
fi
}
function check_conflicts() {
if [[ "$AMD_CPU" == "true" && "$INTEL_CPU" == "true" ]]; then
echo -e "${RED}Error: AMD_CPU and INTEL_CPU are mutually exclusve and can't both be set to 'true'.${NC}"
exit 1
fi
}
function check_network() {
ping -c 1 -i 2 -W 5 -w 30 $PING_HOSTNAME
if [ $? -ne 0 ]; then
echo "Error: Network ping check failed. Cannot continue."
exit 1
fi
}
function confirm_install() {
clear
echo -e "${LBLUE}Saki (Simple Arch KDE Installer)${NC}"
echo ""
echo -e "${RED}Warning"'!'"${NC}"
echo -e "${RED}This script will destroy all data on ${HD_DEVICE}${NC}"
echo ""
echo -e "${LBLUE}HD Configuration:${NC}"
print_variables_value "HD_DEVICE" "$HD_DEVICE"
print_variables_boolean "TRIM_SUPPORT" "$TRIM_SUPPORT"
print_variables_value "SWAPFILE_SIZE" "$SWAPFILE_SIZE"
echo ""
echo -e "${LBLUE}CPU Configuration:${NC}"
print_variables_boolean "AMD_CPU" "$AMD_CPU"
print_variables_boolean "INTEL_CPU" "$INTEL_CPU"
echo ""
echo -e "${LBLUE}GPU Configuration:${NC}"
print_variables_boolean "AMD_GPU" "$AMD_GPU"
print_variables_boolean "INTEL_GPU" "$INTEL_GPU"
print_variables_boolean "NVIDIA_GPU" "$NVIDIA_GPU"
echo ""
echo -e "${LBLUE}Host Configuration:${NC}"
print_variables_value "HOSTNAME" "$HOSTNAME"
print_variables_value "TIMEZONE" "$TIMEZONE"
print_variables_value "KEYS" "$KEYS"
print_variables_value "LOCALE" "$LOCALE"
print_variables_value "LANG" "$LANG"
print_variables_value "REFLECTOR_COUNTRY" "$REFLECTOR_COUNTRY"
echo ""
echo -e "${LBLUE}User Configuration:${NC}"
print_variables_value "ROOT_PASSWORD" "$ROOT_PASSWORD"
print_variables_value "USER_NAME" "$USER_NAME"
print_variables_value "USER_PASSWORD" "$USER_PASSWORD"
echo ""
echo -e "${LBLUE}Linux Command Line Params:${NC}"
print_variables_value "CMDLINE_LINUX" "$CMDLINE_LINUX"
echo ""
read -p "Do you want to continue? [y/N] " yn
case $yn in
[Yy]* )
;;
[Nn]* )
exit
;;
* )
exit
;;
esac
echo ""
}
function install_aur_helper() {
local COMMAND="rm -rf /home/$USER_NAME/.paru-makepkg && mkdir -p /home/$USER_NAME/.paru-makepkg && cd /home/$USER_NAME/.paru-makepkg && git clone https://aur.archlinux.org/paru.git && (cd paru && makepkg -si --noconfirm) && rm -rf /home/$USER_NAME/.paru-makepkg"
exec_as_user "$COMMAND"
}
function exec_as_user() {
local COMMAND="$1"
arch-chroot /mnt sed -i 's/^%wheel ALL=(ALL:ALL) ALL$/%wheel ALL=(ALL:ALL) NOPASSWD: ALL/' /etc/sudoers
arch-chroot /mnt bash -c "echo -e \"$USER_PASSWORD\n$USER_PASSWORD\n$USER_PASSWORD\n$USER_PASSWORD\n\" | su $USER_NAME -s /usr/bin/bash -c \"$COMMAND\""
arch-chroot /mnt sed -i 's/^%wheel ALL=(ALL:ALL) NOPASSWD: ALL$/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
}
function configure_pacman_systemd_boot_hook() {
if [[ ! -d "/mnt/etc/pacman.d/hooks" ]]; then
arch-chroot /mnt mkdir -p /etc/pacman.d/hooks
fi
cat <<EOT > "/mnt/etc/pacman.d/hooks/sytemd-boot.hook"
[Trigger]
Type=Package
Operation=Upgrade
Target=systemd
[Action]
Description=Gracefully upgrading systemd-boot...
When=PostTransaction
Exec=/usr/bin/systemctl restart systemd-boot-update.service
EOT
}
function configure_pacman_mirror_upgrade_hook() {
if [[ ! -d "/mnt/etc/pacman.d/hooks" ]]; then
arch-chroot /mnt mkdir -p /etc/pacman.d/hooks
fi
cat <<EOT > "/mnt/etc/pacman.d/hooks/pacman-mirror-upgrade.hook"
[Trigger]
Operation=Upgrade
Type=Package
Target=pacman-mirrorlist
[Action]
Description=Updating pacman-mirrorlist with reflector and removing pacnew...
When=PostTransaction
Depends=reflector
Exec=/bin/sh -c 'systemctl start reflector.service && rm -f /etc/pacman.d/mirrorlist.pacnew'
EOT
}
function configure_pacman_clean_cache_hook() {
if [[ ! -d "/mnt/etc/pacman.d/hooks" ]]; then
arch-chroot /mnt mkdir -p /etc/pacman.d/hooks
fi
cat <<EOT > "/mnt/etc/pacman.d/hooks/pacman-clean-cache.hook"
[Trigger]
Operation = Remove
Operation = Install
Operation = Upgrade
Type = Package
Target = *
[Action]
Description = Clearing pacman cache [The last 3 versions (including current) of a given package will be kept]...
When = PostTransaction
Exec = /usr/bin/paccache -rvuk0 && /usr/bin/paccache -rvk3
EOT
}
function configure_pacman_nvidia_hook() {
if [[ ! -d "/mnt/etc/pacman.d/hooks" ]]; then
arch-chroot /mnt mkdir -p /etc/pacman.d/hooks
fi
cat <<EOT > "/mnt/etc/pacman.d/hooks/nvidia.hook"
[Trigger]
Operation=Install
Operation=Upgrade
Operation=Remove
Type=Package
Target=nvidia
Target=linux
# Change the linux part above and in the Exec line if a different kernel is used
[Action]
Description=Updating initcpio with latest nvidia kernel module...
Depends=mkinitcpio
When=PostTransaction
NeedsTargets
Exec=/bin/sh -c 'while read -r trg; do case \$trg in linux) exit 0; esac; done; /usr/bin/mkinitcpio -P'
EOT
}
function configure_sddm() {
if [[ ! -d "/mnt/etc/sddm.conf.d" ]]; then
arch-chroot /mnt mkdir -p /etc/sddm.conf.d
fi
cp /mnt/usr/lib/sddm/sddm.conf.d/default.conf /mnt/etc/sddm.conf.d/
sed -i '$!N;s/# Current theme name\nCurrent=/# Current theme name\nCurrent=breeze/;P;D' /mnt/etc/sddm.conf.d/default.conf
}
# Console Colors
NC='\033[0m'
RED='\033[00;31m'
GREEN='\033[00;32m'
YELLOW='\033[00;33m'
BLUE='\033[00;34m'
PURPLE='\033[00;35m'
CYAN='\033[00;36m'
LIGHTGRAY='\033[00;37m'
LRED='\033[01;31m'
LGREEN='\033[01;32m'
LYELLOW='\033[01;33m'
LBLUE='\033[01;34m'
LPURPLE='\033[01;35m'
LCYAN='\033[01;36m'
WHITE='\033[01;37m'
main "$@"