mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-08 09:41:35 +00:00
setup: Run first time setup with apt
Due to problems with running PackageKit inside foriegn binary Qemu, this is a fallback solution to use apt-get directly instead.
This commit is contained in:
parent
8340a813e5
commit
567fd590ab
@ -21,6 +21,7 @@ Framework for installing and updating distribution packages
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
from plinth.utils import import_from_gi
|
||||
glib = import_from_gi('GLib', '2.0')
|
||||
@ -166,3 +167,25 @@ class Transaction(object):
|
||||
else:
|
||||
logger.info('Unhandle packagekit progress callback - %s, %s',
|
||||
progress, progress_type)
|
||||
|
||||
|
||||
class AptTransaction(object):
|
||||
"""Install a package using Apt."""
|
||||
def __init__(self, package_names):
|
||||
"""Initialize transaction object."""
|
||||
self.package_names = package_names
|
||||
|
||||
def install(self):
|
||||
"""Run a PackageKit transaction to install given packages.
|
||||
|
||||
Plinth needs to be running as root when calling this.
|
||||
Currently, this is meant to be only during first time setup
|
||||
when --setup is argument is passed.
|
||||
"""
|
||||
try:
|
||||
subprocess.run(['apt-get', 'update'])
|
||||
subprocess.run(['apt-get', '-y', 'install'] + self.package_names,
|
||||
check=True)
|
||||
except subprocess.CalledProcessError as exception:
|
||||
logger.exception('Error installing package: %s', exception)
|
||||
raise
|
||||
|
||||
@ -27,6 +27,8 @@ import plinth
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
running_initial_setup = False
|
||||
|
||||
|
||||
class Helper(object):
|
||||
"""Helper routines for modules to show progress."""
|
||||
@ -91,6 +93,11 @@ class Helper(object):
|
||||
"""Install a set of packages marking progress."""
|
||||
logger.info('Running install for module - %s, packages - %s',
|
||||
self.module_name, package_names)
|
||||
if running_initial_setup:
|
||||
transaction = package.AptTransaction(package_names)
|
||||
transaction.install()
|
||||
return
|
||||
|
||||
transaction = package.Transaction(package_names)
|
||||
self.current_operation = {
|
||||
'step': 'install',
|
||||
@ -153,6 +160,8 @@ def init(module_name, module):
|
||||
def setup_all_modules(essential=False):
|
||||
"""Run setup on all essential modules and exit."""
|
||||
logger.info('Running setup for all modules, essential - %s', essential)
|
||||
global running_initial_setup
|
||||
running_initial_setup = True
|
||||
for module_name, module in plinth.module_loader.loaded_modules.items():
|
||||
if essential and not getattr(module, 'is_essential', False):
|
||||
continue
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user