#!/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 -r a ################################################################################ # needrestart --help # needrestart 3.6 - Restart daemons after library updates. # Authors: # Thomas Liske # Copyright Holder: # 2013 - 2022 (C) Thomas Liske [http://fiasko-nw.net/~thomas/] # Upstream: # https://github.com/liske/needrestart # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # Usage: # needrestart [-vn] [-c ] [-r ] [-f ] [-u ] [-bkl] # -v be more verbose # -q be quiet # -m set detail level # e (e)asy mode # a (a)dvanced mode # -n set default answer to 'no' # -c config filename # -r set restart mode # l (l)ist only # i (i)nteractive restart # a (a)utomatically restart # -b enable batch mode # -p enable nagios plugin mode # -f override debconf frontend (DEBIAN_FRONTEND, debconf(7)) # -t tolerate interpreter process start times within this value # -u use preferred UI package (-u ? shows available packages) # By using the following options only the specified checks are performed: # -k check for obsolete kernel # -l check for obsolete libraries # -w check for obsolete CPU microcode # --help show this help # --version show version information