apt: Run apt-get -f install before other commands

Run `apt-get --fix-broken install` before installing package or manual
update. This will attempt to correct broken dependencies.

Tests:
- Install a package without its dependencies using `dpkg -i`.
- Both app install and manual update successfully recover from this
  situation.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy authored and Sunil Mohan Adapa committed 2020-06-25 11:54:45 -07:00
1 parent bf53fd8b17
commit 5424e1e23f
3 files changed
+28 -23

No files matched your search

+21
View File
@@ -197,6 +197,7 @@ def webserver_disable(name, kind='config', apply_changes=True):
class WebserverChange(object):
"""Context to restart/reload Apache after configuration changes."""
def __init__(self):
"""Initialize the context object state."""
self.actions_required = set()
@@ -388,3 +389,23 @@ def is_disk_image():
- Installing packages on a Debian machine using apt.
"""
return os.path.exists('/var/lib/freedombox/is-freedombox-disk-image')
def run_apt_command(arguments):
"""Run apt-get with provided arguments."""
# Ask apt-get to output its progress to file descriptor 3.
command = [
'apt-get', '--assume-yes', '--quiet=2', '--option', 'APT::Status-Fd=3'
] + arguments
# Duplicate stdout to file descriptor 3 for this process.
os.dup2(1, 3)
# Pass on file descriptor 3 instead of closing it. Close stdout
# so that regular output is ignored.
env = os.environ.copy()
env['DEBIAN_FRONTEND'] = 'noninteractive'
process = subprocess.run(command, stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL, close_fds=False,
env=env)
return process.returncode