From 6665aa8fbb606e2045dcb10b9d2b6b39966f40e5 Mon Sep 17 00:00:00 2001 From: clore Date: Fri, 3 Jan 2025 18:09:30 +0000 Subject: [PATCH] ensure_packages_installed reconfigure dpkg when mandatory --- lib/ensure_packages_installed.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/ensure_packages_installed.py b/lib/ensure_packages_installed.py index 16ea2c1..c31b616 100644 --- a/lib/ensure_packages_installed.py +++ b/lib/ensure_packages_installed.py @@ -76,6 +76,30 @@ async def ensure_packages_installed( if return_code == 0: log.debug(f"Successfully installed packages: {packages_to_install}") return True + elif return_code == 100: + dpkg_rc, dpkg_stdout, dpkg_stderr = await utils.async_run_command( + "sudo dpkg --configure -a", + timeout=200, + env=non_interactive_env + ) + + # Install packages + return_code, stdout, stderr = await utils.async_run_command( + install_cmd, + timeout=remaining_timeout, + env=non_interactive_env + ) + + if LOGGING_ENABLED: + await ensure_packages_installed_log(f"post-dpkg install stdout: {stdout}") + await ensure_packages_installed_log(f"post-dpkg install stderr: {stderr}\ncode: {str(return_code)}") + + if return_code == 0: + log.debug(f"Successfully installed packages: {packages_to_install}") + return True + else: + log.error(f"Failed to install packages: {stderr}") + return False else: log.error(f"Failed to install packages: {stderr}") return False