
- 配置自动更新并设置凌晨2点自动重启 - 启用非交互式更新模式 - 安装并配置 unattended-upgrades - 配置 needrestart 为非交互式重启模式 - 简化系统更新流程
40 lines
1.0 KiB
Bash
40 lines
1.0 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# ...
|
|
#
|
|
# 使用方法:
|
|
# URL="https://git.1-h.cc/Scripts/Linux/raw/branch/main/debian/upgrade.sh"; curl -fsSL "$URL" | bash || wget -q -O - "$URL" | bash
|
|
|
|
# 设置非交互式环境变量
|
|
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 full-upgrade -y &&
|
|
apt -qq autoremove &&
|
|
apt -qq autoclean &&
|
|
apt clean &&
|
|
systemctl --failed &&
|
|
apt -qq install needrestart -y &&
|
|
needrestart -q -r a
|