diff --git a/debianito.sh b/debianito.sh index 13605de..d968614 100644 --- a/debianito.sh +++ b/debianito.sh @@ -1,132 +1,99 @@ #!/usr/bin/env bash -# Debianito +# Debianito — simple configurator script set -euo pipefail - RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' -# ------------------- -# Load modules -# ----------------- +# TUI dimensions — fixed centered size for whiptail dialogs +TUI_ALTO=20 +TUI_ANCHO=78 +TUI_ALTO_LISTA=10 + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" MODULES_DIR="${SCRIPT_DIR}/modules" source "${MODULES_DIR}/utils.sh" source "${MODULES_DIR}/sudo_config.sh" source "${MODULES_DIR}/repos.sh" -if [ -f "${MODULES_DIR}/firmware.sh" ]; then - source "${MODULES_DIR}/firmware.sh" -fi -if [ -f "${MODULES_DIR}/gpu.sh" ]; then - source "${MODULES_DIR}/gpu.sh" -fi -if [ -f "${MODULES_DIR}/kernel.sh" ]; then - source "${MODULES_DIR}/kernel.sh" -fi -if [ -f "${MODULES_DIR}/gaming.sh" ]; then - source "${MODULES_DIR}/gaming.sh" -fi -if [ -f "${MODULES_DIR}/extras.sh" ]; then - source "${MODULES_DIR}/extras.sh" -fi -if [ -f "${MODULES_DIR}/zram.sh" ]; then - source "${MODULES_DIR}/zram.sh" -fi +[ -f "${MODULES_DIR}/firmware.sh" ] && source "${MODULES_DIR}/firmware.sh" +[ -f "${MODULES_DIR}/gpu.sh" ] && source "${MODULES_DIR}/gpu.sh" +[ -f "${MODULES_DIR}/kernel.sh" ] && source "${MODULES_DIR}/kernel.sh" +[ -f "${MODULES_DIR}/gaming.sh" ] && source "${MODULES_DIR}/gaming.sh" +[ -f "${MODULES_DIR}/extras.sh" ] && source "${MODULES_DIR}/extras.sh" +[ -f "${MODULES_DIR}/zram.sh" ] && source "${MODULES_DIR}/zram.sh" -# -------------------------- -# Global state -# -------------------------- REPOS_CONFIGURED=false DEBIAN_VERSION="" DEBIAN_CODENAME="" -# --------------------------------- -# Pause helper -# --------------------------------- -pause() { - echo "" - read -p "Press Enter to continue..." -} - -# --------------------------------- -# menu -# --------------------------------- - -if ! echo "╔" | grep -q "t"; then - BOX_DRAWING=false -else - BOX_DRAWING=true -fi - main_menu() { - PS3="Select an option (1-9): " - options=( - "User Privileges & Feedback" - "Configure repositories" - "Setup Wireless & Firmware" - "Configure Graphics Stack and Tools" - "Update Kernel to Backports" - "Gaming Setup and Performance" - "Install ZRAM (compressed swap)" - "Install extra applications" - "Exit" - ) + # Auto-adjust TUI dimensions for small terminals + if [ "$LINES" -lt $((TUI_ALTO + 6)) ] || [ "$COLUMNS" -lt $((TUI_ANCHO + 6)) ]; then + TUI_ALTO=$((LINES - 4 > 8 ? LINES - 4 : 8)) + TUI_ANCHO=$((COLUMNS - 4 > 50 ? COLUMNS - 4 : 50)) + TUI_ALTO_LISTA=$((TUI_ALTO - 10 > 4 ? TUI_ALTO - 10 : 4)) + fi while true; do - echo "" - printf "${RED}╔═══════════════════════════════╗\n" >&2 - printf "║ DEBIANITO ║\n" >&2 - printf "║ Debian Post-Install Setup ║\n" >&2 - printf "╚═══════════════════════════════╝\n${NC}" >&2 + local choice + choice=$(whiptail --title "DEBIANITO — simple configurator script" --menu "" \ + $TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \ + "1" "System Info" \ + "2" "User Privileges & Feedback" \ + "3" "Configure repositories" \ + "4" "Wireless & Firmware" \ + "5" "Graphics Stack" \ + "6" "Backports Kernel" \ + "7" "Gaming Setup" \ + "8" "ZRAM (Swap)" \ + "9" "Install Programs and Software" \ + "10" "Exit" \ + 3>&1 1>&2 2>&3) - echo -e "\033[1;97m║─────────── SYSTEM INFO ─────┤\n${NC}\033[0m" - echo "Detected: Debian ${DEBIAN_VERSION} (${DEBIAN_CODENAME})" - echo "Kernel: ${KERNEL_VERSION}" - echo "CPU: $(get_cpu_summary)" - echo "RAM: $(get_ram_summary)" - if [ -n "$GPU_VERSION" ]; then - echo "GPU: ${GPU_DESC} (${GPU_VERSION})" - else - echo "GPU: ${GPU_DESC}" - fi - if [ -n "$ETH_DESC" ] && [ -n "$WIFI_DESC" ]; then - echo "Network:" - echo " Ethernet: ${ETH_DESC}" - echo " WiFi: ${WIFI_DESC}" - elif [ -n "$ETH_DESC" ]; then - echo "Network: ${ETH_DESC}" - elif [ -n "$WIFI_DESC" ]; then - echo "Network: ${WIFI_DESC}" - else - echo "Network: No adapters detected" - fi - echo "" + clear - select opt in "${options[@]}"; do - case $REPLY in - 1) config_sudo || true ;; - 2) configure_repos || true ;; - 3) install_firmware || true ;; - 4) install_gpu_drivers || true ;; - 5) install_kernel_backports || true ;; - 6) install_gaming || true ;; - 7) install_zram || true ;; - 8) install_extras || true ;; - 9) echo "Exiting."; exit 0 ;; - *) echo "Invalid choice. Please try again." ;; - esac - [ "$REPLY" != "9" ] && [ "$REPLY" != "" ] && pause - break - done + case "$choice" in + 1) _show_sysinfo ;; + 2) config_sudo || true ;; + 3) configure_repos || true ;; + 4) install_firmware || true ;; + 5) install_gpu_drivers || true ;; + 6) install_kernel_backports || true ;; + 7) install_gaming || true ;; + 8) install_zram || true ;; + 9) install_extras || true ;; + 10) echo "Exiting."; exit 0 ;; + esac done } -# ---------------- -# Pre-run checks -# ---------------- +_show_sysinfo() { + local gpu_info="${GPU_DESC}" + [ -n "$GPU_VERSION" ] && gpu_info+=" (${GPU_VERSION})" + + local network_info + if [ -n "$ETH_DESC" ] && [ -n "$WIFI_DESC" ]; then + network_info="Ethernet: ${ETH_DESC}\nWiFi: ${WIFI_DESC}" + elif [ -n "$ETH_DESC" ]; then + network_info="${ETH_DESC}" + elif [ -n "$WIFI_DESC" ]; then + network_info="${WIFI_DESC}" + else + network_info="No adapters detected" + fi + + _msg "System Information" \ + "Debian: ${DEBIAN_VERSION} (${DEBIAN_CODENAME}) +Kernel: ${KERNEL_VERSION} +CPU: $(get_cpu_summary) +RAM: $(get_ram_summary) +GPU: ${gpu_info} +Network: ${network_info}" 13 65 +} + check_root check_sudo diff --git a/modules/extras.sh b/modules/extras.sh index 09b2ba5..e2b1d4d 100644 --- a/modules/extras.sh +++ b/modules/extras.sh @@ -15,68 +15,60 @@ install_extras() { fetch_pkg="fastfetch" fi - ! command -v dialog &>/dev/null && sudo apt install -y dialog 2>/dev/null || true - - if dialog --title "Quick Install" --yesno \ - "Install recommended tools?\n\n - Compression tools (zip, unzip, rar, 7z)\n - ${fetch_pkg} (system info)\n - htop (process viewer)\n - VLC (media player)\n - inxi (system information)\n - Microsoft fonts (Times New Roman, Arial)\n\n[Yes - Quick Install] [No - Select individually]" 16 65; then - echo "Installing recommended tools..." - local quick_pkgs=() - ! is_installed "zip" && quick_pkgs+=("zip") - ! is_installed "unzip" && quick_pkgs+=("unzip") - ! is_installed "rar" && quick_pkgs+=("rar") - ! is_installed "unrar" && quick_pkgs+=("unrar") - ! is_installed "p7zip-full" && quick_pkgs+=("p7zip-full") - ! is_installed "p7zip-rar" && quick_pkgs+=("p7zip-rar") - ! is_installed "$fetch_pkg" && quick_pkgs+=("$fetch_pkg") - ! is_installed "htop" && quick_pkgs+=("htop") - ! is_installed "vlc" && quick_pkgs+=("vlc") - ! is_installed "inxi" && quick_pkgs+=("inxi") - ! is_installed "ttf-mscorefonts-installer" && quick_pkgs+=("ttf-mscorefonts-installer") - if [ ${#quick_pkgs[@]} -gt 0 ]; then - sudo apt install -y "${quick_pkgs[@]}" - else - echo "All recommended tools are already installed." - fi - echo -e "${GREEN}Recommended tools installed.${NC}" - return + if _is_headless; then + _msg "Headless Mode" "No graphical display detected.\n\nOnly terminal-friendly packages will be shown.\nGUI applications (browsers, media players, design tools)\nwill be skipped automatically." 12 60 fi while true; do local cat_choice - cat_choice=$(dialog --title "Extra Software" --menu \ - "Select a category:" 20 68 9 \ + cat_choice=$(whiptail --title "Extra Software" --menu \ + "Select a category:" $TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \ + "0" "Essential Pack" \ "1" "System Tools" \ "2" "Development & Servers" \ "3" "Media Players" \ "4" "Web Browsers" \ - "5" "GTK Themes" \ - "6" "Icon Themes" \ - "7" "Fetch / System Info" \ - "8" "Download & Network" \ - "9" "Multimedia & Design" \ - "10" "Back to main menu" \ + "5" "Customization System" \ + "6" "Fetch / System Info" \ + "7" "Download & Network" \ + "8" "Multimedia & Design" \ + "9" "Back to main menu" \ 3>&1 1>&2 2>&3) [ -z "$cat_choice" ] && return - tput reset 2>/dev/null || clear + clear case "$cat_choice" in + 0) _quick_install ;; 1) _cat_general ;; 2) _cat_dev ;; 3) _cat_players ;; 4) _cat_browsers ;; - 5) _cat_themes ;; - 6) _cat_icons ;; - 7) _cat_fetch ;; - 8) _cat_download ;; - 9) _cat_design ;; - 10) return ;; + 5) _cat_customization ;; + 6) _cat_fetch ;; + 7) _cat_download ;; + 8) _cat_design ;; + 9) return ;; esac clear done } +_quick_install() { + _msg "Essential Pack" \ + "Install basic programs:\n\n - Compression (zip, unrar, 7z)\n - System tools (htop, inxi, fastfetch)\n - VLC media player\n - Microsoft fonts" 13 60 + + local quick_pkgs=( + zip unzip rar unrar p7zip-full p7zip-rar + "$fetch_pkg" htop vlc inxi ttf-mscorefonts-installer + ) + _run_install_batch "${quick_pkgs[@]}" + echo -e "${GREEN}Essential Pack installed.${NC}" +} + _cat_general() { + local headless=false + _is_headless && headless=true local alacritty_state="OFF"; is_installed "alacritty" && alacritty_state="ON" local btop_state="OFF"; is_installed "btop" && btop_state="ON" local compress_state="OFF"; is_installed "zip" && is_installed "unzip" && is_installed "p7zip-full" && compress_state="ON" @@ -104,9 +96,10 @@ _cat_general() { local tmux_state="OFF"; is_installed "tmux" && tmux_state="ON" local ttf_state="OFF"; is_installed "ttf-mscorefonts-installer" && ttf_state="ON" + local TUI_ANCHO_REFORZADO=$((TUI_ANCHO + 6)) local choices - choices=$(dialog --title "System Tools" --checklist \ - "Select system utilities to install:" 30 72 26 \ + choices=$(whiptail --title "System Tools" --checklist \ + "Select system utilities to install (26 items, ↑↓ scroll):" $TUI_ALTO $TUI_ANCHO_REFORZADO $TUI_ALTO_LISTA \ "alacritty" "GPU-accelerated terminal$(_inst alacritty)" "$alacritty_state" \ "btop" "Resource monitor (fancy top)$(_inst btop)" "$btop_state" \ "compress" "Compression tools (zip, unrar, 7z)$(_inst zip)" "$compress_state" \ @@ -151,8 +144,7 @@ _cat_general() { ! is_installed "p7zip-full" && need+=("p7zip-full") ! is_installed "p7zip-rar" && need+=("p7zip-rar") if [ ${#need[@]} -gt 0 ]; then - echo "Installing compression utilities..." - sudo apt install -y "${need[@]}" + _run_install_batch "${need[@]}" echo -e "${GREEN}Compression utilities installed.${NC}" fi ;; @@ -161,21 +153,19 @@ _cat_general() { ! is_installed "curl" && need+=("curl") ! is_installed "wget" && need+=("wget") if [ ${#need[@]} -gt 0 ]; then - echo "Installing HTTP tools..." - sudo apt install -y "${need[@]}" + _run_install_batch "${need[@]}" else echo "curl and wget already installed." fi ;; flatpak) if ! is_installed "flatpak"; then - echo "Installing Flatpak..." - sudo apt install -y flatpak + _run_cmd "Flatpak" "sudo apt install -y flatpak" "Installing Flatpak..." if command -v plasma-discover &>/dev/null; then - sudo apt install -y plasma-discover-backend-flatpak + _run_cmd "Flatpak" "sudo apt install -y plasma-discover-backend-flatpak" "Installing Flatpak backend..." echo "Flatpak backend for Discover installed." elif command -v gnome-software &>/dev/null; then - sudo apt install -y gnome-software-plugin-flatpak + _run_cmd "Flatpak" "sudo apt install -y gnome-software-plugin-flatpak" "Installing Flatpak plugin..." echo "Flatpak plugin for GNOME Software installed." fi else @@ -188,9 +178,7 @@ _cat_general() { ;; kvm) if ! is_installed "virt-manager"; then - echo "Installing QEMU/KVM virtualization..." - sudo apt install -y qemu-system-x86 qemu-utils libvirt-daemon-system \ - libvirt-clients bridge-utils virt-manager + _run_cmd "KVM" "sudo apt install -y qemu-system-x86 qemu-utils libvirt-daemon-system libvirt-clients bridge-utils virt-manager" "Installing KVM..." sudo adduser "$USER" libvirt 2>/dev/null || true sudo adduser "$USER" kvm 2>/dev/null || true echo -e "${GREEN}QEMU/KVM installed. A reboot is recommended.${NC}" @@ -199,8 +187,12 @@ _cat_general() { fi ;; *) + if $headless; then + echo "Skipping $pkg (headless mode)" + continue + fi if ! is_installed "$pkg"; then - sudo apt install -y "$pkg" + _run_install "$pkg" else echo "$pkg already installed." fi @@ -212,6 +204,8 @@ _cat_general() { } _cat_dev() { + local headless=false + _is_headless && headless=true local apache_state="OFF"; is_installed "apache2" && apache_state="ON" local build_state="OFF"; is_installed "build-essential" && build_state="ON" local certbot_state="OFF"; is_installed "certbot" && certbot_state="ON" @@ -231,9 +225,9 @@ _cat_dev() { local ufw_state="OFF"; is_installed "ufw" && ufw_state="ON" local zenmap_state="OFF"; is_installed "zenmap" && zenmap_state="ON" - local choices - choices=$(dialog --title "Development & Servers" --checklist \ - "Select development tools and servers:" 26 72 18 \ + local TUI_ANCHO_REFORZADO=$((TUI_ANCHO + 6)) + choices=$(whiptail --title "Development & Servers" --checklist \ + "Select development tools and servers (18 items, ↑↓ scroll):" $TUI_ALTO $TUI_ANCHO_REFORZADO $TUI_ALTO_LISTA \ "apache2" "Apache web server$(_inst apache2)" "$apache_state" \ "build-essential" "C/C++ build tools (gcc, make)$(_inst build-essential)" "$build_state" \ "certbot" "Let's Encrypt TLS certificates$(_inst certbot)" "$certbot_state" \ @@ -267,8 +261,7 @@ _cat_dev() { ! is_installed "python3-venv" && need+=("python3-venv") ! is_installed "python3-dev" && need+=("python3-dev") if [ ${#need[@]} -gt 0 ]; then - echo "Installing Python 3 development tools..." - sudo apt install -y "${need[@]}" + _run_install_batch "${need[@]}" else echo "Python 3 tools already installed." fi @@ -278,8 +271,7 @@ _cat_dev() { ! is_installed "docker.io" && need+=("docker.io") ! is_installed "docker-compose" && need+=("docker-compose") if [ ${#need[@]} -gt 0 ]; then - echo "Installing Docker..." - sudo apt install -y "${need[@]}" + _run_install_batch "${need[@]}" else echo "Docker already installed." fi @@ -289,7 +281,7 @@ _cat_dev() { ;; *) if ! is_installed "$pkg"; then - sudo apt install -y "$pkg" + _run_install "$pkg" else echo "$pkg already installed." fi @@ -301,13 +293,16 @@ _cat_dev() { } _cat_players() { + local headless=false + _is_headless && headless=true local handbrake_state="OFF"; is_installed "handbrake" && handbrake_state="ON" local mpv_state="OFF"; is_installed "mpv" && mpv_state="ON" local vlc_state="OFF"; is_installed "vlc" && vlc_state="ON" + local TUI_ANCHO_REFORZADO=$((TUI_ANCHO + 6)) local choices - choices=$(dialog --title "Media Players" --checklist \ - "Select media players:" 12 72 3 \ + choices=$(whiptail --title "Media Players" --checklist \ + "Select media players:" $TUI_ALTO $TUI_ANCHO_REFORZADO $TUI_ALTO_LISTA \ "handbrake" "Video transcoder (DVD ripper)$(_inst handbrake)" "$handbrake_state" \ "mpv" "Lightweight media player$(_inst mpv)" "$mpv_state" \ "vlc" "VLC media player$(_inst vlc)" "$vlc_state" \ @@ -319,8 +314,12 @@ _cat_players() { local cleaned; cleaned=$(echo "$choices" | tr -d '"') for pkg in $cleaned; do + if $headless; then + echo "Skipping $pkg (headless mode)" + continue + fi if ! is_installed "$pkg"; then - sudo apt install -y "$pkg" + _run_install "$pkg" else echo "$pkg already installed." fi @@ -330,6 +329,8 @@ _cat_players() { } _cat_browsers() { + local headless=false + _is_headless && headless=true local chromium_state="OFF"; is_installed "chromium" && chromium_state="ON" local dillo_state="OFF"; is_installed "dillo" && dillo_state="ON" local elinks_state="OFF"; is_installed "elinks" && elinks_state="ON" @@ -349,8 +350,8 @@ _cat_browsers() { local w3m_state="OFF"; is_installed "w3m" && w3m_state="ON" local choices - choices=$(dialog --title "Web Browsers" --checklist \ - "Select web browsers:" 24 72 14 \ + choices=$(whiptail --title "Web Browsers" --checklist \ + "Select web browsers:" $TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \ "chromium" "Chromium web browser$(_inst chromium)" "$chromium_state" \ "dillo" "Lightweight graphical browser$(_inst dillo)" "$dillo_state" \ "elinks" "Text-mode web browser$(_inst elinks)" "$elinks_state" \ @@ -380,8 +381,8 @@ _cat_browsers() { floorp) if ! is_installed "floorp"; then echo "Setting up Floorp repository..." - ! is_installed "curl" && sudo apt install -y curl - ! is_installed "gpg" && sudo apt install -y gpg + ! is_installed "curl" && _run_install curl + ! is_installed "gpg" && _run_install gpg sudo install -d -m 0755 /etc/apt/keyrings curl -fsSL https://ppa.floorp.app/KEY.gpg | \ sudo gpg --dearmor -o /usr/share/keyrings/Floorp.gpg @@ -392,8 +393,8 @@ Package: * Pin: origin ppa.floorp.app Pin-Priority: 1000 EOF - sudo apt update - sudo apt install -y floorp + _run_cmd "APT Update" "sudo apt update" "Updating package lists..." + _run_install floorp echo -e "${GREEN}Floorp installed.${NC}" else echo "Floorp already installed." @@ -402,10 +403,10 @@ EOF librewolf) if ! is_installed "librewolf"; then echo "Installing LibreWolf..." - sudo apt install -y extrepo + _run_install extrepo sudo extrepo enable librewolf 2>/dev/null || true - sudo apt update - sudo apt install -y librewolf + _run_cmd "APT Update" "sudo apt update" "Updating package lists..." + _run_install librewolf echo -e "${GREEN}LibreWolf installed.${NC}" else echo "LibreWolf already installed." @@ -418,15 +419,18 @@ EOF ! is_installed "ca-certificates" && need+=("ca-certificates") ! is_installed "xsel" && need+=("xsel") if [ ${#need[@]} -gt 0 ]; then - echo "Installing w3m and dependencies..." - sudo apt install -y "${need[@]}" + _run_install_batch w3m w3m-img ca-certificates xsel else echo "w3m already installed." fi ;; *) + if $headless; then + echo "Skipping $pkg (headless mode)" + continue + fi if ! is_installed "$pkg"; then - sudo apt install -y "$pkg" + _run_install "$pkg" else echo "$pkg already installed." fi @@ -437,7 +441,24 @@ EOF echo -e "${GREEN}Web browsers installed.${NC}" } +_cat_customization() { + local TUI_ANCHO_REFORZADO=$((TUI_ANCHO + 6)) + local sub + sub=$(whiptail --title "Customization System" --menu \ + "Select type:" $TUI_ALTO $TUI_ANCHO_REFORZADO $TUI_ALTO_LISTA \ + "1" "GTK Themes" \ + "2" "Icon Themes" \ + 3>&1 1>&2 2>&3) + [ -z "$sub" ] && return + case $sub in + 1) _cat_themes ;; + 2) _cat_icons ;; + esac +} + _cat_themes() { + local headless=false + _is_headless && headless=true local arc_state="OFF"; is_installed "arc-theme" && arc_state="ON" local blackbird_state="OFF"; is_installed "blackbird-gtk-theme" && blackbird_state="ON" local bluebird_state="OFF"; is_installed "bluebird-gtk-theme" && bluebird_state="ON" @@ -447,8 +468,8 @@ _cat_themes() { local orchis_state="OFF"; is_installed "orchis-gtk-theme" && orchis_state="ON" local choices - choices=$(dialog --title "GTK Themes" --checklist \ - "Select GTK themes to install:" 16 72 7 \ + choices=$(whiptail --title "GTK Themes" --checklist \ + "Select GTK themes to install:" $TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \ "arc-theme" "Arc GTK theme$(_inst arc-theme)" "$arc_state" \ "blackbird-gtk-theme" "Blackbird GTK theme$(_inst blackbird-gtk-theme)" "$blackbird_state" \ "bluebird-gtk-theme" "Bluebird GTK theme$(_inst bluebird-gtk-theme)" "$bluebird_state" \ @@ -464,8 +485,12 @@ _cat_themes() { local cleaned; cleaned=$(echo "$choices" | tr -d '"') for pkg in $cleaned; do + if $headless; then + echo "Skipping $pkg (headless mode)" + continue + fi if ! is_installed "$pkg"; then - sudo apt install -y "$pkg" + _run_install "$pkg" else echo "$pkg already installed." fi @@ -475,6 +500,8 @@ _cat_themes() { } _cat_icons() { + local headless=false + _is_headless && headless=true local breeze_state="OFF"; is_installed "breeze-icon-theme" && breeze_state="ON" local deepin_state="OFF"; is_installed "deepin-icon-theme" && deepin_state="ON" local ele_state="OFF"; is_installed "elementary-icon-theme" && ele_state="ON" @@ -494,8 +521,6 @@ _cat_icons() { has_kf6=true fi - local height=18 - local list_height=11 local items=( "breeze-icon-theme" "Breeze icon theme$(_inst breeze-icon-theme)" "$breeze_state" "deepin-icon-theme" "Deepin icon theme$(_inst deepin-icon-theme)" "$deepin_state" @@ -511,13 +536,11 @@ _cat_icons() { ) if $has_kf6; then items+=("kf6-breeze-icon-theme" "KF6 Breeze icon theme$(_inst kf6-breeze-icon-theme)" "$kf6_state") - height=20 - list_height=12 fi local choices - choices=$(dialog --title "Icon Themes" --checklist \ - "Select icon themes to install:" "$height" 72 "$list_height" \ + choices=$(whiptail --title "Icon Themes" --checklist \ + "Select icon themes to install:" $TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \ "${items[@]}" \ 3>&1 1>&2 2>&3) clear @@ -527,8 +550,12 @@ _cat_icons() { local cleaned; cleaned=$(echo "$choices" | tr -d '"') for pkg in $cleaned; do + if $headless; then + echo "Skipping $pkg (headless mode)" + continue + fi if ! is_installed "$pkg"; then - sudo apt install -y "$pkg" + _run_install "$pkg" else echo "$pkg already installed." fi @@ -555,14 +582,11 @@ _cat_fetch() { fi local items=() - local height=14 - local list_height=3 if [ "$fetch_pkg" = "fastfetch" ]; then items+=("fastfetch" "System info fetcher$(_inst fastfetch)" "$fetch_state") if [ "$DEBIAN_CODENAME" = "trixie" ]; then items+=("hyfetch" "Neofetch with pride flags$(_inst hyfetch)" "$hyfetch_state") - height=16; list_height=4 fi fi items+=("linuxlogo" "Linux logo + system info$(_inst linuxlogo)" "$linuxlogo_state") @@ -570,14 +594,14 @@ _cat_fetch() { items+=("neofetch" "System info fetcher$(_inst neofetch)" "$fetch_state") if [ "$DEBIAN_CODENAME" = "trixie" ]; then items+=("hyfetch" "Neofetch with pride flags$(_inst hyfetch)" "$hyfetch_state") - height=16; list_height=4 fi fi items+=("screenfetch" "System info (BSD/Linux)$(_inst screenfetch)" "$screenfetch_state") + local TUI_ANCHO_REFORZADO=$((TUI_ANCHO + 6)) local choices - choices=$(dialog --title "Fetch Tools" --checklist \ - "Select system info tools:" "$height" 72 "$list_height" \ + choices=$(whiptail --title "Fetch Tools" --checklist \ + "Select system info tools:" $TUI_ALTO $TUI_ANCHO_REFORZADO $TUI_ALTO_LISTA \ "${items[@]}" \ 3>&1 1>&2 2>&3) clear @@ -590,14 +614,14 @@ _cat_fetch() { case $pkg in neofetch|fastfetch) if ! is_installed "$pkg"; then - sudo apt install -y "$pkg" + _run_install "$pkg" else echo "$pkg already installed." fi ;; *) if ! is_installed "$pkg"; then - sudo apt install -y "$pkg" + _run_install "$pkg" else echo "$pkg already installed." fi @@ -609,6 +633,8 @@ _cat_fetch() { } _cat_download() { + local headless=false + _is_headless && headless=true local aria2_state="OFF"; is_installed "aria2" && aria2_state="ON" local filezilla_state="OFF"; is_installed "filezilla" && filezilla_state="ON" local riseupvpn_state="OFF"; is_installed "riseup-vpn" && riseupvpn_state="ON" @@ -624,10 +650,11 @@ _cat_download() { local tr_gtk_state="OFF"; is_installed "transmission-gtk" && tr_gtk_state="ON" local tr_qt_state="OFF"; is_installed "transmission-qt" && tr_qt_state="ON" + local TUI_ANCHO_REFORZADO=$((TUI_ANCHO + 6)) local choices1 choices2="" - choices1=$(dialog --title "Download & Network — Downloaders" --checklist \ - "Select download tools:" 16 72 5 \ + choices1=$(whiptail --title "Download & Network — Downloaders" --checklist \ + "Select download tools:" $TUI_ALTO $TUI_ANCHO_REFORZADO $TUI_ALTO_LISTA \ "aria2" "Multiprotocol downloader (CLI)$(_inst aria2)" "$aria2_state" \ "filezilla" "FTP/SFTP client (GUI)$(_inst filezilla)" "$filezilla_state" \ "riseup-vpn" "Riseup VPN client$(_inst riseup-vpn)" "$riseupvpn_state" \ @@ -636,8 +663,8 @@ _cat_download() { 3>&1 1>&2 2>&3) clear - choices2=$(dialog --title "Download & Network — Torrent Clients" --checklist \ - "Select torrent clients:" 18 72 8 \ + choices2=$(whiptail --title "Download & Network — Torrent Clients" --checklist \ + "Select torrent clients:" $TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \ "deluge" "BitTorrent client (GTK)$(_inst deluge)" "$deluge_state" \ "deluged" "BitTorrent daemon/server$(_inst deluged)" "$deluged_state" \ "mktorrent" "Torrent metainfo creator (CLI)$(_inst mktorrent)" "$mktorrent_state" \ @@ -669,8 +696,12 @@ _cat_download() { install_backports_or_stable qbittorrent-nox ;; *) + if $headless; then + echo "Skipping $pkg (headless mode)" + continue + fi if ! is_installed "$pkg"; then - sudo apt install -y "$pkg" + _run_install "$pkg" else echo "$pkg already installed." fi @@ -682,6 +713,8 @@ _cat_download() { } _cat_design() { + local headless=false + _is_headless && headless=true local audacity_state="OFF"; is_installed "audacity" && audacity_state="ON" local ardour_state="OFF"; is_installed "ardour" && ardour_state="ON" local blender_state="OFF"; is_installed "blender" && blender_state="ON" @@ -696,8 +729,8 @@ _cat_design() { local shotcut_state="OFF"; is_installed "shotcut" && shotcut_state="ON" local choices - choices=$(dialog --title "Multimedia & Design" --checklist \ - "Select multimedia and design tools:" 20 72 12 \ + choices=$(whiptail --title "Multimedia & Design" --checklist \ + "Select multimedia and design tools:" $TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \ "audacity" "Audio editor/recorder$(_inst audacity)" "$audacity_state" \ "ardour" "Digital audio workstation$(_inst ardour)" "$ardour_state" \ "blender" "3D modeling/animation suite$(_inst blender)" "$blender_state" \ @@ -718,8 +751,12 @@ _cat_design() { local cleaned; cleaned=$(echo "$choices" | tr -d '"') for pkg in $cleaned; do + if $headless; then + echo "Skipping $pkg (headless mode)" + continue + fi if ! is_installed "$pkg"; then - sudo apt install -y "$pkg" + _run_install "$pkg" else echo "$pkg already installed." fi @@ -737,8 +774,7 @@ install_firefox_mozilla() { echo "Setting up Mozilla APT repository for Firefox..." if is_installed "firefox-esr"; then - if whiptail --title "Firefox ESR" --yesno \ - "Firefox ESR is installed.\n\nRemove it before installing Mozilla Firefox?\n\nChoose No to keep both Firefox versions." 11 60; then + if _confirm "Firefox ESR" "Firefox ESR is installed.\nRemove it before installing Mozilla Firefox?"; then echo "Removing Firefox ESR..." sudo apt remove -y firefox-esr else @@ -746,8 +782,8 @@ install_firefox_mozilla() { fi fi - ! is_installed "wget" && sudo apt install -y wget - ! is_installed "gpg" && sudo apt install -y gpg + ! is_installed "wget" && _run_install wget + ! is_installed "gpg" && _run_install gpg sudo install -d -m 0755 /etc/apt/keyrings @@ -784,8 +820,8 @@ Pin: origin packages.mozilla.org Pin-Priority: 1000 EOF - sudo apt update - sudo apt install -y firefox + _run_cmd "APT Update" "sudo apt update" "Updating package lists..." + _run_install firefox echo -e "${GREEN}Firefox (Mozilla) installed.${NC}" } diff --git a/modules/firmware.sh b/modules/firmware.sh index f60bbb6..9727865 100644 --- a/modules/firmware.sh +++ b/modules/firmware.sh @@ -14,8 +14,7 @@ install_firmware() { fw_ver=$(apt-cache policy firmware-linux-nonfree 2>/dev/null | awk 'NR==3 {print $2; exit}') fw_pkgs=" - firmware-linux-nonfree ${fw_ver}\n" fi - if ! whiptail --title "Base Firmware" --yesno \ - "Install the following package?\n\n${fw_pkgs}\nProvides firmware for various hardware components.\n\nProceed?" 14 65; then + if ! _confirm "Base Firmware" "Install firmware?\n\n${fw_pkgs}"; then echo "Skipping base firmware." return fi @@ -23,9 +22,9 @@ install_firmware() { echo -e "${YELLOW}Installing base firmware...${NC}" local pkg="firmware-linux-nonfree" if [ "$(is_backports_enabled)" == true ] && [ -n "$fw_bpo" ]; then - sudo apt install -y -t "${DEBIAN_CODENAME}-backports" $pkg + _run_cmd "Firmware" "sudo apt install -y -t ${DEBIAN_CODENAME}-backports $pkg" "Installing firmware from backports..." else - sudo apt install -y $pkg + _run_cmd "Firmware" "sudo apt install -y $pkg" "Installing firmware..." fi echo -e "${GREEN}Base firmware installed.${NC}" @@ -57,12 +56,11 @@ handle_wifi_firmware() { if echo "$supported_ids" | grep -qw "$device_id"; then echo "Chipset supported by firmware-brcm80211. Installing..." - sudo apt install -y firmware-brcm80211 + _run_cmd "WiFi" "sudo apt install -y firmware-brcm80211" "Installing Broadcom firmware..." else # Offer to install broadcom-sta-dkms for older chips - if whiptail --title "Broadcom WiFi" \ - --yesno "Your Broadcom chipset may require the proprietary driver (broadcom-sta-dkms).\nThis will also install linux-headers and compile a kernel module.\n\nInstall broadcom-sta-dkms?" 12 70; then - sudo apt install -y linux-headers-$(uname -r) broadcom-sta-dkms + if _confirm "Broadcom WiFi" "Install broadcom-sta-dkms?\n\nRequired for this Broadcom chipset.\nCompiles a kernel module (needs linux-headers)."; then + _run_cmd "Broadcom" "sudo apt install -y linux-headers-$(uname -r) broadcom-sta-dkms" "Installing Broadcom driver..." echo "Broadcom proprietary driver installed. A reboot may be required." else echo "Skipping Broadcom driver installation." diff --git a/modules/gaming.sh b/modules/gaming.sh index 40a000b..53157dd 100644 --- a/modules/gaming.sh +++ b/modules/gaming.sh @@ -6,8 +6,7 @@ install_gaming() { # 1. 32-bit support prompt FIRST local enable_32bit=false - if whiptail --title "32-bit Support" --yesno \ - "Enable 32-bit architecture for gaming?\n\nThis enables i386 support and installs 32-bit\ngraphics drivers needed by Steam and Proton\nfor running 32-bit games with GPU acceleration.\n\nRequired for: Steam\nRecommended for: old games via Wine/Proton\n\nProceed?" 15 65; then + if _confirm "32-bit Support" "Enable i386 for 32-bit games?\n\nRequired by Steam/Proton.\nInstalls matching 32-bit graphics drivers."; then enable_32bit=true fi @@ -16,26 +15,26 @@ install_gaming() { if ! dpkg --print-foreign-architectures | grep -q i386; then sudo dpkg --add-architecture i386 fi - sudo apt update + _run_cmd "APT Update" "sudo apt update" "Updating package lists..." echo "Installing 32-bit graphics drivers..." if [ "$GPU_TYPE" = "nvidia" ]; then - sudo apt install -y nvidia-driver-libs:i386 + _run_cmd "32-bit" "sudo apt install -y nvidia-driver-libs:i386" "Installing 32-bit NVIDIA drivers..." else - sudo apt install -y mesa-vulkan-drivers libglx-mesa0:i386 mesa-vulkan-drivers:i386 libgl1-mesa-dri:i386 + _run_cmd "32-bit" "sudo apt install -y mesa-vulkan-drivers libglx-mesa0:i386 mesa-vulkan-drivers:i386 libgl1-mesa-dri:i386" "Installing 32-bit Mesa drivers..." fi fi # 2. Gaming packages checklist local choices choices=$(whiptail --title "Gaming Setup" --checklist \ - "Select gaming packages to install:" 16 72 6 \ - "steam" "Steam (official .deb from Valve, requires 32-bit)" ON \ - "gamemode" "Optimise system for gaming" ON \ - "mangohud" "Vulkan/OpenGL performance overlay" ON \ - "heroic" "Heroic Games Launcher (Epic Games, GOG) - .deb" OFF \ - "goverlay" "GUI for configuring MangoHud" ON \ - "lutris" "Game launcher/runner" OFF \ + "Select gaming packages to install:" $TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \ + "steam" "Steam (official .deb, needs 32-bit)" ON \ + "gamemode" "Game performance optimization" ON \ + "mangohud" "Performance overlay (Vulkan/GL)" ON \ + "heroic" "Heroic Launcher (Epic/GOG) .deb" OFF \ + "goverlay" "MangoHud config GUI" ON \ + "lutris" "Game launcher/manager" OFF \ 3>&1 1>&2 2>&3) if [ -z "$choices" ]; then @@ -56,37 +55,36 @@ install_gaming() { for pkg in $cleaned; do case $pkg in steam) - echo "Downloading official Steam .deb..." local steam_deb="/tmp/steam_latest.deb" - wget -O "$steam_deb" "https://cdn.fastly.steamstatic.com/client/installer/steam.deb" - sudo apt install -y "$steam_deb" + _run_cmd "Steam" "wget -O $steam_deb https://cdn.fastly.steamstatic.com/client/installer/steam.deb" "Downloading Steam..." + _run_cmd "Steam" "sudo apt install -y $steam_deb" "Installing Steam..." + echo -e "${GREEN}Steam installed.${NC}" ;; mangohud) - sudo apt install -y mangohud + _run_cmd "MangoHud" "sudo apt install -y mangohud" "Installing MangoHud..." if $enable_32bit; then echo "Installing 32-bit MangoHud..." - sudo apt install -y mangohud:i386 + _run_cmd "MangoHud" "sudo apt install -y mangohud:i386" "Installing 32-bit MangoHud..." fi ;; heroic) - echo "Downloading Heroic Games Launcher..." - sudo apt install -y curl wget 2>/dev/null || true local heroic_deb="/tmp/heroic.deb" + _run_cmd "Heroic" "sudo apt install -y curl wget" "Installing dependencies..." local gh_url - gh_url=$(curl -s https://api.github.com/repos/Heroic-Games-Launcher/\ + gh_url=$(curl -s --connect-timeout 10 https://api.github.com/repos/Heroic-Games-Launcher/\ HeroicGamesLauncher/releases/latest | \ grep -oP 'https://[^"]+amd64\.deb' | head -1) if [ -z "$gh_url" ]; then echo -e "${RED}Could not determine latest Heroic release.${NC}" else - wget -O "$heroic_deb" "$gh_url" - sudo apt install -y "$heroic_deb" + _run_cmd "Heroic" "wget -O $heroic_deb $gh_url" "Downloading Heroic..." + _run_cmd "Heroic" "sudo apt install -y $heroic_deb" "Installing Heroic..." rm -f "$heroic_deb" echo -e "${GREEN}Heroic Games Launcher installed.${NC}" fi ;; *) - sudo apt install -y "$pkg" + _run_install "$pkg" ;; esac done diff --git a/modules/gpu.sh b/modules/gpu.sh index 28328a4..07429aa 100644 --- a/modules/gpu.sh +++ b/modules/gpu.sh @@ -7,8 +7,7 @@ install_gpu_drivers() { intel) install_intel ;; nvidia) install_nvidia ;; *) - echo -e "${YELLOW}No supported GPU detected or unknown GPU type.${NC}" - echo "You can install GPU drivers manually later." + _msg "GPU" "No dedicated GPU detected.\n\nIf you are in a virtual machine, GPU acceleration\ndepends on VM configuration (SPICE, VirtIO).\n\nNo additional drivers will be installed." 12 60 return ;; esac @@ -25,19 +24,17 @@ install_gpu_drivers() { mesa_pkgs+=" - ${mpkg} (from stable)\n" fi done - if whiptail --title "Mesa Backports" --yesno \ - "Install newer Mesa GPU drivers from backports?\n\n${mesa_pkgs}\nRecommended for better GPU performance and gaming." 14 65; then - echo "Installing Mesa from backports..." - sudo apt install -y -t "${DEBIAN_CODENAME}-backports" libgl1-mesa-dri mesa-vulkan-drivers + if _confirm_custom "Mesa Backports" "Install Mesa?\n${mesa_pkgs}" "Backports" "Stable"; then + _run_cmd "Mesa" "sudo apt install -y -t ${DEBIAN_CODENAME}-backports libgl1-mesa-dri mesa-vulkan-drivers" "Installing Mesa from backports..." + else + _run_cmd "Mesa" "sudo apt install -y libgl1-mesa-dri mesa-vulkan-drivers" "Installing Mesa from stable..." fi fi local tool_pkgs tool_pkgs=$(pkg_versions nvtop vainfo) - if whiptail --title "GPU Tools" --yesno \ - "Install the following packages?\n\n${tool_pkgs}\nProceed?" 14 65; then - sudo apt install -y nvtop vainfo - echo "" + if _confirm "GPU Tools" "Install monitoring tools?\n${tool_pkgs}"; then + _run_cmd "GPU Tools" "sudo apt install -y nvtop vainfo" "Installing GPU tools..." vainfo else echo "Skipping GPU monitoring tools." @@ -51,13 +48,11 @@ install_gpu_drivers() { install_amd() { local pkgs pkgs=$(pkg_versions firmware-amd-graphics radeontop) - if ! whiptail --title "AMD GPU" --yesno \ - "Install the following packages?\n\n${pkgs}\nProceed?" 14 65; then + if ! _confirm "AMD GPU" "Install AMD drivers?\n${pkgs}"; then echo "Skipping AMD GPU drivers." return fi - echo -e "${YELLOW}Installing AMD GPU drivers and firmware...${NC}" - sudo apt install -y firmware-amd-graphics radeontop + _run_cmd "AMD" "sudo apt install -y firmware-amd-graphics radeontop" "Installing AMD drivers..." echo -e "${GREEN}AMD drivers installed.${NC}" } @@ -76,19 +71,16 @@ install_intel() { local pkgs pkgs=$(pkg_versions firmware-intel-graphics "$va_driver") - if ! whiptail --title "Intel GPU" --yesno \ - "Install the following packages?\n\n${pkgs}\nProceed?" 14 65; then + if ! _confirm "Intel GPU" "Install Intel drivers?\n${pkgs}"; then echo "Skipping Intel GPU drivers." return fi - echo -e "${YELLOW}Installing Intel GPU firmware and drivers...${NC}" - - sudo apt install -y firmware-intel-graphics + _run_cmd "Intel" "sudo apt install -y firmware-intel-graphics" "Installing Intel firmware..." echo "Detected Intel GPU generation: $gen" echo "Installing ${va_driver}..." - sudo apt install -y "$va_driver" + _run_cmd "Intel" "sudo apt install -y $va_driver" "Installing Intel VA driver..." echo -e "${GREEN}Intel GPU drivers installed.${NC}" } @@ -113,16 +105,13 @@ install_nvidia() { echo "NVIDIA driver. The script will now install the recommended driver" echo "from the STABLE repositories only, NOT from backports." - if ! whiptail --title "NVIDIA + Backports Warning" \ - --yesno "You have backports enabled.\n\nThere is a known conflict between backports kernels (6.19+) and the NVIDIA driver.\n\nDo you want to continue using the stable NVIDIA driver?\n\n(Choose No to skip NVIDIA installation)" 15 70; then + if ! _confirm "NVIDIA + Backports" "Backports kernel (6.19+) may break NVIDIA driver.\nContinue with stable NVIDIA driver?"; then echo "Skipping NVIDIA driver installation." return 0 fi fi - # Install nvidia-detect - echo "Installing nvidia-detect..." - sudo apt install -y nvidia-detect + _run_cmd "NVIDIA" "sudo apt install -y nvidia-detect" "Installing nvidia-detect..." # Run nvidia-detect and parse the recommended package echo "Detecting recommended NVIDIA driver..." @@ -165,15 +154,11 @@ install_nvidia() { local nv_pkgs nv_pkgs=$(pkg_versions "$recommended" firmware-misc-nonfree nvidia-vaapi-driver) - if ! whiptail --title "NVIDIA Driver" --yesno \ - "Install the following packages?\n\n${nv_pkgs}\nA reboot will be required.\n\nProceed?" 14 65; then + if ! _confirm "NVIDIA Driver" "Install NVIDIA driver?\n${nv_pkgs}\nReboot required."; then echo "Skipping NVIDIA driver installation." return 0 fi - sudo apt install -y "$recommended" firmware-misc-nonfree nvidia-vaapi-driver - - echo -e "${GREEN}NVIDIA drivers installed.${NC}" - echo "A reboot is required to load the NVIDIA kernel module." - echo "After reboot, run 'nvidia-smi' to verify the installation." + _run_cmd "NVIDIA" "sudo apt install -y $recommended firmware-misc-nonfree nvidia-vaapi-driver" "Installing NVIDIA driver..." + echo -e "${GREEN}NVIDIA drivers installed. Reboot required.${NC}" } diff --git a/modules/kernel.sh b/modules/kernel.sh index 42c5c16..99df051 100644 --- a/modules/kernel.sh +++ b/modules/kernel.sh @@ -2,62 +2,29 @@ # kernel.sh install_kernel_backports() { - echo -e "${YELLOW}Kernel from Backports${NC}" - - # Check if backports are enabled at system level if [ "$(is_backports_enabled)" != "true" ]; then - echo -e "${YELLOW}Backports repository is not enabled.${NC}" - echo "Use option 2 (Configure repositories) to enable backports first." + _msg "Kernel" "Backports repository is not enabled.\n\nUse option 3 (Configure repositories) to enable backports\nbefore installing the backports kernel." return 1 fi local backports_kernel_ver backports_kernel_ver=$(get_backports_kernel_version) - echo "This will install the latest stable kernel from backports." - echo " - Newer hardware support" - echo " - Potential performance improvements" + local msg="Install the latest kernel from backports?" if [ "$backports_kernel_ver" != "unknown" ]; then - echo " - Kernel version available: $backports_kernel_ver" - else - echo " - Kernel version could not be determined at this time" + msg+="\n\nVersion: $backports_kernel_ver" fi - echo "" - - # Extra warning if NVIDIA GPU is detected - if [ "$GPU_TYPE" == "nvidia" ]; then - echo -e "${RED}============================================${NC}" - echo -e "${RED} WARNING: NVIDIA GPU detected${NC}" - echo -e "${RED}============================================${NC}" - echo "Backports kernels (6.19+) can break the NVIDIA 550 driver." - echo "If you installed the NVIDIA driver earlier, this may cause" - echo "display issues or DKMS compilation failures." - echo "" - fi - - # Build the whiptail message dynamically - local msg - msg="Do you want to install the latest kernel from backports?\n\n" - if [ "$backports_kernel_ver" != "unknown" ]; then - msg+="Kernel version: $backports_kernel_ver\n\n" - fi - msg+="This replaces the current linux-image-amd64 metapackage.\n" - msg+="You can still boot older kernels from GRUB.\n" + msg+="\nOlder kernels remain available in GRUB." if [ "$GPU_TYPE" == "nvidia" ]; then - msg+="\n WARNING: NVIDIA GPU detected.\n" - msg+="Backports kernels (6.19+) may break the NVIDIA 550 driver.\n" + msg+="\n\nWARNING: may break NVIDIA driver." fi - if ! whiptail --title "Install Kernel from Backports" \ - --yesno "$msg" 16 70; then + if ! _confirm "Backports Kernel" "$msg"; then echo "Skipping kernel installation." return fi - echo "Installing kernel from backports..." - sudo apt install -y -t "${DEBIAN_CODENAME}-backports" linux-image-amd64 - - echo -e "${GREEN}Kernel from backports installed.${NC}" - echo "Please reboot to use the new kernel." + _run_cmd "Kernel" "sudo apt install -y -t ${DEBIAN_CODENAME}-backports linux-image-amd64" "Installing kernel from backports..." + echo -e "${GREEN}Kernel installed. Reboot to use it.${NC}" } diff --git a/modules/repos.sh b/modules/repos.sh index 0f23728..4624b2d 100644 --- a/modules/repos.sh +++ b/modules/repos.sh @@ -52,18 +52,14 @@ configure_repos() { local use_deb822=false if [ "$DEBIAN_CODENAME" = "trixie" ]; then - if whiptail --title "Repository Format" --defaultno \ - --yesno "Use the modern .sources (deb822) format?\n(default is classic one-line style)" 10 60; then + if whiptail --title "Repository Format" --defaultno --yesno "Use deb822 format (modern .sources)?" 8 60; then use_deb822=true fi fi - local enable_backports - if whiptail --title "Backports" \ - --yesno "Enable backports?\nBackports provide newer versions of some software (kernel, drivers, Mesa) for better hardware support.\nIt is recommended to enable it (default: Yes)." 12 70; then + local enable_backports=false + if _confirm "Backports" "Enable backports repository?\n\nProvides newer kernel, drivers, Mesa."; then enable_backports=true - else - enable_backports=false fi if [ -z "$DEBIAN_CODENAME" ]; then @@ -82,7 +78,9 @@ configure_repos() { fi echo "Updating package lists..." - if sudo apt update; then + sudo apt update + local apt_rc=$? + if [ $apt_rc -eq 0 ]; then REPOS_CONFIGURED=true echo -e "${GREEN}Repositories configured and updated successfully.${NC}" @@ -95,10 +93,9 @@ configure_repos() { local upgradable upgradable=$(apt list --upgradable 2>/dev/null | grep -c /) if [ "$upgradable" -gt 0 ]; then - if whiptail --title "Upgrade System" \ - --yesno "There are $upgradable packages that can be upgraded.\n\nDo you want to upgrade them now?" 10 60; then + if _confirm "Upgrade System" "$upgradable packages can be upgraded. Upgrade now?"; then sudo apt-mark hold tzdata 2>/dev/null || true - sudo apt upgrade -y + _run_cmd "Upgrade" "sudo apt upgrade -y" "Upgrading system..." sudo apt-mark unhold tzdata 2>/dev/null || true sudo apt autoremove -y sudo apt autoclean diff --git a/modules/sudo_config.sh b/modules/sudo_config.sh index ba59ca5..6a35d5f 100644 --- a/modules/sudo_config.sh +++ b/modules/sudo_config.sh @@ -17,11 +17,7 @@ config_sudo() { fi fi - local answer - answer=$(whiptail --title "Sudo Password Feedback" \ - --yesno "Show asterisks when typing the sudo password?" 8 60 3>&1 1>&2 2>&3) - local exitstatus=$? - if [ $exitstatus -eq 0 ]; then + if _confirm "Sudo Password Feedback" "Show asterisks when typing the sudo password?"; then echo 'Defaults pwfeedback' | sudo tee /etc/sudoers.d/pwfeedback > /dev/null if [ $? -eq 0 ]; then echo -e "${GREEN}Password feedback enabled.${NC}" diff --git a/modules/utils.sh b/modules/utils.sh index 8426ad8..3718547 100644 --- a/modules/utils.sh +++ b/modules/utils.sh @@ -260,9 +260,11 @@ install_backports_or_stable() { if [ -n "$bpo_ver" ]; then local current_ver current_ver=$(dpkg -l "$pkg" 2>/dev/null | awk '/^ii/{print $3}') - if whiptail --title "Backports: ${pkg}" --yesno \ - "${pkg} is installed (${current_ver}).\n\nUpgrade to backports version ${bpo_ver}?" 12 62; then - sudo apt install -y -t "${DEBIAN_CODENAME}-backports" "$pkg" + if _confirm "Backports: ${pkg}" \ + "${pkg} ${current_ver} installed.\nUpgrade to backports ${bpo_ver}?"; then + _run_cmd "Backports" \ + "sudo DEBIAN_FRONTEND=noninteractive apt install -y -t ${DEBIAN_CODENAME}-backports $pkg" \ + "Upgrading $pkg..." return fi fi @@ -273,13 +275,94 @@ install_backports_or_stable() { if [ -n "$bpo_ver" ]; then local stable_ver stable_ver=$(apt-cache policy "$pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') - if whiptail --title "Backports: ${pkg}" --yesno \ - "Install ${pkg} from backports?\n\nBackports: ${bpo_ver}\nStable: ${stable_ver:-N/A}\n\nChoose Yes for backports, No for stable." 12 62; then - sudo apt install -y -t "${DEBIAN_CODENAME}-backports" "$pkg" + if _confirm_custom "${pkg}" "Install from backports?\n\nBackports: ${bpo_ver}\nStable: ${stable_ver:-N/A}" "Backports" "Stable"; then + _run_cmd "Backports" \ + "sudo DEBIAN_FRONTEND=noninteractive apt install -y -t ${DEBIAN_CODENAME}-backports $pkg" \ + "Installing $pkg from backports..." return fi + # User chose "Stable" — install stable directly, no re-prompt + _run_cmd "APT" "sudo DEBIAN_FRONTEND=noninteractive apt install -y $pkg" "Installing $pkg from stable..." + return + fi + local stable_ver + stable_ver=$(apt-cache policy "$pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') + if _confirm "Install: ${pkg}" "Install ${pkg} ${stable_ver:-} from stable?"; then + _run_cmd "APT" "sudo DEBIAN_FRONTEND=noninteractive apt install -y $pkg" "Installing $pkg..." + fi +} + +# ---------------------------------------------------------------------- +# Whiptail helpers (4-block pattern) +# ---------------------------------------------------------------------- + +_confirm() { + whiptail --title "$1" --yes-button "Execute" --no-button "Skip" \ + --yesno "$2" "${3:-10}" "${4:-65}" +} + +_confirm_custom() { + local title="$1" text="$2" yes_btn="$3" no_btn="$4" + shift 4 + whiptail --title "$title" --yes-button "$yes_btn" --no-button "$no_btn" \ + --yesno "$text" "${@:-10 65}" +} + +_msg() { + whiptail --title "$1" --msgbox "$2" "${3:-10}" "${4:-65}" +} + +# Blocks 2-4: clear → run → pause +_run_cmd() { + local title="$1" command="$2" success_msg="${3:-Running...}" + clear + echo -e "${GREEN}[+]${NC} $success_msg" + echo "──────────────────────────────────────────────" + eval "$command" + local rc=$? + echo "──────────────────────────────────────────────" + if [ $rc -eq 0 ]; then + echo -e "${GREEN}[+]${NC} Done." + else + echo -e "${RED}[-]${NC} Failed (exit code: $rc)." + fi + echo "Press [ENTER] to continue..." + read -r +} + +# Blocks 1-4: confirm → clear → run → pause +_run() { + if _confirm "$1" "$2"; then + _run_cmd "$1" "$3" "$4" + fi +} + +_is_headless() { + [ -z "${DISPLAY:-}" ] && [ -z "${WAYLAND_DISPLAY:-}" ] +} + +_run_install() { + local pkg="$1" + local ver + ver=$(apt-cache policy "$pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') + [ -z "$ver" ] && ver="(version unknown)" + if _confirm "Install: ${pkg}" "Install ${pkg}\nVersion: ${ver}?"; then + _run_cmd "Install" "sudo DEBIAN_FRONTEND=noninteractive apt install -y $pkg" "Installing $pkg..." + fi +} + +_run_install_batch() { + local pkgs=("$@") + [ ${#pkgs[@]} -eq 0 ] && return 0 + local ver_list="" + for pkg in "${pkgs[@]}"; do + local ver + ver=$(apt-cache policy "$pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') + ver_list+=" - ${pkg} ${ver:-unknown}\n" + done + if _confirm "Install" "Install these packages?\n${ver_list}"; then + _run_cmd "Install" "sudo DEBIAN_FRONTEND=noninteractive apt install -y ${pkgs[*]}" "Installing..." fi - sudo apt install -y "$pkg" } get_backports_kernel_version() { diff --git a/modules/zram.sh b/modules/zram.sh index 01e2851..167c807 100644 --- a/modules/zram.sh +++ b/modules/zram.sh @@ -13,10 +13,16 @@ install_zram() { local algo algo=$(whiptail --title "ZRAM Compression" --menu \ - "ZRAM compresses a portion of RAM to use as\nswap, effectively increasing available memory.\n\nChoose the compression algorithm:\n\nlz4: Very fast, low CPU usage. Minimal latency.\n Recommended for most users.\n\nzstd: Better compression ratio (10-20% more),\n slightly higher CPU usage.\n\nPress Cancel to abort." \ - 18 65 2 \ - "lz4" "Fastest, lowest CPU usage (recommended)" \ - "zstd" "Best ratio, slightly more CPU" \ + "ZRAM compresses a portion of RAM into compressed swap,\ + effectively increasing available memory. + +Useful for systems with limited RAM or when you need +more swap space without disk writes. + +Choose compression algorithm:" \ + $TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \ + "lz4" "Fastest, low CPU (recommended)" \ + "zstd" "Better ratio, more CPU" \ 3>&1 1>&2 2>&3) if [ -z "$algo" ]; then @@ -25,8 +31,7 @@ install_zram() { fi local zram_size - if whiptail --title "ZRAM Size" --yesno \ - "Use 50% of RAM for ZRAM? (${half_ram_mb} MB out of ${RAM_SUMMARY})\n\nChoose No to enter a custom size." 10 60; then + if _confirm "ZRAM Size" "Use 50% of RAM for ZRAM? (${half_ram_mb} MB out of ${RAM_SUMMARY})"; then zram_size=$half_ram_mb else zram_size=$(whiptail --title "ZRAM Size" --inputbox \ @@ -37,14 +42,12 @@ install_zram() { fi fi - if ! whiptail --title "ZRAM Summary" --yesno \ - "Algorithm: ${algo}\nSize: ${zram_size} MB (${RAM_SUMMARY} total)\nPriority: 100\n\nApply ZRAM configuration?" 13 60; then + if ! _confirm "ZRAM Summary" "Algorithm: ${algo}\nSize: ${zram_size} MB\nPriority: 100\n\nApply?"; then echo "ZRAM configuration cancelled." return 0 fi - echo -e "${YELLOW}Installing zram-tools...${NC}" - sudo apt install -y zram-tools + _run_cmd "ZRAM" "sudo apt install -y zram-tools" "Installing zram-tools..." echo "Writing configuration..." sudo tee /etc/default/zramswap > /dev/null <