56 lines
2.2 KiB
Bash
56 lines
2.2 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 11 Bullseye
|
|
echo -e "${YELLOW}Updating APT sources list to Debian 11 (Bullseye)...${NC}"
|
|
sed -i 's/buster/bullseye/g' /etc/apt/sources.list
|
|
sed -i 's/buster-security/bullseye-security/g' /etc/apt/sources.list
|
|
find /etc/apt/sources.list.d/ -type f -name "*.list" -exec sed -i 's/buster/bullseye/g' {} +
|
|
find /etc/apt/sources.list.d/ -type f -name "*.list" -exec sed -i 's/buster-security/bullseye-security/g' {} +
|
|
|
|
# Check and replace specific security entry in sources.list
|
|
if grep -q "deb http://security.debian.org bullseye/updates main contrib" /etc/apt/sources.list; then
|
|
sed -i 's|deb http://security.debian.org bullseye/updates main contrib|deb http://security.debian.org/debian-security bullseye-security main contrib non-free|' /etc/apt/sources.list
|
|
echo -e "${YELLOW}Updated security repository entry in sources.list.${NC}"
|
|
fi
|
|
|
|
# Update APT cache and perform upgrade
|
|
echo -e "${BLUE}Updating package lists...${NC}"
|
|
apt update
|
|
|
|
echo -e "${BLUE}Upgrading to Debian 11 Bullseye...${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
|