one-click-installation-script/todebian11.sh

83 lines
2.2 KiB
Bash
Raw Normal View History

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
# 从文件中读取当前版本代号
CURRENT_VERSION=$(cat /etc/os-release | grep VERSION= | cut -d '"' -f2 | cut -d ' ' -f1)
2023-02-25 19:45:22 +08:00
# 判断当前版本是否为最新版本
if [ $CURRENT_VERSION == "bullseye" ]; then
2023-02-25 19:48:27 +08:00
_blue "当前系统版本为最新版本"
2023-02-25 19:45:22 +08:00
exit 0
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 19:35:45 +08:00
apt-get update
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 重启系统以完成内核升级"
exit 1