这是我“Linux 一键装机脚本”里的一个函数,每台必跑 ``` setup_auto_upgrade(){ local file o m d r if [ "$distro" = debian ]; then sudo $pkg install -y unattended-upgrades # In case not installed yet. file=/etc/apt/apt.conf.d/50unattended-upgrades # ${distro_codename}-updates & ${distro_codename}-proposed-updates o='origin=Debian,codename=${distro_codename}.*-updates' m='Unattended-Upgrade::Mail ' d='Unattended-Upgrade::Remove-Unused-Dependencies' # Automatic-Reboot & Automatic-Reboot-WithUsers r='Unattended-Upgrade::Automatic-Reboot.*"\(false\|true\)"'
# Set mail to sudo sed -i "/$m/s:\"\":\"$user\":" $file # Set Remove-Unused-Dependencies, Automatic-Reboot and Automatic-Reboot-WithUsers to true sudo sed -i "/$d\|$r/s:false:true:" $file # Uncomment these lines sudo sed -i "/$o\|$m\|$d\|$r/s://::" $file
# Generate /etc/apt/apt.conf.d/20auto-upgrades sudo dpkg-reconfigure -plow unattended-upgrades fi
if [ "$distro" = fedora ]; then sudo $pkg install -y dnf-automatic # In case not installed yet. local file=/etc/dnf/automatic.conf sudo sed -i '/apply_updates/s/no/yes/' $file sudo systemctl enable --now dnf-automatic.timer postfix fi } ```