From bc8a19560e72671e96a5b06b027dd17d83bb58b3 Mon Sep 17 00:00:00 2001 From: mini2024 Date: Tue, 11 Mar 2025 23:15:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20Debian=20=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=8D=87=E7=BA=A7=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 配置自动更新并设置凌晨2点自动重启 - 启用非交互式更新模式 - 安装并配置 unattended-upgrades - 配置 needrestart 为非交互式重启模式 - 简化系统更新流程 --- debian/upgrade.sh | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) 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