Files
debianito-post-install/modules/repos.sh
T
stornic56 656f045163 add Debian 11 support
- Created dedicated modules/bullseye/` folder for legacy isolation (Debian 11 support).
- Implemented 4-block inclusive PCI range detection for Nvidia Kepler/Fermi to prevent black screens.
- Centralized system time verification checking against year 2026 before APT execution.
- Cleaned and purged modern package lists for the Bullseye extra software module.
- Updated main menu with conditional sourcing and fixed Option 7 (Gaming Lite) for Bullseye.
- Updated README.md with explicit TUI navigation instructions and full repository directory tree mapping.
2026-06-11 17:22:11 -05:00

167 lines
5.6 KiB
Bash

#!/usr/bin/env bash
# State for backup/restore
REPO_BACKUP_DIR=""
backup_current_repos() {
REPO_BACKUP_DIR=$(mktemp -d)
for f in /etc/apt/sources.list /etc/apt/sources.list.d/debian.sources; do
if [ -f "$f" ]; then
cp "$f" "$REPO_BACKUP_DIR/$(basename "$f")"
fi
done
}
restore_previous_repos() {
if [ -z "$REPO_BACKUP_DIR" ] || [ ! -d "$REPO_BACKUP_DIR" ]; then
return
fi
echo -e "${RED}Restoring previous repository configuration...${NC}"
if [ -f "$REPO_BACKUP_DIR/sources.list" ]; then
sudo cp "$REPO_BACKUP_DIR/sources.list" /etc/apt/sources.list
else
sudo rm -f /etc/apt/sources.list
fi
if [ -f "$REPO_BACKUP_DIR/debian.sources" ]; then
sudo cp "$REPO_BACKUP_DIR/debian.sources" /etc/apt/sources.list.d/debian.sources
else
sudo rm -f /etc/apt/sources.list.d/debian.sources
fi
sudo rm -f /etc/apt/sources.list.disabled
rm -rf "$REPO_BACKUP_DIR"
REPO_BACKUP_DIR=""
}
cleanup_repo_backup() {
if [ -n "$REPO_BACKUP_DIR" ] && [ -d "$REPO_BACKUP_DIR" ]; then
rm -rf "$REPO_BACKUP_DIR"
REPO_BACKUP_DIR=""
fi
}
finalize_deb822() {
if [ -f /etc/apt/sources.list ]; then
sudo mv /etc/apt/sources.list /etc/apt/sources.list.disabled
echo "Classic sources.list disabled (renamed to sources.list.disabled)"
fi
cleanup_repo_backup
}
configure_repos() {
echo -e "${YELLOW}Repository configuration...${NC}"
local use_deb822=false
if [ "$DEBIAN_CODENAME" = "trixie" ]; then
if whiptail --title "Repository Format" --defaultno --yesno "Use deb822 format (modern .sources)?" 8 60; then
use_deb822=true
fi
fi
local enable_backports=false
if _confirm "Backports" "Enable backports repository?\n\nProvides newer kernel, drivers, Mesa."; then
enable_backports=true
fi
if [ -z "$DEBIAN_CODENAME" ]; then
echo -e "${RED}Error: Could not detect Debian codename. Aborting.${NC}"
return 1
fi
backup_current_repos
if $use_deb822; then
generate_deb822_sources "$DEBIAN_CODENAME" "$enable_backports"
else
generate_classic_sources "$DEBIAN_CODENAME" "$enable_backports"
fi
echo "Updating package lists..."
sudo apt update
local apt_rc=$?
if [ $apt_rc -eq 0 ]; then
REPOS_CONFIGURED=true
echo -e "${GREEN}Repositories configured and updated successfully.${NC}"
if $use_deb822; then
finalize_deb822
else
cleanup_repo_backup
fi
local upgradable
upgradable=$(apt list --upgradable 2>/dev/null | grep -c /)
if [ "$upgradable" -gt 0 ]; then
if _confirm "Upgrade System" "$upgradable packages can be upgraded. Upgrade now?"; then
sudo apt-mark hold tzdata 2>/dev/null || true
_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
echo -e "${GREEN}System upgraded.${NC}"
else
echo "Skipping upgrade."
fi
fi
else
restore_previous_repos
echo -e "${RED}apt update failed. Previous repository configuration restored.${NC}"
return 1
fi
}
generate_classic_sources() {
local codename="$1"
local backports="$2"
local content=""
content="# Official repository\n"
content+="deb https://deb.debian.org/debian ${codename} main contrib non-free non-free-firmware\n"
content+="# deb-src https://deb.debian.org/debian ${codename} main contrib non-free non-free-firmware\n\n"
content+="# Updates\n"
content+="deb https://deb.debian.org/debian ${codename}-updates main contrib non-free non-free-firmware\n"
content+="# deb-src https://deb.debian.org/debian ${codename}-updates main contrib non-free non-free-firmware\n\n"
content+="# Security\n"
content+="deb https://security.debian.org/debian-security ${codename}-security main contrib non-free non-free-firmware\n"
content+="# deb-src https://security.debian.org/debian-security ${codename}-security main contrib non-free non-free-firmware\n\n"
if $backports; then
content+="# Backports (active)\n"
content+="deb https://deb.debian.org/debian ${codename}-backports main contrib non-free non-free-firmware\n"
content+="# deb-src https://deb.debian.org/debian ${codename}-backports main contrib non-free non-free-firmware\n"
else
content+="# Backports (not enabled)\n"
content+="# deb https://deb.debian.org/debian ${codename}-backports main contrib non-free non-free-firmware\n"
fi
echo -e "$content" | sudo tee /etc/apt/sources.list > /dev/null
}
generate_deb822_sources() {
local codename="$1"
local backports="$2"
sudo mkdir -p /etc/apt/sources.list.d
local content=""
content="Types: deb\n"
content+="URIs: https://deb.debian.org/debian\n"
content+="Suites: ${codename} ${codename}-updates\n"
content+="Components: main contrib non-free non-free-firmware\n\n"
content+="Types: deb\n"
content+="URIs: https://security.debian.org/debian-security\n"
content+="Suites: ${codename}-security\n"
content+="Components: main contrib non-free non-free-firmware\n\n"
if $backports; then
content+="Types: deb\n"
content+="URIs: https://deb.debian.org/debian\n"
content+="Suites: ${codename}-backports\n"
content+="Components: main contrib non-free non-free-firmware\n"
fi
echo -e "$content" | sudo tee /etc/apt/sources.list.d/debian.sources > /dev/null
}