packages: Mark freedombox package as held during package installs

In case the package to be installed (or its dependencies) conflicts
with freedombox (or its dependencies), this will fail the installation
rather than removing the freedombox package.

Closes #1790.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2020-03-07 10:46:34 -05:00
parent 9d6d3427da
commit 10c6ee13da
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -11,6 +11,7 @@ import os
import subprocess import subprocess
import sys import sys
from collections import defaultdict from collections import defaultdict
from contextlib import contextmanager
from importlib import import_module from importlib import import_module
import apt.cache import apt.cache
@ -54,6 +55,15 @@ def parse_arguments():
return parser.parse_args() return parser.parse_args()
@contextmanager
def _apt_hold():
"""Do not allow freedombox package to be removed during package install."""
try:
yield subprocess.run(['apt-mark', 'hold', 'freedombox'], check=True)
finally:
subprocess.run(['apt-mark', 'unhold', 'freedombox'], check=True)
def _run_apt_command(arguments): def _run_apt_command(arguments):
"""Run apt-get with provided arguments.""" """Run apt-get with provided arguments."""
# Ask apt-get to output its progress to file descriptor 3. # Ask apt-get to output its progress to file descriptor 3.
@ -71,12 +81,12 @@ def _run_apt_command(arguments):
process = subprocess.run(command, stdin=subprocess.DEVNULL, process = subprocess.run(command, stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL, close_fds=False, stdout=subprocess.DEVNULL, close_fds=False,
env=env) env=env)
sys.exit(process.returncode) return process.returncode
def subcommand_update(arguments): def subcommand_update(arguments):
"""Update apt package lists.""" """Update apt package lists."""
_run_apt_command(['update']) sys.exit(_run_apt_command(['update']))
def subcommand_install(arguments): def subcommand_install(arguments):
@ -99,7 +109,11 @@ def subcommand_install(arguments):
elif arguments.force_configuration == 'new': elif arguments.force_configuration == 'new':
extra_arguments += ['-o', 'Dpkg::Options::=--force-confnew'] extra_arguments += ['-o', 'Dpkg::Options::=--force-confnew']
_run_apt_command(['install'] + extra_arguments + arguments.packages) with _apt_hold():
returncode = _run_apt_command(['install'] + extra_arguments +
arguments.packages)
sys.exit(returncode)
def _assert_managed_packages(module, packages): def _assert_managed_packages(module, packages):