优化 Debian 系统升级脚本

- 配置自动更新并设置凌晨2点自动重启
- 启用非交互式更新模式
- 安装并配置 unattended-upgrades
- 配置 needrestart 为非交互式重启模式
- 简化系统更新流程
This commit is contained in:
mini2024
2025-03-11 23:15:25 +08:00
parent d4075cc93b
commit bc8a19560e

28
debian/upgrade.sh vendored
View File

@ -5,8 +5,30 @@
# 使用方法: # 使用方法:
# URL="https://git.1-h.cc/Scripts/Linux/raw/branch/main/debian/upgrade.sh"; curl -fsSL "$URL" | bash || wget -q -O - "$URL" | bash # URL="https://git.1-h.cc/Scripts/Linux/raw/branch/main/debian/upgrade.sh"; curl -fsSL "$URL" | bash || wget -q -O - "$URL" | bash
DEBIAN_FRONTEND=noninteractive && # 设置非交互式环境变量
apt -qq update && export DEBIAN_FRONTEND=noninteractive
export NEEDRESTART_MODE=a
# 安装自动更新
apt install -y unattended-upgrades
# 配置自动更新并在凌晨2点自动重启
cat << EOF | tee /etc/apt/apt.conf.d/50unattended-upgrades
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-WithUsers "true";
Unattended-Upgrade::Automatic-Reboot-Time "02:00";
EOF
# 配置 needrestart 为非交互式
cat << EOF | tee /etc/needrestart/conf.d/50noninteractive.conf
\$nrconf{restart} = 'a';
\$nrconf{kernelhints} = -1;
EOF
# 启用自动更新
dpkg-reconfigure -plow unattended-upgrades
apt -qq update &&
apt -qq upgrade -y && apt -qq upgrade -y &&
apt -qq full-upgrade -y && apt -qq full-upgrade -y &&
apt -qq autoremove && apt -qq autoremove &&
@ -14,4 +36,4 @@ DEBIAN_FRONTEND=noninteractive &&
apt clean && apt clean &&
systemctl --failed && systemctl --failed &&
apt -qq install needrestart -y && apt -qq install needrestart -y &&
needrestart -q -r l needrestart -q -r a