#!/usr/bin/env bash # shellcheck shell=bash # # Configuration screens for the main menu. # # Each screen edits the structured configuration (CFG). Screens can be revisited # at any time before installation; nothing here touches a disk. _ui_ok() { return 0; } # _pick_from_list TITLE TEXT CANDIDATES... - radiolist, sets UI_RESULT _pick_from_list() { local title="$1" text="$2" current="$3"; shift 3 local -a items=() item for item in "$@"; do if [[ "$item" == "$current" ]]; then items+=("$item" "" on) else items+=("$item" "" off) fi done ui_radiolist "$title" "$text" 0 0 12 "${items[@]}" } # --------------------------------------------------------------------------- # 1. Keyboard # --------------------------------------------------------------------------- screen_keyboard() { local current choice custom current="$(config_get KEYMAP)" local -a layouts=(us gb de fr es it pt-br dvorak colemak ru pl nl se no dk "fi" cz hu tr jp kr) if _pick_from_list "Keyboard" "Select a console keymap:" "$current" "${layouts[@]}" other; then choice="$UI_RESULT" else return 0 fi if [[ "$choice" == "other" ]]; then ui_inputbox "Keyboard" "Enter a keymap name (e.g. us-acentos):" "$current" || return 0 custom="$UI_RESULT" [[ -n "$custom" ]] && config_set KEYMAP "$custom" else config_set KEYMAP "$choice" fi } # --------------------------------------------------------------------------- # 2. Network # --------------------------------------------------------------------------- screen_network() { local status action network_live_start status="$(network_status_text)" while true; do if ! ui_menu "Network" "$status Choose an action:" 18 70 5 \ status "Show interface status" \ wifi "Connect to a Wi-Fi network" \ refresh "Refresh status" \ "done" "Back"; then return 0 fi action="$UI_RESULT" case "$action" in status|refresh) status="$(network_status_text)" ;; wifi) local scan scan="$(network_wifi_scan)" if [[ -z "$scan" ]]; then ui_msgbox "Network" "No Wi-Fi networks found. You can configure networking later." continue fi local tmp tmp="$(mktemp)" printf '%s\n' "$scan" >"$tmp" local -a items=() local ssid sig sec while read -r ssid sig sec; do [[ -z "$ssid" ]] && continue items+=("$ssid" "${sig} ${sec}" off) done <"$tmp" rm -f "$tmp" ((${#items[@]})) || continue if ui_radiolist "Wi-Fi" "Select a network:" 0 0 12 "${items[@]}"; then ssid="$UI_RESULT" ui_passwordbox "Wi-Fi" "Passphrase for '$ssid' (blank for open):" || continue network_connect_wifi "$ssid" "$UI_RESULT" || ui_error "Could not connect to $ssid" fi ;; done) return 0 ;; esac done } # --------------------------------------------------------------------------- # 3. Source / installation media # --------------------------------------------------------------------------- screen_source() { local url sha while true; do if ! ui_menu "Source" "Stage3 source Mirror: $(config_get STAGE3_MIRROR) URL: $(config_get STAGE3_URL) SHA-256: $(config_get STAGE3_SHA256)" 16 74 4 \ auto "Use current stable systemd stage3" \ pin "Pin an explicit stage3 URL" \ sha "Set expected SHA-256" \ "done" "Back"; then return 0 fi case "$UI_RESULT" in auto) config_set STAGE3_URL ""; config_set STAGE3_SHA256 "" ;; pin) ui_inputbox "Source" "Stage3 tarball URL:" "$(config_get STAGE3_URL)" || continue config_set STAGE3_URL "$UI_RESULT" ;; sha) ui_inputbox "Source" "Expected SHA-256 (blank to clear):" "$(config_get STAGE3_SHA256)" || continue config_set STAGE3_SHA256 "$UI_RESULT" ;; done) return 0 ;; esac done } # --------------------------------------------------------------------------- # 4. Hostname # --------------------------------------------------------------------------- screen_hostname() { local hostname ui_inputbox "Hostname" "Enter the system hostname:" "$(config_get HOSTNAME)" || return 0 hostname="$UI_RESULT" if validate_hostname "$hostname" >/dev/null; then config_set HOSTNAME "$hostname" else ui_error "$(validate_hostname "$hostname")" fi } # --------------------------------------------------------------------------- # 5. Locale # --------------------------------------------------------------------------- screen_locale() { local current current="$(config_get LOCALE)" local -a locales=(en_US.UTF-8 en_GB.UTF-8 de_DE.UTF-8 fr_FR.UTF-8 es_ES.UTF-8 it_IT.UTF-8 pt_BR.UTF-8 nl_NL.UTF-8 pl_PL.UTF-8 ru_RU.UTF-8) if _pick_from_list "Locale" "Select the system locale:" "$current" "${locales[@]}" other; then if [[ "$UI_RESULT" == "other" ]]; then ui_inputbox "Locale" "Enter a locale (e.g. sv_SE.UTF-8):" "$current" || return 0 [[ -n "$UI_RESULT" ]] && config_set LOCALE "$UI_RESULT" else config_set LOCALE "$UI_RESULT" fi fi } # --------------------------------------------------------------------------- # 6. Timezone # --------------------------------------------------------------------------- screen_timezone() { local current current="$(config_get TIMEZONE)" local -a zones=(UTC Europe/London Europe/Berlin Europe/Paris Europe/Madrid Europe/Rome Europe/Amsterdam Europe/Warsaw America/New_York America/Chicago America/Denver America/Los_Angeles America/Sao_Paulo Asia/Tokyo Asia/Shanghai Asia/Kolkata Australia/Sydney) if _pick_from_list "Timezone" "Select the timezone:" "$current" "${zones[@]}" other; then if [[ "$UI_RESULT" == "other" ]]; then ui_inputbox "Timezone" "Enter a timezone (e.g. Europe/Stockholm):" "$current" || return 0 [[ -n "$UI_RESULT" ]] && config_set TIMEZONE "$UI_RESULT" else config_set TIMEZONE "$UI_RESULT" fi fi } # --------------------------------------------------------------------------- # 7. User account # --------------------------------------------------------------------------- screen_user() { local username fullname while true; do if ! ui_menu "User account" "Username: $(config_get USERNAME) Full name: $(config_get USER_FULLNAME) Groups: $(config_get USER_GROUPS)" 15 74 4 \ username "Set username" \ fullname "Set full name" \ password "Set password" \ "done" "Back"; then return 0 fi case "$UI_RESULT" in username) ui_inputbox "User account" "Username:" "$(config_get USERNAME)" || continue username="$UI_RESULT" if validate_username "$username" >/dev/null; then config_set USERNAME "$username" else ui_error "$(validate_username "$username")" fi ;; fullname) ui_inputbox "User account" "Full name:" "$(config_get USER_FULLNAME)" || continue config_set USER_FULLNAME "$UI_RESULT" ;; password) users_prompt_passwords || ui_error "Could not set password" ;; done) return 0 ;; esac done } # --------------------------------------------------------------------------- # 8. Disk # --------------------------------------------------------------------------- screen_disk() { local current disk reason current="$(config_get TARGET_DISK)" disks_refresh if ((${#DISK_LIST[@]} == 0)); then ui_error "No disks were detected." return 0 fi local -a items=() for disk in "${DISK_LIST[@]}"; do reason="$(disk_protected_reason "$disk")" if [[ -n "$reason" ]]; then continue fi if [[ "$disk" == "$current" ]]; then items+=("$disk" "$(disk_display_line "$disk")" on) else items+=("$disk" "$(disk_display_line "$disk")" off) fi done if ((${#items[@]} == 0)); then ui_error "No safe target disks found. All detected disks are protected (live medium, mounted, or read-only)." return 0 fi if ui_radiolist "Disk" "Select the installation target. All data on the selected disk will be destroyed later, after review." \ 0 0 10 "${items[@]}"; then config_set TARGET_DISK "$UI_RESULT" local tmp tmp="$(mktemp)" disk_layout_text "$UI_RESULT" >"$tmp" 2>/dev/null ui_textbox "Current layout: $UI_RESULT" "$tmp" rm -f "$tmp" fi } # --------------------------------------------------------------------------- # 9. Filesystem / encryption # --------------------------------------------------------------------------- screen_filesystem() { local action while true; do if ! ui_menu "Filesystem" "Filesystem: $(config_get FILESYSTEM) Encryption: $(config_get ENCRYPTION) Compression: $(config_get COMPRESS) EFI size: $(config_get EFI_SIZE_MIB) MiB" 17 74 6 \ fs "Change filesystem" \ encryption "Change encryption" \ passphrase "Set encryption passphrase" \ compress "Change Btrfs compression" \ efi "Change EFI partition size" \ "done" "Back"; then return 0 fi case "$UI_RESULT" in fs) if _pick_from_list "Filesystem" "Select the root filesystem:" "$(config_get FILESYSTEM)" btrfs ext4; then config_set FILESYSTEM "$UI_RESULT" fi ;; encryption) if _pick_from_list "Encryption" "Select encryption for the root partition:" "$(config_get ENCRYPTION)" luks2 none; then config_set ENCRYPTION "$UI_RESULT" fi ;; passphrase) encryption_configure || ui_error "Passphrase not set" ;; compress) ui_inputbox "Filesystem" "Btrfs compression (zstd:3 recommended):" "$(config_get COMPRESS)" || continue config_set COMPRESS "$UI_RESULT" ;; efi) ui_inputbox "Filesystem" "EFI partition size in MiB:" "$(config_get EFI_SIZE_MIB)" || continue [[ "$UI_RESULT" =~ ^[0-9]+$ ]] && config_set EFI_SIZE_MIB "$UI_RESULT" ;; done) return 0 ;; esac done } # --------------------------------------------------------------------------- # 10. Boot # --------------------------------------------------------------------------- screen_boot() { local action while true; do if ! ui_menu "Boot" "Bootloader: $(config_get BOOTLOADER) Unified UKI: $(config_get KERNEL_UKI) Secure Boot: $(config_get SECUREBOOT) Keep kernels: $(config_get KEEP_KERNELS) Secure Boot status: $(boot_secureboot_status)" 18 74 4 \ uki "Toggle Unified Kernel Image" \ keep "Set number of kernels to keep" \ secure "Toggle Secure Boot preference (not enforced yet)" \ "done" "Back"; then return 0 fi case "$UI_RESULT" in uki) if config_bool KERNEL_UKI; then config_set KERNEL_UKI no; else config_set KERNEL_UKI yes; fi ;; keep) ui_inputbox "Boot" "Number of kernels to keep (>=2):" "$(config_get KEEP_KERNELS)" || continue if [[ "$UI_RESULT" =~ ^[0-9]+$ ]] && ((UI_RESULT >= 2)); then config_set KEEP_KERNELS "$UI_RESULT" else ui_error "Keep at least 2 kernels so a known-good kernel is always available." fi ;; secure) if config_bool SECUREBOOT; then config_set SECUREBOOT no; else config_set SECUREBOOT yes; fi ;; done) return 0 ;; esac done } # --------------------------------------------------------------------------- # 11. Kernel # --------------------------------------------------------------------------- screen_kernel() { local action while true; do if ! ui_menu "Kernel" "Profile: $(config_get KERNEL_PROFILE) Package: $(kernel_select_package) UKI: $(config_get KERNEL_UKI) Recommended for this machine: $(hw_recommended_kernel_profile)" 17 74 4 \ profile "Select kernel profile" \ package "Select kernel package" \ "done" "Back"; then return 0 fi case "$UI_RESULT" in profile) if _pick_from_list "Kernel" "safe = prebuilt distribution kernel optimized = distribution kernel, conservative local fragments (default) aggressive = distribution sources with a locally tuned config" \ "$(config_get KERNEL_PROFILE)" safe optimized aggressive; then config_set KERNEL_PROFILE "$UI_RESULT" fi ;; package) ui_inputbox "Kernel" "Kernel package:" "$(config_get KERNEL_PACKAGE)" || continue config_set KERNEL_PACKAGE "$UI_RESULT" ;; done) return 0 ;; esac done } # --------------------------------------------------------------------------- # 12. Package policy # --------------------------------------------------------------------------- screen_packages() { local action while true; do if ! ui_menu "Packages" "Policy: $(config_get PACKAGE_POLICY) Binary packages: $(config_get FEATURES_BINPKG) Accept license: $(config_get ACCEPT_LICENSE) source_first - compile everything possible balanced - compile cheap/frequent, use binaries for huge packages (default) binary_first - prefer binaries whenever available" 19 76 5 \ policy "Change policy" \ binpkg "Toggle binary packages" \ license "Change accepted licenses" \ show "Show example decisions" \ "done" "Back"; then return 0 fi case "$UI_RESULT" in policy) if _pick_from_list "Packages" "Select the package policy:" "$(config_get PACKAGE_POLICY)" source_first balanced binary_first; then config_set PACKAGE_POLICY "$UI_RESULT" fi ;; binpkg) if config_bool FEATURES_BINPKG; then config_set FEATURES_BINPKG no; else config_set FEATURES_BINPKG yes; fi ;; license) ui_inputbox "Packages" "ACCEPT_LICENSE value:" "$(config_get ACCEPT_LICENSE)" || continue config_set ACCEPT_LICENSE "$UI_RESULT" ;; show) local tmp tmp="$(mktemp)" pkgpolicy_report >"$tmp" ui_textbox "Package policy examples" "$tmp" rm -f "$tmp" ;; done) return 0 ;; esac done } # --------------------------------------------------------------------------- # 13. Desktop # --------------------------------------------------------------------------- screen_desktop() { local action while true; do if ! ui_menu "Desktop" "Profile: $(config_get DESKTOP_PROFILE) Flatpak: $(config_get FLATPAK) Audio: $(config_get AUDIO_STACK) none - server / no graphical session minimal - Wayland libraries and XWayland only dwl - dwl tiling desktop with Waybar, fuzzel, mako, ... full - dwl plus Flatpak, BlueZ and keyring" 20 76 5 \ profile "Select desktop profile" \ flatpak "Toggle Flatpak" \ "done" "Back"; then return 0 fi case "$UI_RESULT" in profile) if _pick_from_list "Desktop" "Select the desktop profile:" "$(config_get DESKTOP_PROFILE)" none minimal dwl full; then config_set DESKTOP_PROFILE "$UI_RESULT" fi ;; flatpak) if config_bool FLATPAK; then config_set FLATPAK no; else config_set FLATPAK yes; fi ;; done) return 0 ;; esac done } # --------------------------------------------------------------------------- # 14. AI configuration # --------------------------------------------------------------------------- screen_ai() { local action while true; do if ! ui_menu "AI assistant" "$(ai_status_text)" 18 76 4 \ configure "Configure provider and model" \ bootstrap "Install / verify OpenCode" \ test "Test OpenCode availability" \ "done" "Back"; then return 0 fi case "$UI_RESULT" in configure) ai_configure ;; bootstrap) if opencode_bootstrap; then ui_msgbox "AI assistant" "OpenCode installed and verified." else ui_error "OpenCode installation failed. See the log for details." fi ;; test) if opencode_available; then local bin ver bin="$(opencode_detect)" ver="$(opencode_print_version "$bin")" ui_msgbox "AI assistant" "OpenCode found: $bin version: ${ver:-unknown}" else ui_msgbox "AI assistant" "OpenCode is not installed. Use 'Install / verify OpenCode'." fi ;; done) return 0 ;; esac done }