Files
debianito-post-install/debianito.sh
T
stornic56 54257d5a8a Security hardening & DRY refactoring
- Fixed command injection in desktop_display.sh by converting word-splitting loops to safe array-based iteration for LightDM/GDM3 configuration and XFCE package installation.
- Added symlink detection guard before repository file operations in repos.sh to prevent TOCTOU attacks during restore_previous_repos().
- Hardened SUDO_USER resolution with awk validation against /etc/passwd to prevent root fallback and ensure real login users are targeted for sudoers configuration.
- Implemented algorithm (lz4/zstd) and size validation before ZRAM configuration writes in zram.sh to reject invalid inputs.
- Protected grep MemTotal read from /proc/meminfo with 2>/dev/null and default assignment under set -u.
- Added || true guards around apt-cache madison pipelines in firmware.sh, kernel.sh, gpu.sh, and utils.sh to prevent pipefail aborts when backports unavailable.
- Wrapped whiptail installation in if/else blocks to allow offline error messages instead of script termination under set -e.
- Fixed grep -c output duplication in swap.sh with proper || true pattern and default variable assignment.
- Replaced unquoted $cleaned loops with array conversion using while read for secure package iteration across gaming, desktop_display, firmware, and kernel modules.
- Anchored sed regex patterns to space-delimited "main" components to prevent mirror URL corruption in sources.list editing.
- Escaped % characters in _msg() function before passing to whiptail to prevent printf format interpretation crashes.
- Consolidated package version helpers into canonical wrappers: _get_pkg_version, _get_installed_version, _get_backports_version for consistent apt/dpkg queries.
- Created _install_if_missing() and _install_pkg() with proper error handling that respects set -e while providing user feedback on installation failures.
- Removed 6 dead code functions (~51 lines): check_system_time, sync_system_time, get_cpu_summary, get_ram_summary, pkg_versions, get_backports_kernel_version.
- Added detect_displayserver and detect_audio_server to refresh_system_state() for complete state refresh when returning from menus.
- Enhanced _on_interrupt() trap handler to kill lingering apt/dpkg child processes and clean /tmp/debianito.* temporary files on Ctrl+C or TERM.
- Improved restore_previous_repos() with manifest-based backup verification (.backed_up_* markers) to prevent destructive repository file deletion.
- Added mktemp usage for secure temporary deb file downloads in nvidia.sh, heroic.sh, and tools.sh to eliminate TOCTOU vulnerabilities in /tmp.
- Fixed Bluetooth USB dongle misclassification as WiFi devices by excluding "bluetooth" strings from USB_WIFI_DEVS detection in firmware.sh.
- Properly utilized the need array for selective package installation in internet.sh instead of hardcoding full package list.
- Corrected fwupdmgr duplicate execution and grep false positives in system.sh with strict pattern matching for available updates.
- update docs and added quickstart guide
2026-09-14 20:31:48 -05:00

226 lines
7.7 KiB
Bash

