2023-02-15 11:45:10 +08:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
#from https://github.com/spiritLHLS/pve
|
|
|
|
|
# pve 6 to pve 7
|
|
|
|
|
|
|
|
|
|
# 打印信息
|
|
|
|
|
_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:18:30 +08:00
|
|
|
|
# 检查是否为 root 用户
|
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
|
|
|
echo "请使用 root 用户执行脚本"
|
|
|
|
|
exit 1
|
2023-02-15 11:45:10 +08:00
|
|
|
|
fi
|
|
|
|
|
|
2023-02-25 19:18:30 +08:00
|
|
|
|
# 删除企业源
|
|
|
|
|
rm -rf /etc/apt/sources.list.d/pve-enterprise.list
|
2023-02-15 11:45:10 +08:00
|
|
|
|
|
|
|
|
|
# 卸载无关内核
|
|
|
|
|
current_kernel=$(uname -r)
|
|
|
|
|
_yellow "当前内核: $current_kernel"
|
|
|
|
|
installed_kernels=$(dpkg -l | grep -E 'linux-(image|headers)-[0-9]+' | grep -v "$current_kernel" | awk '{print $2}')
|
|
|
|
|
if [ -z "$installed_kernels" ]; then
|
|
|
|
|
_blue "无闲置的内核"
|
|
|
|
|
else
|
2023-02-25 19:18:30 +08:00
|
|
|
|
_yellow "卸载闲置内核..."
|
2023-02-15 11:45:10 +08:00
|
|
|
|
for kernel in $installed_kernels; do
|
2023-02-25 19:18:30 +08:00
|
|
|
|
_yellow "卸载内核: $kernel"
|
2023-02-15 11:45:10 +08:00
|
|
|
|
dpkg --purge --force-remove-essential $kernel
|
|
|
|
|
apt-get remove -y $kernel > /dev/null 2>&1
|
|
|
|
|
done
|
|
|
|
|
_green "闲置内核已卸载完毕"
|
|
|
|
|
fi
|
|
|
|
|
|
2023-02-25 19:18:30 +08:00
|
|
|
|
# 检查 PVE 版本是否为最新版本
|
|
|
|
|
if ! [ "$(pveversion -v)" = "$(pveversion -r)" ]; then
|
|
|
|
|
_yellow "当前 PVE 版本不是最新版本,尝试升级到最新版本"
|
|
|
|
|
apt-get update && apt-get dist-upgrade -y
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
|
_red "升级 PVE 失败,请检查网络或源配置"
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
|
|
|
|
_green "PVE 升级到最新版本成功"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# 检查 PVE 是否可以升级
|
2023-02-25 19:20:20 +08:00
|
|
|
|
if ! pve6to7 | grep -q "FAILURES: 0"; then
|
2023-02-25 19:18:30 +08:00
|
|
|
|
_red "检测到 PVE 升级存在问题,请先解决问题后再执行升级"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2023-02-15 11:50:43 +08:00
|
|
|
|
|
2023-02-25 19:18:30 +08:00
|
|
|
|
# 检查是否为 Debian 11
|
|
|
|
|
if ! [ "$(lsb_release -cs)" = "bullseye" ]; then
|
|
|
|
|
_yellow "当前不是 Debian 11,尝试升级到 Debian 11"
|
|
|
|
|
apt-get update && apt-get dist-upgrade -y
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
|
_red "升级 Debian 11 失败,请检查网络或源配置"
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
2023-02-25 19:23:13 +08:00
|
|
|
|
_green "Debian 升级到 11 成功,请重启服务器"
|
|
|
|
|
exit 1
|
2023-02-25 19:18:30 +08:00
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# 升级 PVE
|
|
|
|
|
_yellow "升级 PVE ..."
|
2023-02-25 19:23:13 +08:00
|
|
|
|
sed -i 's/buster/bullseye/g' /etc/apt/sources.list
|
2023-02-25 19:18:30 +08:00
|
|
|
|
apt-get update && apt-get dist-upgrade -y
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
|
_red "升级 PVE 失败,请检查网络或源配置"
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
|
|
|
|
_green "PVE 升级成功,请重启系统以应用更改"
|
|
|
|
|
fi
|