diff --git a/debian/upgrade.sh b/debian/upgrade.sh index 24c1314..bacea2e 100644 --- a/debian/upgrade.sh +++ b/debian/upgrade.sh @@ -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 -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 full-upgrade -y && apt -qq autoremove && @@ -14,4 +36,4 @@ DEBIAN_FRONTEND=noninteractive && apt clean && systemctl --failed && apt -qq install needrestart -y && - needrestart -q -r l + needrestart -q -r a