优化 Debian 系统升级脚本
- 配置自动更新并设置凌晨2点自动重启 - 启用非交互式更新模式 - 安装并配置 unattended-upgrades - 配置 needrestart 为非交互式重启模式 - 简化系统更新流程
This commit is contained in:
28
debian/upgrade.sh
vendored
28
debian/upgrade.sh
vendored
@ -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
|
||||
|
Reference in New Issue
Block a user