Skip to content

Commit

Permalink
fix: only show post update notification when there is a pending deplo…
Browse files Browse the repository at this point in the history
…yment (#83)
  • Loading branch information
gerblesh authored Oct 11, 2023
1 parent 9993055 commit e117cc8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
45 changes: 19 additions & 26 deletions src/ublue_update/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -201,6 +193,7 @@ def run_updates(args):
log = logging.getLogger(__name__)

cli_args = None
system_update_available: bool = False


def main():
Expand Down Expand Up @@ -240,20 +233,20 @@ 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,
)
if cli_args.check:
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)

Expand Down
18 changes: 12 additions & 6 deletions src/ublue_update/update_checks/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from logging import getLogger
from subprocess import PIPE, run


"""Setup logging"""
log = getLogger(__name__)

Expand All @@ -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://"
Expand All @@ -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

0 comments on commit e117cc8

Please sign in to comment.