#!/usr/bin/env bash # shellcheck shell=bash # # Installation plan generation. # # The plan is a deterministic, human-readable description of the operations the # backend will perform. Nothing is executed until the plan has been displayed # and explicitly approved (see install.sh). declare -ga PLAN_LINES=() declare -ga PLAN_STEPS=() _plan_add() { PLAN_LINES+=("$@"); } _step() { PLAN_STEPS+=("$*"); } # plan_swap_mib - swapfile size in MiB derived from installed RAM plan_swap_mib() { local mem mem="$(hw_mem_total_mib)" [[ -n "$mem" ]] || mem=4096 local swap=$((mem / 2)) ((swap < 1024)) && swap=1024 ((swap > 8192)) && swap=8192 printf '%s' "$swap" } # plan_storage_sizes - sets PLAN_EFI_MIB and PLAN_LUKS_MIB plan_storage_sizes() { local disk="${1:-$(config_get TARGET_DISK)}" total efi PLAN_EFI_MIB="$(config_get EFI_SIZE_MIB)" [[ "$PLAN_EFI_MIB" =~ ^[0-9]+$ ]] || PLAN_EFI_MIB=1024 total=0 if [[ -b "$disk" ]]; then total="$(disk_size_bytes "$disk")" fi PLAN_LUKS_MIB=$(( (total / 1048576) - PLAN_EFI_MIB - 2 )) ((PLAN_LUKS_MIB < 0)) && PLAN_LUKS_MIB=0 } # plan_generate - build PLAN_LINES and PLAN_STEPS from CFG plan_generate() { PLAN_LINES=() PLAN_STEPS=() local disk hostname locale tz username fs enc kprofile desktop policy disk="$(config_get TARGET_DISK)" hostname="$(config_get HOSTNAME)" locale="$(config_get LOCALE)" tz="$(config_get TIMEZONE)" username="$(config_get USERNAME)" fs="$(config_get FILESYSTEM)" enc="$(config_get ENCRYPTION)" kprofile="$(config_get KERNEL_PROFILE)" desktop="$(config_get DESKTOP_PROFILE)" policy="$(config_get PACKAGE_POLICY)" _plan_add "Installation plan" _plan_add "=================" _plan_add "" _plan_add "System:" _plan_add " Distribution : $(config_get DISTRO_NAME)" _plan_add " Architecture : $(config_get ARCH)" _plan_add " Init system : $(config_get INIT_SYSTEM)" _plan_add " Firmware : $(hw_firmware_mode)" _plan_add "" _plan_add "Identity:" _plan_add " Hostname : $hostname" _plan_add " Keymap : $(config_get KEYMAP)" _plan_add " Locale : $locale" _plan_add " Timezone : $tz" _plan_add " User : ${username:-}" _plan_add "" _plan_add "Storage:" _plan_add " Target disk : ${disk:-}" if [[ -n "$disk" && -b "$disk" ]]; then _plan_add " Disk model : $(disk_model "$disk")" _plan_add " Disk size : $(disk_size_human "$(disk_size_bytes "$disk")")" fi _plan_add " Partitioning : GPT (${PARTITION_SCHEME:-whole_disk})" _plan_add " Encryption : ${enc:-none}" _plan_add " Filesystem : $fs" _plan_add "" _plan_add " Layout:" _plan_add " EFI System Partition (FAT32) $(config_get EFI_SIZE_MIB) MiB -> $(config_get EFI_MOUNT)" _plan_add " $(printf '%-36s' "${enc^^} container") remainder" _plan_add " $(printf '%-34s' "$fs")" local subvol for subvol in $(config_get BTRFS_SUBVOLS); do _plan_add " $subvol" done _plan_add "" _plan_add "Boot and kernel:" _plan_add " Bootloader : $(config_get BOOTLOADER) (BLS entries)" _plan_add " Unified UKI : $(config_get KERNEL_UKI) (deferred; BLS used)" _plan_add " Kernel : $(kernel_select_package 2>/dev/null || config_get KERNEL_PACKAGE) ($kprofile profile)" _plan_add " Keep kernels : $(config_get KEEP_KERNELS)" _plan_add "" _plan_add "Software:" _plan_add " Package policy : $policy" _plan_add " Binary pkgs : $(config_get FEATURES_BINPKG)" _plan_add " Accept license : $(config_get ACCEPT_LICENSE)" _plan_add " Desktop : $desktop" _plan_add " Flatpak : $(config_get FLATPAK)" _plan_add " Audio : $(config_get AUDIO_STACK)" _plan_add " AI assistant : $(config_get AI_ENABLED)" # Ordered execution steps (names map to backend functions in install.sh). _step "storage_prepare" _step "stage_install" _step "fstab_generate" _step "portage_configure" _step "packages_base" _step "kernel_install" _step "boot_install" _step "users_configure" _step "services_configure" _step "desktop_install" _step "finalize" } # plan_render - print the full plan plan_render() { printf '%s\n' "${PLAN_LINES[@]}"; } # plan_destructive_preview - the scary, explicit summary shown before wiping plan_destructive_preview() { local disk enc fs disk="$(config_get TARGET_DISK)" enc="$(config_get ENCRYPTION)" fs="$(config_get FILESYSTEM)" printf 'TARGET: %s\n' "$disk" printf '\n' printf 'ALL DATA ON THIS DEVICE WILL BE DESTROYED.\n' printf 'This cannot be undone.\n' printf '\n' printf ' EFI (FAT32): %s MiB\n' "$(config_get EFI_SIZE_MIB)" if [[ "$enc" != "none" && -n "$enc" ]]; then printf ' %s (passphrase): remainder\n' "${enc^^}" fi printf ' %s:\n' "$fs" local subvol for subvol in $(config_get BTRFS_SUBVOLS); do printf ' %s\n' "$subvol" done printf '\n' printf 'Existing partitions on the target:\n' disk_layout_text "$disk" 2>/dev/null | sed 's/^/ /' }