50 lines
1.7 KiB
Bash
50 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
set -e # Exit on any error
|
|
|
|
# Define color codes
|
|
RED='\e[31m'
|
|
GREEN='\e[32m'
|
|
YELLOW='\e[33m'
|
|
BLUE='\e[34m'
|
|
NC='\e[0m' # No Color
|
|
|
|
# Ensure the script is run as root
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo -e "${RED}This script must be run as root. Try running it with sudo.${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${BLUE}Updating package lists and upgrading installed packages...${NC}"
|
|
DEBIAN_FRONTEND=noninteractive apt update && apt upgrade -y -o Dpkg::Options::="--force-confold"
|
|
|
|
echo -e "${BLUE}Upgrading full system...${NC}"
|
|
DEBIAN_FRONTEND=noninteractive apt full-upgrade -y -o Dpkg::Options::="--force-confold"
|
|
|
|
echo -e "${BLUE}Removing obsolete packages...${NC}"
|
|
apt autoremove -y
|
|
|
|
# Update all .list files in /etc/apt/sources.list.d/ and sources.list to Debian 12 Bookworm
|
|
echo -e "${YELLOW}Updating APT sources list to Debian 12 (Bookworm)...${NC}"
|
|
sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list
|
|
sed -i 's/bullseye-security/bookworm-security/g' /etc/apt/sources.list
|
|
find /etc/apt/sources.list.d/ -type f -name "*.list" -exec sed -i 's/bullseye/bookworm/g' {} +
|
|
find /etc/apt/sources.list.d/ -type f -name "*.list" -exec sed -i 's/bullseye-security/bookworm-security/g' {} +
|
|
|
|
# Update APT cache and perform upgrade
|
|
echo -e "${BLUE}Updating package lists...${NC}"
|
|
apt update
|
|
|
|
echo -e "${BLUE}Upgrading to Debian 12 Bookworm...${NC}"
|
|
DEBIAN_FRONTEND=noninteractive apt upgrade -y -o Dpkg::Options::="--force-confold"
|
|
DEBIAN_FRONTEND=noninteractive apt full-upgrade -y -o Dpkg::Options::="--force-confold"
|
|
|
|
echo -e "${BLUE}Cleaning up unnecessary packages...${NC}"
|
|
apt autoremove -y
|
|
apt clean
|
|
|
|
echo -e "${GREEN}Upgrade completed. A system reboot is required.${NC}"
|
|
read -p "Do you want to reboot now? (y/N) " answer
|
|
if [[ "$answer" =~ ^[Yy]$ ]]; then
|
|
reboot
|
|
fi
|