Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion usr/bin/mintupdate-automation
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
30 changes: 20 additions & 10 deletions usr/lib/linuxmint/mintUpdate/automatic_upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
44 changes: 29 additions & 15 deletions usr/lib/linuxmint/mintUpdate/mintUpdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = _("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)
Expand Down Expand Up @@ -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])
Expand Down
6 changes: 4 additions & 2 deletions usr/lib/linuxmint/mintUpdate/mintupdate-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion usr/share/linuxmint/mintupdate/automation/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}