關機時自動更新

關機時自動更新

在我的系統中,我想出了以下 bash 別名:

alias updt='apt update -y && apt update -y && apt autoremove -y'

我幾乎每次使用系統時都會運行這個。我的問題是:

是否可以讓系統在每次關閉電腦時都執行此命令?

作為獎勵:我可以像在 Windows 上一樣,在直接從桌面環境的右上角使用關閉選項時使系統自動更新嗎?

答案1

是的。這是一個設定。

易於已經後台 apt 更新和 apt 升級嗎...

/lib/systemd/system/apt-daily.timer           // update
/lib/systemd/system/apt-daily-upgrade.timer   // upgrade

....您真正需要做的就是遠離它,並如下所示調整設定。


編輯設定檔/etc/apt/apt.conf.d/50unattended-upgrades

命令範例:$ sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

第 1 步:編輯您的來源。預設設定僅包括 -security 儲存庫。您可以更新它以包含您的所有來源。最佳實踐是添加穩定、可靠的來源,例如-updates 和-security(這兩個應該是升級的絕大多數!)不建議將其用於-提議的或其他測試/不穩定的來源。

// Automatically upgrade packages from these (origin:archive) pairs
//
// Note that in Ubuntu security updates may pull in new dependencies
// from non-security sources (e.g. chromium). By allowing the release
// pocket these get automatically pulled in.
Unattended-Upgrade::Allowed-Origins {
        "${distro_id}:${distro_codename}";
        "${distro_id}:${distro_codename}-security";
        // Extended Security Maintenance; does not necessarily exist for
        // every release and this system may not have it installed, but if
        // available, the policy for updates is such that unattended-upgrades
        // should also install from here by default.
        "${distro_id}ESM:${distro_codename}";
        "${distro_id}:${distro_codename}-updates";
//      "${distro_id}:${distro_codename}-proposed";
//      "${distro_id}:${distro_codename}-backports";
};

第 2 步:啟用自動刪除。只需取消最後一行的註解:

// Do automatic removal of unused packages after the upgrade
// (equivalent to apt-get autoremove)
//Unattended-Upgrade::Remove-Unused-Dependencies "true";

步驟 3:關機時進行升級而不是在後台。只需取消最後一行的註解:

// Install all unattended-upgrades when the machine is shutting down
// instead of doing it in the background while the machine is running
// This will (obviously) make shutdown slower
//Unattended-Upgrade::InstallOnShutdown "true";

相關內容