Refactored helpers to reduce duplication and improve naming.
- Renamed chroot_install/chroot_enable to chroot_pacman_install/chroot_systemd_enable. - Made chroot_systemd_enable auto-print status, removing need for wrapper functions. - Used generic prompt helpers instead of duplicating logic in specialized functions. - Inlined and removed single-use wrapper functions throughout.
This commit is contained in:
@@ -30,17 +30,20 @@ chroot_run() {
|
||||
arch-chroot "${MOUNT_POINT}" "$@"
|
||||
}
|
||||
|
||||
# Install packages in the chroot environment
|
||||
# Install packages in the chroot environment using pacman
|
||||
# Arguments:
|
||||
# $@ - package names
|
||||
chroot_install() {
|
||||
chroot_pacman_install() {
|
||||
run_visible_cmd chroot_run pacman --noconfirm -S "$@"
|
||||
}
|
||||
|
||||
# Enable a systemd service in the chroot environment
|
||||
# Enable systemd units in the chroot environment
|
||||
# Arguments:
|
||||
# $@ - service names
|
||||
chroot_enable() {
|
||||
# $@ - unit names (services, timers, etc.)
|
||||
chroot_systemd_enable() {
|
||||
for unit in "$@"; do
|
||||
print "Enabling ${unit}..."
|
||||
done
|
||||
run_visible_cmd chroot_run systemctl enable "$@"
|
||||
}
|
||||
|
||||
@@ -80,10 +83,10 @@ install_microcode() {
|
||||
|
||||
case "$vendor" in
|
||||
"intel")
|
||||
chroot_install intel-ucode
|
||||
chroot_pacman_install intel-ucode
|
||||
;;
|
||||
"amd")
|
||||
chroot_install amd-ucode
|
||||
chroot_pacman_install amd-ucode
|
||||
;;
|
||||
*)
|
||||
print_warning "Unknown CPU vendor: ${vendor}. Please install microcode manually after installation, if available."
|
||||
|
||||
@@ -55,41 +55,24 @@ configure_mirrorlist() {
|
||||
echo "Server = ${MIRROR_URL}" > /etc/pacman.d/mirrorlist
|
||||
}
|
||||
|
||||
# Enable systemd-resolved
|
||||
# Enable systemd-resolved and configure resolv.conf symlink
|
||||
enable_resolved() {
|
||||
print "Enabling systemd-resolved..."
|
||||
|
||||
chroot_enable systemd-resolved.service
|
||||
chroot_systemd_enable systemd-resolved.service
|
||||
ln -sf ../run/systemd/resolve/stub-resolv.conf "${MOUNT_POINT}/etc/resolv.conf"
|
||||
}
|
||||
|
||||
# Enable systemd-networkd
|
||||
enable_networkd() {
|
||||
print "Enabling systemd-networkd..."
|
||||
chroot_enable systemd-networkd.service
|
||||
}
|
||||
|
||||
# Enable systemd-timesyncd
|
||||
enable_timesyncd() {
|
||||
print "Enabling systemd-timesyncd..."
|
||||
chroot_enable systemd-timesyncd.service
|
||||
}
|
||||
|
||||
# Prompt and install iwd for Wi-Fi support
|
||||
prompt_install_wifi() {
|
||||
print "Would you like to install iwd for Wi-Fi support? Enter 'y' exactly for yes, otherwise anything else to skip."
|
||||
read -r install_iwd
|
||||
|
||||
if [ "$install_iwd" = "y" ]; then
|
||||
if confirm "Would you like to install iwd for Wi-Fi support?"; then
|
||||
print "Installing iwd..."
|
||||
chroot_install iwd
|
||||
chroot_enable iwd.service
|
||||
chroot_pacman_install iwd
|
||||
chroot_systemd_enable iwd.service
|
||||
fi
|
||||
}
|
||||
|
||||
# Full network setup
|
||||
setup_network() {
|
||||
enable_resolved
|
||||
enable_networkd
|
||||
enable_timesyncd
|
||||
chroot_systemd_enable systemd-networkd.service
|
||||
chroot_systemd_enable systemd-timesyncd.service
|
||||
}
|
||||
|
||||
@@ -36,21 +36,14 @@ configure_initramfs() {
|
||||
run_visible_cmd chroot_run mkinitcpio -P
|
||||
}
|
||||
|
||||
# Enable fstrim timer for SSD maintenance
|
||||
enable_fstrim() {
|
||||
print "Enabling fstrim timer..."
|
||||
chroot_enable fstrim.timer
|
||||
}
|
||||
|
||||
# Enable BTRFS scrub timer
|
||||
# Enable BTRFS scrub timer if using BTRFS filesystem
|
||||
# Arguments:
|
||||
# $1 - filesystem type
|
||||
enable_btrfs_scrub() {
|
||||
local filesystem="$1"
|
||||
|
||||
if [ "$filesystem" = "btrfs" ] || [ "$filesystem" = "btrfs-dup" ]; then
|
||||
print "Enabling btrfs scrub timer..."
|
||||
chroot_enable btrfs-scrub@-.timer
|
||||
chroot_systemd_enable btrfs-scrub@-.timer
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -66,18 +59,6 @@ disable_root() {
|
||||
chroot_run passwd -l root
|
||||
}
|
||||
|
||||
# Enable nftables firewall
|
||||
enable_firewall() {
|
||||
print "Enabling nftables firewall..."
|
||||
chroot_enable nftables.service
|
||||
}
|
||||
|
||||
# Enable smartd for drive monitoring
|
||||
enable_smartd() {
|
||||
print "Enabling smartd..."
|
||||
chroot_enable smartd.service
|
||||
}
|
||||
|
||||
# Configure SSH server
|
||||
# Arguments:
|
||||
# $1 - username to allow SSH access
|
||||
@@ -88,7 +69,7 @@ configure_ssh() {
|
||||
|
||||
chroot_run sed -i "s|PLACEHOLDER|${username}|" /etc/ssh/sshd_config
|
||||
run_visible_cmd chroot_run ssh-keygen -t ed25519 -C "" -N "" -f /etc/ssh/ssh_host_ed25519_key
|
||||
chroot_enable sshd.service
|
||||
chroot_systemd_enable sshd.service
|
||||
}
|
||||
|
||||
# Display SSH host key fingerprint
|
||||
@@ -113,7 +94,7 @@ configure_usbguard() {
|
||||
read -r
|
||||
|
||||
chroot_run sh -c "usbguard generate-policy > /etc/usbguard/rules.conf"
|
||||
chroot_enable usbguard.service
|
||||
chroot_systemd_enable usbguard.service
|
||||
}
|
||||
|
||||
# Full security setup
|
||||
@@ -124,8 +105,8 @@ setup_security() {
|
||||
|
||||
configure_sudo
|
||||
disable_root
|
||||
enable_firewall
|
||||
enable_smartd
|
||||
enable_fstrim
|
||||
chroot_systemd_enable nftables.service
|
||||
chroot_systemd_enable smartd.service
|
||||
chroot_systemd_enable fstrim.timer
|
||||
enable_btrfs_scrub "$filesystem"
|
||||
}
|
||||
|
||||
@@ -22,14 +22,10 @@
|
||||
# Sets:
|
||||
# USERNAME - the entered username
|
||||
prompt_username() {
|
||||
local username
|
||||
|
||||
while true; do
|
||||
print "Please enter the username you'd like to use for your account:"
|
||||
read -r username
|
||||
prompt "Please enter the username you'd like to use for your account:" USERNAME
|
||||
|
||||
if validate_username "$username"; then
|
||||
USERNAME="$username"
|
||||
if validate_username "$USERNAME"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user