关机时自动更新

关机时自动更新

在我的系统中我想出了以下 bash 别名:

别名 updt='apt update -y && apt upgrade -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 repo。您可以更新它以包含所有来源。最佳做法是添加稳定、可靠的来源,如 -updates 和 -security(这两个应该是您升级的绝大部分!)不建议将其用于 -proposed 或其他测试/不稳定来源。

// 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";

相关内容