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