diff --git a/src/ublue_update/cli.py b/src/ublue_update/cli.py index 58aa029..0702524 100644 --- a/src/ublue_update/cli.py +++ b/src/ublue_update/cli.py @@ -3,7 +3,10 @@ import logging import argparse -from ublue_update.update_checks.system import system_update_check +from ublue_update.update_checks.system import ( + system_update_check, + pending_deployment_check, +) from ublue_update.update_checks.wait import transaction_wait from ublue_update.update_inhibitors.hardware import check_hardware_inhibitors from ublue_update.config import load_value @@ -69,25 +72,9 @@ def ask_for_updates(): if "universal-blue-update-confirm" in out.stdout.decode("utf-8"): run_updates(cli_args) - -def check_for_updates(checks_failed: bool) -> bool: - """Tracks whether any updates are available""" - update_available: bool = False - system_update_available: bool = False - system_update_available = system_update_check() - if system_update_available: - update_available = True - if update_available: - return True - log.info("No updates are available.") - return False - - -def hardware_inhibitor_checks_failed( - hardware_checks_failed: bool, failures: list, hardware_check: bool -): +def hardware_inhibitor_checks_failed(failures: list, hardware_check: bool): # ask if an update can be performed through dbus notifications - if check_for_updates(hardware_checks_failed) and not hardware_check: + if system_update_available and not hardware_check: log.info("Harware checks failed, but update is available") ask_for_updates() # notify systemd that the checks have failed, @@ -176,11 +163,16 @@ def run_updates(args): capture_output=True, ) log.debug(out.stdout.decode("utf-8")) - notify( - "System Updater", - "System update complete, reboot for changes to take effect", - ) log.info("System update complete") + if pending_deployment_check() and system_update_available: + out = notify( + "System Updater", + "System update complete, pending changes will take effect after reboot. Reboot now?", + ["universal-blue-update-reboot=Reboot Now"], + ) + # if the user has confirmed the reboot + if "universal-blue-update-reboot" in out.stdout.decode("utf-8"): + subprocess.run(["systemctl", "reboot"]) else: if args.system: raise Exception( @@ -201,6 +193,7 @@ def run_updates(args): log = logging.getLogger(__name__) cli_args = None +system_update_available: bool = False def main(): @@ -240,11 +233,12 @@ def main(): transaction_wait() os._exit(0) + system_update_available = system_update_check() + if not cli_args.force and not cli_args.updatecheck: hardware_checks_failed, failures = check_hardware_inhibitors() if hardware_checks_failed: hardware_inhibitor_checks_failed( - hardware_checks_failed, failures, cli_args.check, ) @@ -252,8 +246,7 @@ def main(): os._exit(0) if cli_args.updatecheck: - update_available = check_for_updates(False) - if not update_available: + if not system_update_available: raise Exception("Update not available") os._exit(0) diff --git a/src/ublue_update/update_checks/system.py b/src/ublue_update/update_checks/system.py index 61dd942..2afa4b4 100644 --- a/src/ublue_update/update_checks/system.py +++ b/src/ublue_update/update_checks/system.py @@ -3,7 +3,6 @@ from logging import getLogger from subprocess import PIPE, run - """Setup logging""" log = getLogger(__name__) @@ -24,13 +23,13 @@ def system_update_check(): """Parse installation digest and image""" try: deployments = loads(status)["deployments"][0] + installation_digest = deployments["base-commit-meta"]["ostree.manifest-digest"] + current_image = deployments["container-image-reference"].split(":", 1) except (JSONDecodeError, KeyError): log.error( "update check failed, system isn't managed by rpm-ostree container native" ) return False - installation_digest = deployments["base-commit-meta"]["ostree.manifest-digest"] - current_image = deployments["container-image-reference"].split(":", 1) """Dissect current image to form URL to latest image""" protocol = "docker://" @@ -48,7 +47,14 @@ def system_update_check(): """Digests match, so no updates""" log.info("No system update available.") return False - else: - """Digests do not match, so updates are available""" - log.info("System update available.") + """Digests do not match, so updates are available""" + log.info("System update available.") + return True + + +def pending_deployment_check(): + rpm_ostree_cmd = ["rpm-ostree", "status", "--pending-exit-77"] + status = run(rpm_ostree_cmd, capture_output=True) + if status.returncode == 77: # no pending deployment return True + return False