From 4c5a10cbd0687a305027ccff54440ccb94894d48 Mon Sep 17 00:00:00 2001 From: johanw Date: Sat, 17 Apr 2021 16:32:51 +0200 Subject: [PATCH 1/3] Add automatic Downloads This commit is for automatic Downloads of Upgrades. The Upgrades are Downloaded automatically and installed Manually. --- .../mintupdate-automation-download.service | 13 +++++++++++++ .../system/mintupdate-automation-download.timer | 11 +++++++++++ usr/bin/mintupdate-automation | 2 +- .../linuxmint/mintUpdate/automatic_upgrades.py | 6 ++++++ usr/lib/linuxmint/mintUpdate/mintUpdate.py | 16 ++++++++++++++++ usr/lib/linuxmint/mintUpdate/mintupdate-cli.py | 6 ++++-- .../linuxmint/mintupdate/automation/index.json | 3 ++- 7 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 lib/systemd/system/mintupdate-automation-download.service create mode 100644 lib/systemd/system/mintupdate-automation-download.timer diff --git a/lib/systemd/system/mintupdate-automation-download.service b/lib/systemd/system/mintupdate-automation-download.service new file mode 100644 index 000000000..0302f228b --- /dev/null +++ b/lib/systemd/system/mintupdate-automation-download.service @@ -0,0 +1,13 @@ +[Unit] +Description=Update Manager automatic upgrades only Downloads +After=network-online.target + +[Service] +Type=oneshot +CPUQuota=50% +CPUWeight=20 +IOWeight=20 +ExecStart=/usr/lib/linuxmint/mintUpdate/automatic_upgrades.py -d + +[Install] +WantedBy=multi-user.target diff --git a/lib/systemd/system/mintupdate-automation-download.timer b/lib/systemd/system/mintupdate-automation-download.timer new file mode 100644 index 000000000..239cbe7df --- /dev/null +++ b/lib/systemd/system/mintupdate-automation-download.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Update Manager only download upgrades + +[Timer] +OnCalendar=daily +OnStartupSec=60m +RandomizedDelaySec=60m +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/usr/bin/mintupdate-automation b/usr/bin/mintupdate-automation index ba8f6c78f..c33aecdb0 100755 --- a/usr/bin/mintupdate-automation +++ b/usr/bin/mintupdate-automation @@ -10,7 +10,7 @@ if not os.getuid() == 0: print("This command needs to be run as root or with sudo.") sys.exit(1) -if len(sys.argv) != 3 or sys.argv[1] not in ("upgrade", "autoremove", "blacklist") or sys.argv[2] not in ("enable", "disable"): +if len(sys.argv) != 3 or sys.argv[1] not in ("upgrade", "autoremove", "blacklist", "download") or sys.argv[2] not in ("enable", "disable"): print("Bad arguments") sys.exit(1) diff --git a/usr/lib/linuxmint/mintUpdate/automatic_upgrades.py b/usr/lib/linuxmint/mintUpdate/automatic_upgrades.py index 3493575d7..da4faf40f 100755 --- a/usr/lib/linuxmint/mintUpdate/automatic_upgrades.py +++ b/usr/lib/linuxmint/mintUpdate/automatic_upgrades.py @@ -3,7 +3,11 @@ import os import subprocess import time +import argparse +parser = argparse.ArgumentParser(description="Script for automatic Upgrades") +parser.add_argument("-d", "--only-download", action="store_true", help="only download upgrades and do not install them.") +args=parser.parse_args() optionsfile = "/etc/mintupdate-automatic-upgrades.conf" logfile = "/var/log/mintupdate.log" log = open(logfile, "a") @@ -32,6 +36,8 @@ cmd = ["/bin/systemd-inhibit", '--why="Performing automatic updates"', '--who="Update Manager"', "--what=shutdown", "--mode=block", "/usr/bin/mintupdate-cli", "upgrade", "--refresh-cache", "--yes"] + if(args.only_download): + cmd[6] = "download" cmd.extend(arguments) subprocess.run(cmd, stdout=log, stderr=log) diff --git a/usr/lib/linuxmint/mintUpdate/mintUpdate.py b/usr/lib/linuxmint/mintUpdate/mintUpdate.py index d9750434b..a2673fa1b 100755 --- a/usr/lib/linuxmint/mintUpdate/mintUpdate.py +++ b/usr/lib/linuxmint/mintUpdate/mintUpdate.py @@ -2328,6 +2328,10 @@ def open_preferences(self, widget, show_automation=False): autoupgrade_switch.content_widget.set_active(os.path.isfile(AUTOMATIONS["upgrade"][0])) autoupgrade_switch.content_widget.connect("notify::active", self.set_auto_upgrade) section.add_row(autoupgrade_switch) + autodownload_switch = Switch(_("Download updates automatically")) + autodownload_switch.content_widget.set_active(os.path.isfile(AUTOMATIONS["download"][0])) + autodownload_switch.content_widget.connect("notify::active", self.set_auto_download) + section.add_row(autodownload_switch) button = Gtk.Button(label=_("Export blacklist to /etc/mintupdate.blacklist")) button.set_margin_start(20) button.set_margin_end(20) @@ -2383,6 +2387,18 @@ def set_auto_upgrade(self, widget, param): if widget.get_active() != os.path.isfile(AUTOMATIONS["upgrade"][0]): widget.set_active(not widget.get_active()) + def set_auto_download(self, widget, param): + exists = os.path.isfile(AUTOMATIONS["download"][0]) + action = None + if widget.get_active() and not exists: + action = "enable" + elif not widget.get_active() and exists: + action = "disable" + if action: + subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "download", action]) + if widget.get_active() != os.path.isfile(AUTOMATIONS["download"][0]): + widget.set_active(not widget.get_active()) + def set_auto_remove(self, widget, param): exists = os.path.isfile(AUTOMATIONS["autoremove"][0]) action = None diff --git a/usr/lib/linuxmint/mintUpdate/mintupdate-cli.py b/usr/lib/linuxmint/mintUpdate/mintupdate-cli.py index d99ae5175..3f55e8aca 100755 --- a/usr/lib/linuxmint/mintUpdate/mintupdate-cli.py +++ b/usr/lib/linuxmint/mintUpdate/mintupdate-cli.py @@ -24,7 +24,7 @@ def is_blacklisted(blacklisted_packages, source_name, version): return False parser = argparse.ArgumentParser(prog="mintupdate-cli") - parser.add_argument("command", help="command to run (possible commands are: list, upgrade)") + parser.add_argument("command", help="command to run (possible commands are: list, upgrade, download)") group = parser.add_mutually_exclusive_group() group.add_argument("-k", "--only-kernel", action="store_true", help="only include kernel updates") @@ -72,11 +72,13 @@ def is_blacklisted(blacklisted_packages, source_name, version): if args.command == "list": for update in updates: print ("%-15s %-45s %s" % (update.type, update.source_name, update.new_version)) - elif args.command == "upgrade": + elif args.command == "upgrade" or "download": packages = [] for update in updates: packages += update.package_names arguments = ["apt-get", "install"] + if(args.command == "download"): + arguments.append("--download-only") if args.dry_run: arguments.append("--simulate") if args.yes: diff --git a/usr/share/linuxmint/mintupdate/automation/index.json b/usr/share/linuxmint/mintupdate/automation/index.json index ab04d3af9..ee3a986cd 100644 --- a/usr/share/linuxmint/mintupdate/automation/index.json +++ b/usr/share/linuxmint/mintupdate/automation/index.json @@ -2,5 +2,6 @@ "upgrade": ["/etc/systemd/system/timers.target.wants/mintupdate-automation-upgrade.timer", "systemd"], "blacklist": ["/etc/mintupdate.blacklist", "Blacklist"], "autoremove": ["/etc/systemd/system/timers.target.wants/mintupdate-automation-autoremove.timer", "systemd"], - "clean": ["/etc/apt/apt.conf.d/99_mintupdate_clean", "apt-daily config"] + "clean": ["/etc/apt/apt.conf.d/99_mintupdate_clean", "apt-daily config"], + "download": ["/etc/systemd/system/timers.target.wants/mintupdate-automation-download.timer", "systemd"] } From b51ee5d815ed0290d14d8c13fe50394084ad8fce Mon Sep 17 00:00:00 2001 From: johan Date: Mon, 8 Apr 2024 17:56:09 +0200 Subject: [PATCH 2/3] Only one combo box to select wether updates are installed automatically, downloaded automatically ore nothing is done automatically --- .../mintupdate-automation-download.service | 13 ---- .../mintupdate-automation-download.timer | 11 ---- .../mintUpdate/automatic_upgrades.py | 15 +++-- usr/lib/linuxmint/mintUpdate/mintUpdate.py | 60 +++++++++---------- .../mintupdate/automation/index.json | 2 +- 5 files changed, 39 insertions(+), 62 deletions(-) delete mode 100644 lib/systemd/system/mintupdate-automation-download.service delete mode 100644 lib/systemd/system/mintupdate-automation-download.timer diff --git a/lib/systemd/system/mintupdate-automation-download.service b/lib/systemd/system/mintupdate-automation-download.service deleted file mode 100644 index 0302f228b..000000000 --- a/lib/systemd/system/mintupdate-automation-download.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Update Manager automatic upgrades only Downloads -After=network-online.target - -[Service] -Type=oneshot -CPUQuota=50% -CPUWeight=20 -IOWeight=20 -ExecStart=/usr/lib/linuxmint/mintUpdate/automatic_upgrades.py -d - -[Install] -WantedBy=multi-user.target diff --git a/lib/systemd/system/mintupdate-automation-download.timer b/lib/systemd/system/mintupdate-automation-download.timer deleted file mode 100644 index 239cbe7df..000000000 --- a/lib/systemd/system/mintupdate-automation-download.timer +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Update Manager only download upgrades - -[Timer] -OnCalendar=daily -OnStartupSec=60m -RandomizedDelaySec=60m -Persistent=true - -[Install] -WantedBy=timers.target diff --git a/usr/lib/linuxmint/mintUpdate/automatic_upgrades.py b/usr/lib/linuxmint/mintUpdate/automatic_upgrades.py index e75d8079c..c8bfa8bce 100755 --- a/usr/lib/linuxmint/mintUpdate/automatic_upgrades.py +++ b/usr/lib/linuxmint/mintUpdate/automatic_upgrades.py @@ -16,7 +16,10 @@ logfile = "/var/log/mintupdate.log" power_connectfile="/sys/class/power_supply/AC/online" log = open(logfile, "a") -log.write("\n-- Automatic Upgrade starting %s:\n" % time.strftime('%a %d %b %Y %H:%M:%S %Z')) +if only_download: + log.write("\n-- Automatic Upgrade will only be downloaded and not installed(can be changed in mintupdate settings) %s:\n" % time.strftime('%a %d %b %Y %H:%M:%S %Z')) +else: + log.write("\n-- Automatic Upgrade starting %s:\n" % time.strftime('%a %d %b %Y %H:%M:%S %Z')) log.flush() pkla_source = "/usr/share/linuxmint/mintupdate/automation/99-mintupdate-temporary.pkla" @@ -44,7 +47,10 @@ line = line.strip() if line and not line.startswith("#"): arguments.append(line) - + except: + import traceback + log.write("Exception occurred:\n") + log.write(traceback.format_exc()) # Run mintupdate-cli through systemd-inhibit cmd = ["/bin/systemd-inhibit", '--why="Performing automatic updates"', '--who="Update Manager"', "--what=shutdown", "--mode=block", @@ -54,10 +60,7 @@ cmd.extend(arguments) subprocess.run(cmd, stdout=log, stderr=log) - except: - import traceback - log.write("Exception occurred:\n") - log.write(traceback.format_exc()) + try: # Remove shutdown and reboot blocker diff --git a/usr/lib/linuxmint/mintUpdate/mintUpdate.py b/usr/lib/linuxmint/mintUpdate/mintUpdate.py index 7bd14a876..dd6f53531 100755 --- a/usr/lib/linuxmint/mintUpdate/mintUpdate.py +++ b/usr/lib/linuxmint/mintUpdate/mintUpdate.py @@ -2544,14 +2544,16 @@ def open_preferences(self, widget, show_automation=False): page = SettingsPage() box.pack_start(page, True, True, 0) section = page.add_section(_("Package Updates"), _("Performed as root on a daily basis")) - autoupgrade_switch = Switch(_("Apply updates automatically")) - autoupgrade_switch.content_widget.set_active(os.path.isfile(AUTOMATIONS["upgrade"][2])) - autoupgrade_switch.content_widget.connect("notify::active", self.set_auto_upgrade) - section.add_row(autoupgrade_switch) - autodownload_switch = Switch(_("Download updates automatically")) - autodownload_switch.content_widget.set_active(os.path.isfile(AUTOMATIONS["download"][0])) - autodownload_switch.content_widget.connect("notify::active", self.set_auto_download) - section.add_row(autodownload_switch) + autoupgrade_combo = ComboBox(label = _("Select what to do automatically"), options = [[0, _("Nothing")], [1,_("Only Download")], [2,_("Download and install (recommended)")]]) + if (os.path.isfile(AUTOMATIONS["upgrade"][2])): + active = 2 + elif (os.path.isfile(AUTOMATIONS["download"][2])): + active = 1 + else: + active = 0 + autoupgrade_combo.content_widget.set_active(active) + autoupgrade_combo.content_widget.connect("changed", self.set_auto_upgrade) + section.add_row(autoupgrade_combo) button = Gtk.Button(label=_("Export blacklist to /etc/mintupdate.blacklist")) button.set_margin_start(20) button.set_margin_end(20) @@ -2595,29 +2597,25 @@ def auto_refresh_toggled(self, widget, param): self.auto_refresh = AutomaticRefreshThread(self) self.auto_refresh.start() - def set_auto_upgrade(self, widget, param): - exists = os.path.isfile(AUTOMATIONS["upgrade"][2]) - action = None - if widget.get_active() and not exists: - action = "enable" - elif not widget.get_active() and exists: - action = "disable" - if action: - subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "upgrade", action]) - if widget.get_active() != os.path.isfile(AUTOMATIONS["upgrade"][2]): - widget.set_active(not widget.get_active()) - - def set_auto_download(self, widget, param): - exists = os.path.isfile(AUTOMATIONS["download"][0]) - action = None - if widget.get_active() and not exists: - action = "enable" - elif not widget.get_active() and exists: - action = "disable" - if action: - subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "download", action]) - if widget.get_active() != os.path.isfile(AUTOMATIONS["download"][0]): - widget.set_active(not widget.get_active()) + def set_auto_upgrade(self, widget): + model = widget.get_model() + upgrade_exists = exists = os.path.isfile(AUTOMATIONS["upgrade"][2]) + download_exists = exists = os.path.isfile(AUTOMATIONS["download"][2]) + if model[widget.get_active_iter()][0]==0: + if upgrade_exists: + subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "upgrade", "disable"]) + if download_exists: + subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "download", "disable"]) + elif model[widget.get_active_iter()][0]==1: + if upgrade_exists: + subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "upgrade", "disable"]) + if not download_exists: + subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "download", "enable"]) + elif model[widget.get_active_iter()][0]==2: + if download_exists: + subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "download", "disable"]) + if not upgrade_exists: + subprocess.run(["pkexec", "/usr/bin/mintupdate-automation", "upgrade", "enable"]) def set_auto_remove(self, widget, param): exists = os.path.isfile(AUTOMATIONS["autoremove"][2]) diff --git a/usr/share/linuxmint/mintupdate/automation/index.json b/usr/share/linuxmint/mintupdate/automation/index.json index ed6474db7..c8d4af7d9 100644 --- a/usr/share/linuxmint/mintupdate/automation/index.json +++ b/usr/share/linuxmint/mintupdate/automation/index.json @@ -2,6 +2,6 @@ "upgrade": ["/etc/systemd/system/timers.target.wants/mintupdate-automation-upgrade.timer", "systemd", "/var/lib/linuxmint/mintupdate-automatic-upgrades-enabled"], "blacklist": ["/etc/mintupdate.blacklist", "Blacklist", null], "autoremove": ["/etc/systemd/system/timers.target.wants/mintupdate-automation-autoremove.timer", "systemd", "/var/lib/linuxmint/mintupdate-automatic-removals-enabled"], - "clean": ["/etc/apt/apt.conf.d/99_mintupdate_clean", "apt-daily config", null] + "clean": ["/etc/apt/apt.conf.d/99_mintupdate_clean", "apt-daily config", null], "download": ["/etc/systemd/system/timers.target.wants/mintupdate-automation-upgrade.timer", "systemd", "/var/lib/linuxmint/mintupdate-automatic-downloads-enabled"] } From 8e6f241f7b9d4a4236e4f8346b0f91fbfde1ddc8 Mon Sep 17 00:00:00 2001 From: MidnightNerd <47281801+MidnightNerd@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:03:52 +0200 Subject: [PATCH 3/3] Improved texts --- usr/lib/linuxmint/mintUpdate/mintUpdate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/lib/linuxmint/mintUpdate/mintUpdate.py b/usr/lib/linuxmint/mintUpdate/mintUpdate.py index dd6f53531..ea498ed58 100755 --- a/usr/lib/linuxmint/mintUpdate/mintUpdate.py +++ b/usr/lib/linuxmint/mintUpdate/mintUpdate.py @@ -2544,7 +2544,7 @@ def open_preferences(self, widget, show_automation=False): page = SettingsPage() box.pack_start(page, True, True, 0) section = page.add_section(_("Package Updates"), _("Performed as root on a daily basis")) - autoupgrade_combo = ComboBox(label = _("Select what to do automatically"), options = [[0, _("Nothing")], [1,_("Only Download")], [2,_("Download and install (recommended)")]]) + autoupgrade_combo = ComboBox(label = _("Apply updates automatically?"), options = [[0, _("No")], [1,_("Only Download")], [2,_("Yes (recommended)")]]) if (os.path.isfile(AUTOMATIONS["upgrade"][2])): active = 2 elif (os.path.isfile(AUTOMATIONS["download"][2])):