mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
upgrades: Refactor code to hold packages
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
20d9f8af8d
commit
6b13e0eb7a
@ -9,8 +9,7 @@ import time
|
|||||||
from typing import Generator
|
from typing import Generator
|
||||||
|
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
from plinth.action_utils import (apt_hold, apt_hold_freedombox,
|
from plinth.action_utils import (debconf_set_selections, run_apt_command,
|
||||||
debconf_set_selections, run_apt_command,
|
|
||||||
service_daemon_reload, service_restart)
|
service_daemon_reload, service_restart)
|
||||||
from plinth.modules import snapshot as snapshot_module
|
from plinth.modules import snapshot as snapshot_module
|
||||||
|
|
||||||
@ -168,12 +167,32 @@ def _services_disable():
|
|||||||
flush=True)
|
flush=True)
|
||||||
|
|
||||||
|
|
||||||
def perform():
|
@contextlib.contextmanager
|
||||||
"""Perform upgrade to next release of Debian."""
|
def _apt_hold_packages():
|
||||||
|
"""Apt hold some packages during dist upgrade."""
|
||||||
|
packages = DIST_UPGRADE_PACKAGES_WITH_PROMPTS
|
||||||
|
packages_string = ', '.join(packages)
|
||||||
|
|
||||||
# Hold freedombox package during entire dist upgrade.
|
# Hold freedombox package during entire dist upgrade.
|
||||||
print('Holding freedombox package...', flush=True)
|
print('Holding freedombox package...', flush=True)
|
||||||
with (apt_hold_freedombox(), _snapshot_run_and_disable(),
|
with action_utils.apt_hold_freedombox():
|
||||||
_services_disable()):
|
# Hold packages known to have conffile prompts. FreedomBox service
|
||||||
|
# will handle their upgrade later.
|
||||||
|
print(f'Holding packages with conffile prompts: {packages_string}...',
|
||||||
|
flush=True)
|
||||||
|
with action_utils.apt_hold(packages):
|
||||||
|
yield
|
||||||
|
print(
|
||||||
|
'Releasing holds on packages with conffile prompts: '
|
||||||
|
f'{packages_string}...', flush=True)
|
||||||
|
|
||||||
|
print('Releasing hold on freedombox package...')
|
||||||
|
|
||||||
|
|
||||||
|
def perform():
|
||||||
|
"""Perform upgrade to next release of Debian."""
|
||||||
|
with (_snapshot_run_and_disable(), _services_disable(),
|
||||||
|
_apt_hold_packages()):
|
||||||
print('Updating Apt cache...', flush=True)
|
print('Updating Apt cache...', flush=True)
|
||||||
run_apt_command(['update'])
|
run_apt_command(['update'])
|
||||||
|
|
||||||
@ -192,16 +211,9 @@ def perform():
|
|||||||
flush=True)
|
flush=True)
|
||||||
run_apt_command(['remove'] + DIST_UPGRADE_OBSOLETE_PACKAGES)
|
run_apt_command(['remove'] + DIST_UPGRADE_OBSOLETE_PACKAGES)
|
||||||
|
|
||||||
# Hold packages known to have conffile prompts. FreedomBox service
|
# Run and check if apt upgrade was successful.
|
||||||
# will handle their upgrade later.
|
|
||||||
print(
|
|
||||||
'Holding packages with conffile prompts: ' +
|
|
||||||
', '.join(DIST_UPGRADE_PACKAGES_WITH_PROMPTS) + '...', flush=True)
|
|
||||||
with apt_hold(DIST_UPGRADE_PACKAGES_WITH_PROMPTS):
|
|
||||||
print('Running apt full-upgrade...', flush=True)
|
print('Running apt full-upgrade...', flush=True)
|
||||||
returncode = run_apt_command(['full-upgrade'])
|
returncode = run_apt_command(['full-upgrade'])
|
||||||
|
|
||||||
# Check if apt upgrade was successful.
|
|
||||||
if returncode:
|
if returncode:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
'Apt full-upgrade was not successful. Distribution upgrade '
|
'Apt full-upgrade was not successful. Distribution upgrade '
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user