miaohao
光这样不行吧,得参考一下这个 https://gist.github.com/tomzo/115c37aa0e3a6cf1c58dde12d2ff47ce
#!/bin/bash
# disable automatic upgrades to avoid error on start: "Could not get lock /var/lib/dpkg/lock"
cat << EOF > 20auto-upgrades
// Do "apt-get update" automatically every n-days (0=disable)
APT::Periodic::Update-Package-Lists "0";
// Run the "unattended-upgrade" security upgrade script
// every n-days (0=disabled)
// Requires the package "unattended-upgrades" and will write
// a log in /var/log/unattended-upgrades
APT::Periodic::Unattended-Upgrade "0";
// Do "apt-get upgrade --download-only" every n-days (0=disable)
APT::Periodic::Download-Upgradeable-Packages "0";
// Do "apt-get autoclean" every n-days (0=disable)
APT::Periodic::AutocleanInterval "0";
// Send report mail to root
// 0: no report (or null string)
// 1: progress report (actually any string)
// 2: + command outputs (remove -qq, remove 2>/dev/null, add -d)
// 3: + trace on
APT::Periodic::Verbose "1";
EOF
sudo mv -f 20auto-upgrades /etc/apt/apt.conf.d/20auto-upgrades
sudo chmod 644 /etc/apt/apt.conf.d/20auto-upgrades
sudo apt-get purge -y unattended-upgrades
sudo systemctl stop apt-daily.timer
sudo systemctl disable apt-daily.timer
sudo systemctl mask apt-daily.service
sudo rm /usr/lib/apt/apt.systemd.daily
function purge_if_installed() {
local package=${1}
( set +e; dpkg -s "${package}" 1>/dev/null && sudo apt-get purge -y "${package}" || echo "package was not installed: ${package}"; )
}
purge_if_installed ubuntu-release-upgrader-core
purge_if_installed python3-update-manager
sudo apt-get clean
sudo apt-get -y autoremove --purge
sudo apt-get autoclean
sudo rm -rf /var/cache/apt/*