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:
2026-01-17 10:58:37 -05:00
parent 6b70ce8a97
commit f6fe732b4b
8 changed files with 40 additions and 110 deletions

View File

@@ -33,32 +33,19 @@ NVIDIA_PACKAGES=(
libva-nvidia-driver libva-nvidia-driver
) )
# Install Intel graphics drivers
install_intel_graphics() {
print "Installing Intel graphics drivers..."
chroot_install "${INTEL_PACKAGES[@]}"
}
# Install NVIDIA graphics drivers
install_nvidia_graphics() {
print "Installing NVIDIA graphics drivers..."
chroot_install "${NVIDIA_PACKAGES[@]}"
}
# Prompt user for graphics driver selection and install # Prompt user for graphics driver selection and install
prompt_install_graphics() { prompt_install_graphics() {
print "Would you like to install graphics drivers? Type 'intel' exactly for Intel graphics drivers, 'nvidia' for NVIDIA graphics drivers, or anything else to skip." prompt_menu "Would you like to install graphics drivers?" "Intel" "NVIDIA" "Skip"
read -r driver
case "$driver" in case "$MENU_SELECTION" in
"intel") 1)
install_intel_graphics print "Installing Intel graphics drivers..."
chroot_pacman_install "${INTEL_PACKAGES[@]}"
;; ;;
"nvidia") 2)
install_nvidia_graphics print "Installing NVIDIA graphics drivers..."
;; chroot_pacman_install "${NVIDIA_PACKAGES[@]}"
*)
print "Skipping graphics driver installation."
;; ;;
*) print "Skipping graphics driver installation." ;;
esac esac
} }

View File

@@ -61,12 +61,7 @@ XFCE_PACKAGES=(
# Install XFCE base packages # Install XFCE base packages
install_xfce_packages() { install_xfce_packages() {
chroot_install "${XFCE_PACKAGES[@]}" chroot_pacman_install "${XFCE_PACKAGES[@]}"
}
# Enable LightDM display manager
enable_lightdm() {
chroot_enable lightdm.service
} }
# Configure LightDM greeter # Configure LightDM greeter
@@ -109,7 +104,7 @@ install_xfce() {
local username="$1" local username="$1"
install_xfce_packages install_xfce_packages
enable_lightdm chroot_systemd_enable lightdm.service
configure_lightdm configure_lightdm
copy_xfce_config "$username" copy_xfce_config "$username"
} }

View File

@@ -98,24 +98,9 @@ close_luks_container() {
# Returns: # Returns:
# 0 on success, 1 on mismatch # 0 on success, 1 on mismatch
prompt_encryption_password() { prompt_encryption_password() {
local password if ! prompt_password "Please enter your desired encryption passphrase." ENCRYPTION_PASSWORD; then
local password_confirm
print "Please enter your desired encryption passphrase."
read -rs password
echo
print "Please confirm your encryption passphrase."
read -rs password_confirm
echo
if [ "$password" != "$password_confirm" ]; then
print_error "Passphrases do not match."
return 1 return 1
fi fi
ENCRYPTION_PASSWORD="$password"
unset password password_confirm
return 0 return 0
} }

View File

@@ -30,17 +30,20 @@ chroot_run() {
arch-chroot "${MOUNT_POINT}" "$@" arch-chroot "${MOUNT_POINT}" "$@"
} }
# Install packages in the chroot environment # Install packages in the chroot environment using pacman
# Arguments: # Arguments:
# $@ - package names # $@ - package names
chroot_install() { chroot_pacman_install() {
run_visible_cmd chroot_run pacman --noconfirm -S "$@" run_visible_cmd chroot_run pacman --noconfirm -S "$@"
} }
# Enable a systemd service in the chroot environment # Enable systemd units in the chroot environment
# Arguments: # Arguments:
# $@ - service names # $@ - unit names (services, timers, etc.)
chroot_enable() { chroot_systemd_enable() {
for unit in "$@"; do
print "Enabling ${unit}..."
done
run_visible_cmd chroot_run systemctl enable "$@" run_visible_cmd chroot_run systemctl enable "$@"
} }
@@ -80,10 +83,10 @@ install_microcode() {
case "$vendor" in case "$vendor" in
"intel") "intel")
chroot_install intel-ucode chroot_pacman_install intel-ucode
;; ;;
"amd") "amd")
chroot_install amd-ucode chroot_pacman_install amd-ucode
;; ;;
*) *)
print_warning "Unknown CPU vendor: ${vendor}. Please install microcode manually after installation, if available." print_warning "Unknown CPU vendor: ${vendor}. Please install microcode manually after installation, if available."

View File

