diff --git a/src/packages.sh b/src/packages.sh new file mode 100644 index 0000000..667c948 --- /dev/null +++ b/src/packages.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# === Motivation === +# Install all required packages for a bootable Void Linux system. + +# === Problem Statement === +# The installer must provide a minimal base system without relying on void-installer. + +# === Scope === +# In scope: package installation, repository synchronization, dependency resolution. +# Out of scope: package selection UI, custom repository configuration. + +# === Concepts === +# XBPS: Void's package manager, handles installation and dependency resolution. +# chroot: Execute package installation in the target system environment. +# Repository sync: Update package index before installation. + +# === Decisions === +# Install minimal package set by default for base CLI system. +# Support optional package installation via config (future: config file support). +# Use xbps-install with sync (-S) and yes (-y) flags for non-interactive installation. +# Ensure network connectivity before package installation (handled by live environment). +# Package list is conservative: only essentials for boot + network + basic tools. + +# === Alternatives Considered === +# Interactive package selection rejected (violates CLI-only requirement). +# Separate kernel installation rejected (included in base-system dependency). +# systemd-based packages rejected (Void uses runit). + +# === Constraints === +# Target system must be mounted at $MOUNT_ROOT. +# Repository must be accessible via network. +# xbps must be available in live environment. + +# === Open Questions === +# Should firmware packages beyond linux-firmware be included (e.g., nvidia, AMD)? +# Should we validate package availability before installation? +# How to handle optional packages (desktop environments, development tools)? + +# === Success Criteria === +# All required packages are installed in the target system. +# Package manager can be used in the installed system post-reboot. +# System can boot with network connectivity and basic tools available. + +packages_install() { + : "${MOUNT_ROOT:?Mount root is required}" + require_command xbps-install + + log_info "Package installation: installing base system" + + # Define minimal package set for bootable CLI system + local base_packages=( + "base-system" # Essential base packages (includes kernel via dependency) + "linux" # Linux kernel + "linux-firmware" # Firmware blobs for hardware + "grub" # Bootloader + "cryptsetup" # LUKS encryption tools + "dracut" # initramfs generator + ) + + local network_packages=( + "dhcpcd" # DHCP client for network + "iproute2" # ip command for network configuration + "iputils" # ping, traceroute, etc. + ) + + local system_tools=( + "vim" # Text editor + "nano" # Alternative text editor + "sudo" # Privilege escalation + ) + + # Combine all package arrays + local all_packages=("${base_packages[@]}" "${network_packages[@]}" "${system_tools[@]}") + + log_info "Package list: ${all_packages[*]}" + log_info "Installing ${#all_packages[@]} packages (this may take several minutes)..." + + # Ensure repository is accessible and synchronized + # Use chroot to install packages into target system + if ! chroot "$MOUNT_ROOT" xbps-install -Syu "${all_packages[@]}"; then + die "Package installation failed. Check network connectivity and repository status." + fi + + log_info "Package installation complete." + + # Verify critical packages are installed + log_info "Verifying package installation..." + local critical_packages=("base-system" "linux" "grub" "cryptsetup") + for pkg in "${critical_packages[@]}"; do + if ! chroot "$MOUNT_ROOT" xbps-query "$pkg" >/dev/null 2>&1; then + die "Critical package not found: $pkg" + fi + done + + log_info "Package verification passed." +}