2023-02-25 19:33:38 +08:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
#by spiritlhl
|
|
|
|
|
#from https://github.com/spiritLHLS/one-click-installation-script
|
|
|
|
|
#version: 2023.02.25
|
|
|
|
|
|
2023-02-25 19:48:27 +08:00
|
|
|
|
# 打印信息
|
|
|
|
|
_red() { echo -e "\033[31m\033[01m$@\033[0m"; }
|
|
|
|
|
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
|
|
|
|
|
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
|
|
|
|
|
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
|
|
|
|
|
|
2023-02-25 19:45:39 +08:00
|
|
|
|
# 检查是否为 root 用户
|
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
2023-02-25 19:48:27 +08:00
|
|
|
|
_red "请使用 root 用户执行脚本"
|
2023-02-25 19:45:39 +08:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2023-02-25 19:45:22 +08:00
|
|
|
|
# 判断是否为 Debian 系统
|
|
|
|
|
if [ ! -f /etc/debian_version ]; then
|
2023-02-25 19:48:27 +08:00
|
|
|
|
_red "当前系统不是 Debian 系统"
|
2023-02-25 19:45:22 +08:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2023-02-25 19:33:38 +08:00
|
|
|
|
# 从文件中读取当前版本代号
|
2023-02-25 20:16:36 +08:00
|
|
|
|
CURRENT_VERSION=$(lsb_release -cs)
|
2023-02-25 19:33:38 +08:00
|
|
|
|
|
2023-02-25 19:45:22 +08:00
|
|
|
|
# 判断当前版本是否为最新版本
|
2023-02-26 11:05:02 +08:00
|
|
|
|
version=$(cat /etc/debian_version)
|
2023-02-25 19:45:22 +08:00
|
|
|
|
if [ $CURRENT_VERSION == "bullseye" ]; then
|
2023-02-26 11:05:02 +08:00
|
|
|
|
_blue "当前系统版本为最新版本,Debian version: $version , 代号 $CURRENT_VERSION"
|
2023-02-25 19:45:22 +08:00
|
|
|
|
exit 0
|
2023-02-25 22:58:47 +08:00
|
|
|
|
else
|
2023-02-26 10:50:10 +08:00
|
|
|
|
_blue "当前 Debian version: $version , 代号 $CURRENT_VERSION ,开始升级"
|
2023-02-25 19:45:22 +08:00
|
|
|
|
fi
|
|
|
|
|
|
2023-02-25 19:33:38 +08:00
|
|
|
|
# 检查脚本是否已经在执行
|
|
|
|
|
if [ -f /tmp/debian_upgrade_in_progress ]; then
|
2023-02-25 19:48:27 +08:00
|
|
|
|
_yellow "升级正在进行中,请勿重复执行,如若已停止执行请重启服务器并删除文件 /tmp/debian_upgrade_in_progress "
|
2023-02-25 19:33:38 +08:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# 标记脚本已经在执行
|
|
|
|
|
touch /tmp/debian_upgrade_in_progress
|
|
|
|
|
|
|
|
|
|
# 设置升级前备份的文件夹路径
|
|
|
|
|
BACKUP_DIR="/root/debian_upgrade_backup"
|
|
|
|
|
|
|
|
|
|
# 创建备份文件夹
|
|
|
|
|
mkdir -p $BACKUP_DIR
|
|
|
|
|
|
|
|
|
|
# 更新软件包列表
|
|
|
|
|
apt update
|
|
|
|
|
|
|
|
|
|
# 升级已安装的软件包
|
|
|
|
|
apt upgrade -y
|
|
|
|
|
|
|
|
|
|
# 升级系统到最新版本
|
|
|
|
|
if [ $CURRENT_VERSION == "squeeze" ]; then
|
|
|
|
|
sed -i 's/squeeze/wheezy/g' /etc/apt/sources.list
|
|
|
|
|
elif [ $CURRENT_VERSION == "wheezy" ]; then
|
|
|
|
|
sed -i 's/wheezy/jessie/g' /etc/apt/sources.list
|
|
|
|
|
elif [ $CURRENT_VERSION == "jessie" ]; then
|
|
|
|
|
sed -i 's/jessie/stretch/g' /etc/apt/sources.list
|
|
|
|
|
elif [ $CURRENT_VERSION == "stretch" ]; then
|
|
|
|
|
sed -i 's/stretch/buster/g' /etc/apt/sources.list
|
|
|
|
|
elif [ $CURRENT_VERSION == "buster" ]; then
|
|
|
|
|
sed -i 's/buster/bullseye/g' /etc/apt/sources.list
|
|
|
|
|
fi
|
|
|
|
|
|
2023-02-25 22:54:43 +08:00
|
|
|
|
replace(){
|
|
|
|
|
sed -i 's/^deb http:\/\/security.debian.org\/debian-security wheezy\/updates main/# &/' /etc/apt/sources.list
|
|
|
|
|
sed -i 's/^deb-src http:\/\/security.debian.org\/debian-security wheezy\/updates main/# &/' /etc/apt/sources.list
|
|
|
|
|
sed -i 's/^deb http:\/\/security.debian.org\/debian-security jessie\/updates main/# &/' /etc/apt/sources.list
|
|
|
|
|
sed -i 's/^deb-src http:\/\/security.debian.org\/debian-security jessie\/updates main/# &/' /etc/apt/sources.list
|
|
|
|
|
sed -i 's/^deb http:\/\/security.debian.org\/debian-security stretch\/updates main/# &/' /etc/apt/sources.list
|
|
|
|
|
sed -i 's/^deb-src http:\/\/security.debian.org\/debian-security stretch\/updates main/# &/' /etc/apt/sources.list
|
|
|
|
|
sed -i 's/^deb http:\/\/security.debian.org\/debian-security buster\/updates main/# &/' /etc/apt/sources.list
|
|
|
|
|
sed -i 's/^deb-src http:\/\/security.debian.org\/debian-security buster\/updates main/# &/' /etc/apt/sources.list
|
|
|
|
|
sed -i 's/^deb http:\/\/security.debian.org\/debian-security bullseye\/updates main/# &/' /etc/apt/sources.list
|
|
|
|
|
sed -i 's/^deb-src http:\/\/security.debian.org\/debian-security bullseye\/updates main/# &/' /etc/apt/sources.list
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-25 19:35:45 +08:00
|
|
|
|
apt-get update
|
2023-02-25 22:54:43 +08:00
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
|
# 去除漏洞修补源避免更新异常
|
|
|
|
|
replace > /dev/null 2>&1
|
|
|
|
|
apt-get update
|
|
|
|
|
fi
|
2023-02-25 19:35:45 +08:00
|
|
|
|
apt-get upgrade -y
|
|
|
|
|
apt-get full-upgrade -y
|
2023-02-25 19:33:38 +08:00
|
|
|
|
|
|
|
|
|
# 清理系统
|
2023-02-25 19:35:45 +08:00
|
|
|
|
apt-get autoremove -y
|
|
|
|
|
apt-get autoclean
|
2023-02-25 19:33:38 +08:00
|
|
|
|
|
|
|
|
|
# 备份系统配置文件
|
|
|
|
|
cp -r /etc $BACKUP_DIR
|
|
|
|
|
|
|
|
|
|
# 删除标记文件
|
|
|
|
|
rm /tmp/debian_upgrade_in_progress
|
|
|
|
|
|
2023-02-25 19:48:27 +08:00
|
|
|
|
_green "脚本执行完毕系统内核应当已升级到最新版本,执行 reboot 重启系统以完成内核升级"
|