diff --git a/usr/bin/mintupdate-automation b/usr/bin/mintupdate-automation index 929e4cb1..eae03ba3 100755 --- a/usr/bin/mintupdate-automation +++ b/usr/bin/mintupdate-automation @@ -11,7 +11,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 14196d60..c8bfa8bc 100755 --- a/usr/lib/linuxmint/mintUpdate/automatic_upgrades.py +++ b/usr/lib/linuxmint/mintUpdate/automatic_upgrades.py @@ -3,15 +3,23 @@ import os import subprocess import time +import argparse -if not os.path.exists("/var/lib/linuxmint/mintupdate-automatic-upgrades-enabled"): +if not (os.path.exists("/var/lib/linuxmint/mintupdate-automatic-upgrades-enabled") or os.path.exists("/var/lib/linuxmint/mintupdate-automatic-downloads-enabled")): exit(0) +if os.path.exists("/var/lib/linuxmint/mintupdate-automatic-downloads-enabled"): + only_download = True +else: + only_download = False optionsfile = "/etc/mintupdate-automatic-upgrades.conf" 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" @@ -39,18 +47,20 @@ line = line.strip() if line and not line.startswith("#"): arguments.append(line) - - # Run mintupdate-cli through systemd-inhibit - cmd = ["/bin/systemd-inhibit", '--why="Performing automatic updates"', - '--who="Update Manager"', "--what=shutdown", "--mode=block", - "/usr/bin/mintupdate-cli", "upgrade", "--refresh-cache", "--yes"] - cmd.extend(arguments) - subprocess.run(cmd, stdout=log, stderr=log) - 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", + "/usr/bin/mintupdate-cli", "upgrade", "--refresh-cache", "--yes"] + if(only_download): + cmd[6] = "download" + cmd.extend(arguments) + subprocess.run(cmd, stdout=log, stderr=log) + + try: # Remove shutdown and reboot blocker diff --git a/usr/lib/linuxmint/mintUpdate/mintUpdate.py b/usr/lib/linuxmint/mintUpdate/mintUpdate.py index 070eed0d..ea498ed5 100755 --- a/usr/lib/linuxmint/mintUpdate/mintUpdate.py +++ b/usr/lib/linuxmint/mintUpdate/mintUpdate.py @@ -2544,10 +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) + 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])): + 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) @@ -2591,17 +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_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/lib/linuxmint/mintUpdate/mintupdate-cli.py b/usr/lib/linuxmint/mintUpdate/mintupdate-cli.py index d99ae517..3f55e8ac 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 577bd8a4..c8d4af7d 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", "/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"] }