diff --git a/src/ublue_update/cli.py b/src/ublue_update/cli.py index aa2da7e..834acd6 100644 --- a/src/ublue_update/cli.py +++ b/src/ublue_update/cli.py @@ -5,7 +5,9 @@ import tomllib import argparse + from ublue_update.update_checks.system import system_update_check +from ublue_update.update_checks.wait import transaction_wait def notify(title: str, body: str, actions: list = [], expire_time: int = 0): @@ -153,6 +155,9 @@ def run_updates(): log.info("Running system update") + """Wait on any existing transactions to complete before updating""" + transaction_wait() + for root, dirs, files in os.walk(root_dir): for file in files: full_path = root_dir + str(file) @@ -214,9 +219,19 @@ def main(): action="store_true", help="check for updates and exit", ) + parser.add_argument( + "-w", + "--wait", + action="store_true", + help="wait for transactions to complete and exit", + ) args = parser.parse_args() hardware_checks_failed = False + if args.wait: + transaction_wait() + os._exit(0) + if not args.force and not args.updatecheck: hardware_checks_failed, failures = check_hardware_inhibitors() if hardware_checks_failed: diff --git a/src/ublue_update/update_checks/wait.py b/src/ublue_update/update_checks/wait.py new file mode 100644 index 0000000..2108841 --- /dev/null +++ b/src/ublue_update/update_checks/wait.py @@ -0,0 +1,16 @@ +from json import loads +from subprocess import PIPE, run +from time import sleep + + +def transaction(): + """Pull deployment status via rpm-ostree""" + rpm_ostree_status = ["rpm-ostree", "status", "--json"] + status = run(rpm_ostree_status, stdout=PIPE) + """Parse transaction state""" + return loads(status.stdout)["transaction"] + + +def transaction_wait(): + while transaction() is not None: + sleep(1)