@@ -55,41 +55,24 @@ configure_mirrorlist() {
echo "Server = ${MIRROR_URL}" > /etc/pacman.d/mirrorlist echo "Server = ${MIRROR_URL}" > /etc/pacman.d/mirrorlist
} }
# Enable systemd-resolved # Enable systemd-resolved and configure resolv.conf symlink
enable_resolved() { enable_resolved() {
print "Enabling systemd-resolved..." chroot_systemd_enable systemd-resolved.service
chroot_enable systemd-resolved.service
ln -sf ../run/systemd/resolve/stub-resolv.conf "${MOUNT_POINT}/etc/resolv.conf" 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 and install iwd for Wi-Fi support
prompt_install_wifi() { prompt_install_wifi() {
print "Would you like to install iwd for Wi-Fi support? Enter 'y' exactly for yes, otherwise anything else to skip." if confirm "Would you like to install iwd for Wi-Fi support?"; then
read -r install_iwd
if [ "$install_iwd" = "y" ]; then
print "Installing iwd..." print "Installing iwd..."
chroot_install iwd chroot_pacman_install iwd
chroot_enable iwd.service chroot_systemd_enable iwd.service
fi fi
} }
# Full network setup # Full network setup
setup_network() { setup_network() {
enable_resolved enable_resolved
enable_networkd chroot_systemd_enable systemd-networkd.service
enable_timesyncd chroot_systemd_enable systemd-timesyncd.service
} }

View File

@@ -36,21 +36,14 @@ configure_initramfs() {
run_visible_cmd chroot_run mkinitcpio -P run_visible_cmd chroot_run mkinitcpio -P
} }
# Enable fstrim timer for SSD maintenance # Enable BTRFS scrub timer if using BTRFS filesystem
enable_fstrim() {
print "Enabling fstrim timer..."
chroot_enable fstrim.timer
}
# Enable BTRFS scrub timer
# Arguments: # Arguments:
# $1 - filesystem type # $1 - filesystem type
enable_btrfs_scrub() { enable_btrfs_scrub() {
local filesystem="$1" local filesystem="$1"
if [ "$filesystem" = "btrfs" ] || [ "$filesystem" = "btrfs-dup" ]; then if [ "$filesystem" = "btrfs" ] || [ "$filesystem" = "btrfs-dup" ]; then
print "Enabling btrfs scrub timer..." chroot_systemd_enable btrfs-scrub@-.timer
chroot_enable btrfs-scrub@-.timer
fi fi
} }
@@ -66,18 +59,6 @@ disable_root() {
chroot_run passwd -l 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 # Configure SSH server
# Arguments: # Arguments:
# $1 - username to allow SSH access # $1 - username to allow SSH access
@@ -88,7 +69,7 @@ configure_ssh() {
chroot_run sed -i "s|PLACEHOLDER|${username}|" /etc/ssh/sshd_config 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 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 # Display SSH host key fingerprint
@@ -113,7 +94,7 @@ configure_usbguard() {
read -r read -r
chroot_run sh -c "usbguard generate-policy > /etc/usbguard/rules.conf" chroot_run sh -c "usbguard generate-policy > /etc/usbguard/rules.conf"
chroot_enable usbguard.service chroot_systemd_enable usbguard.service
} }
# Full security setup # Full security setup
@@ -124,8 +105,8 @@ setup_security() {
configure_sudo configure_sudo
disable_root disable_root
enable_firewall chroot_systemd_enable nftables.service
enable_smartd chroot_systemd_enable smartd.service
enable_fstrim chroot_systemd_enable fstrim.timer
enable_btrfs_scrub "$filesystem" enable_btrfs_scrub "$filesystem"
} }

View File

@@ -22,14 +22,10 @@
# Sets: # Sets:
# USERNAME - the entered username # USERNAME - the entered username
prompt_username() { prompt_username() {
local username
while true; do while true; do
print "Please enter the username you'd like to use for your account:" prompt "Please enter the username you'd like to use for your account:" USERNAME
read -r username
if validate_username "$username"; then if validate_username "$USERNAME"; then
USERNAME="$username"
return 0 return 0
fi fi

View File

@@ -153,14 +153,14 @@ install_profile() {
packages=$(get_profile_packages "$profile") packages=$(get_profile_packages "$profile")
if [ -n "$packages" ]; then if [ -n "$packages" ]; then
# shellcheck disable=SC2086 # shellcheck disable=SC2086
chroot_install $packages chroot_pacman_install $packages
fi fi
# Enable profile services # Enable profile services
services=$(get_profile_services "$profile") services=$(get_profile_services "$profile")
if [ -n "$services" ]; then if [ -n "$services" ]; then
# shellcheck disable=SC2086 # shellcheck disable=SC2086
chroot_enable $services chroot_systemd_enable $services
fi fi
} }