#!/usr/bin/env bash
# Debianito — simple configurator script
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
# 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"
[ -f "${MODULES_DIR}/sysinfo.sh" ] && source "${MODULES_DIR}/sysinfo.sh"
source "${MODULES_DIR}/sudo_config.sh"
source "${MODULES_DIR}/repos/repo_detect.sh"
source "${MODULES_DIR}/repos.sh"
[ -f "${MODULES_DIR}/firmware.sh" ] && source "${MODULES_DIR}/firmware.sh"
[ -f "${MODULES_DIR}/bluetooth.sh" ] && source "${MODULES_DIR}/bluetooth.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"
[ -f "${MODULES_DIR}/extras/java.sh" ] && source "${MODULES_DIR}/extras/java.sh"
[ -f "${MODULES_DIR}/rescue.sh" ] && source "${MODULES_DIR}/rescue.sh"
[ -f "${MODULES_DIR}/swap.sh" ] && source "${MODULES_DIR}/swap.sh"
[ -f "${MODULES_DIR}/desktop_display.sh" ] && source "${MODULES_DIR}/desktop_display.sh"
[ -f "${MODULES_DIR}/system/system_prefs.sh" ] && source "${MODULES_DIR}/system/system_prefs.sh"
[ -f "${MODULES_DIR}/system/audio.sh" ] && source "${MODULES_DIR}/system/audio.sh"
# ── Bullseye-specific modules (loaded only on Debian 11) ──
if [ -d "${MODULES_DIR}/bullseye" ]; then
[ -f "${MODULES_DIR}/bullseye/legacy.sh" ] && source "${MODULES_DIR}/bullseye/legacy.sh"
[ -f "${MODULES_DIR}/bullseye/repos.sh" ] && source "${MODULES_DIR}/bullseye/repos.sh"
[ -f "${MODULES_DIR}/bullseye/extras.sh" ] && source "${MODULES_DIR}/bullseye/extras.sh"
fi
# ── Interrupt safety: restore repository state on Ctrl+C / TERM ──
_on_interrupt() {
echo -e "${RED}[!] Interrupted. Restoring repository state if possible...${NC}"
if type restore_previous_repos &>/dev/null; then
restore_previous_repos 2>/dev/null || true
fi
# Kill any lingering child processes (apt, dpkg) from interrupted runs
pkill -f "apt.*install" 2>/dev/null || true
pkill -f "dpkg.*configure" 2>/dev/null || true
# Clean up temporary files created during execution
rm -rf /tmp/debianito.* 2>/dev/null || true
echo -e "${YELLOW}[!] Child processes killed and temp files cleaned.${NC}"
exit 130
}
trap _on_interrupt INT TERM
DEBIAN_VERSION=""
DEBIAN_CODENAME=""
main_menu() {
# Auto-adjust TUI dimensions for small terminals
if [ "${LINES:-24}" -lt $((TUI_ALTO + 6)) ] || [ "${COLUMNS:-80}" -lt $((TUI_ANCHO + 6)) ]; then
TUI_ALTO=$((${LINES:-24} - 4 > 8 ? ${LINES:-24} - 4 : 8))
TUI_ANCHO=$((${COLUMNS:-80} - 4 > 50 ? ${COLUMNS:-80} - 4 : 50))
TUI_ALTO_LISTA=$((TUI_ALTO - 10 > 4 ? TUI_ALTO - 10 : 4))
fi
while true; do
sudo -v >/dev/null 2>&1 || true
local STATE_REFRESHED=false
local choice
choice=$(_menu "DEBIANITO — Simple Configurator Script" "" \
$TUI_ALTO $TUI_ANCHO $TUI_ALTO_LISTA \
"1" "System Information" \
"2" "User Privileges & Feedback" \
"3" "System Preferences" \
"4" "Configure Repositories" \
"5" "Firmware, Wireless & Bluetooth" \
"6" "Graphics Drivers & Mesa Stack" \
"7" "Kernel" \
"8" "Gaming Setup" \
"9" "ZRAM" \
"10" "Swap Management" \
"11" "Install Programs and Software" \
"12" "Boot Rescue + GRUB" \
"13" "Desktop & Display" \
"14" "Exit")
clear
case "$choice" in
1) _show_sysinfo ;;
2) config_sudo || true ;;
3)
_system_preferences_menu
STATE_REFRESHED=true
;;
4)
if [ "$DEBIAN_VERSION" = "11" ] && type configure_repos_bullseye &>/dev/null; then
configure_repos_bullseye || true
else
configure_repos || true
fi
STATE_REFRESHED=true
;;
5)
if [ "$DEBIAN_VERSION" = "11" ] && type install_firmware_bullseye &>/dev/null; then
install_firmware_bullseye || true
else
install_firmware || true
fi
STATE_REFRESHED=true
;;
6)
local gpu_sub
gpu_sub=$(_menu "Graphics Drivers" "" 12 50 2 \
"1" "Radeon/Intel Mesa" \
"2" "NVIDIA Drivers")
[ -z "$gpu_sub" ] && continue
clear
case $gpu_sub in
1) _install_amd_intel_stack || true ;;
2) _install_nvidia_stack || true ;;
esac
STATE_REFRESHED=true
;;
7)
show_kernel_menu || true
STATE_REFRESHED=true
;;
8)
if [ "$DEBIAN_VERSION" = "11" ] && type install_gaming_bullseye &>/dev/null; then
install_gaming_bullseye || true
else
install_gaming || true
fi
STATE_REFRESHED=true
;;
9)
zram_menu || true
STATE_REFRESHED=true
;;
10)
manage_swap || true
STATE_REFRESHED=true
;;
11)
if [ "$DEBIAN_VERSION" = "11" ] && type install_extras_bullseye &>/dev/null; then
install_extras_bullseye || true
else
install_extras || true
fi
STATE_REFRESHED=true
;;
12)
rescue_boot || true
STATE_REFRESHED=true
;;
13)
manage_desktop_display || true
STATE_REFRESHED=true
;;
14)
echo "Exiting."
exit 0
;;
esac
if $STATE_REFRESHED; then
refresh_system_state
fi
done
}
check_root
check_sudo
if ! command -v whiptail >/dev/null 2>&1; then
echo -e "${YELLOW}[+] whiptail not found. Installing required TUI dependencies...${NC}"
if _ensure_apt_updated && sudo apt-get install -y whiptail; then
echo -e "${GREEN}[+] whiptail installed.${NC}"
else
echo -e "${RED}[-] Could not install whiptail (no network?).${NC}" >&2
echo -e "${RED} The TUI menu requires it; install manually and re-run.${NC}" >&2
fi
fi
if ! _check_network; then
echo -e "${YELLOW}──────────────────────────────────────────${NC}"
echo -e "${YELLOW} No internet connectivity detected.${NC}"
echo -e "${YELLOW} Package installation will fail without network.${NC}"
echo -e "${YELLOW} You can use: System Info, User Privileges, and${NC}"
echo -e "${YELLOW} other offline features.${NC}"
echo -e "${YELLOW}──────────────────────────────────────────${NC}"
fi
_ensure_time_synced
detect_debian_version
detect_cpu_ram
detect_kernel
_init_lspci_cache
detect_gpu
detect_network
detect_displayserver
detect_storage
detect_desktop_environment
_configure_lightdm
detect_audio_server
# ── Bullseye-specific init (archive phase) ──
if [ "$DEBIAN_VERSION" = "11" ] && type check_bullseye_archive_phase &>/dev/null; then
check_bullseye_archive_phase
fi
if ! command -v whiptail >/dev/null 2>&1; then
echo -e "${RED}[-] whiptail is required for the TUI menu. Aborting.${NC}" >&2
exit 1
fi
main_menu