mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
upgrades: Log apt output to journal during dist upgrade
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
32739bb8b7
commit
1b89151c38
@ -449,14 +449,14 @@ def is_disk_image():
|
||||
return os.path.exists('/var/lib/freedombox/is-freedombox-disk-image')
|
||||
|
||||
|
||||
def run_apt_command(arguments):
|
||||
def run_apt_command(arguments, stdout=subprocess.DEVNULL):
|
||||
"""Run apt-get with provided arguments."""
|
||||
command = ['apt-get', '--assume-yes', '--quiet=2'] + arguments
|
||||
|
||||
env = os.environ.copy()
|
||||
env['DEBIAN_FRONTEND'] = 'noninteractive'
|
||||
process = subprocess.run(command, stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.DEVNULL, env=env, check=False)
|
||||
process = subprocess.run(command, stdin=subprocess.DEVNULL, stdout=stdout,
|
||||
env=env, check=False)
|
||||
return process.returncode
|
||||
|
||||
|
||||
|
||||
@ -27,6 +27,11 @@ DIST_UPGRADE_PRE_DEBCONF_SELECTIONS: list[str] = [
|
||||
]
|
||||
|
||||
|
||||
def _apt_run(arguments):
|
||||
"""Run an apt command and ensure that output is written to stdout."""
|
||||
return action_utils.run_apt_command(arguments, stdout=None)
|
||||
|
||||
|
||||
def _sources_list_update(old_codename: str, new_codename: str):
|
||||
"""Change the distribution in /etc/apt/sources.list."""
|
||||
logging.info('Upgrading from %s to %s...', old_codename, new_codename)
|
||||
@ -208,26 +213,25 @@ def _packages_remove_obsolete() -> None:
|
||||
if DIST_UPGRADE_OBSOLETE_PACKAGES:
|
||||
print(f'Removing packages: {DIST_UPGRADE_OBSOLETE_PACKAGES}...',
|
||||
flush=True)
|
||||
action_utils.run_apt_command(['remove'] +
|
||||
DIST_UPGRADE_OBSOLETE_PACKAGES)
|
||||
_apt_run(['remove'] + DIST_UPGRADE_OBSOLETE_PACKAGES)
|
||||
|
||||
|
||||
def _apt_update():
|
||||
"""Run 'apt update'."""
|
||||
print('Updating Apt cache...', flush=True)
|
||||
action_utils.run_apt_command(['update'])
|
||||
_apt_run(['update'])
|
||||
|
||||
|
||||
def _apt_autoremove():
|
||||
"""Run 'apt autoremove'."""
|
||||
print('Running apt autoremove...', flush=True)
|
||||
action_utils.run_apt_command(['autoremove'])
|
||||
_apt_run(['autoremove'])
|
||||
|
||||
|
||||
def _apt_full_upgrade():
|
||||
"""Run and check if apt upgrade was successful."""
|
||||
print('Running apt full-upgrade...', flush=True)
|
||||
returncode = action_utils.run_apt_command(['full-upgrade'])
|
||||
returncode = _apt_run(['full-upgrade'])
|
||||
if returncode:
|
||||
raise RuntimeError(
|
||||
'Apt full-upgrade was not successful. Distribution upgrade '
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user