mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-02-04 08:13:38 +00:00
config: Migrate default app configuration to new conf file
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
209d8e7b3a
commit
a87b0ff596
@ -23,8 +23,11 @@ Configuration helper for FreedomBox general configuration.
|
||||
import argparse
|
||||
import os
|
||||
|
||||
import augeas
|
||||
|
||||
from plinth import action_utils
|
||||
from plinth.modules.config import DEFAULT_APP_CONF_FILE_NAME
|
||||
from plinth.modules.config import (DEFAULT_APP_CONF_FILE_NAME,
|
||||
FREEDOMBOX_APACHE_CONFIG)
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
@ -35,11 +38,31 @@ def parse_arguments():
|
||||
'set-default-app',
|
||||
help='Set the default app for this FreedomBox instance.')
|
||||
set_default_app.add_argument('app', help='name of the default app')
|
||||
subparsers.add_parser(
|
||||
'reset-default-app',
|
||||
help='Reset the default app configuraton in freedombox.conf')
|
||||
|
||||
subparsers.required = True
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_reset_default_app(_):
|
||||
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
||||
augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||
aug.set('/augeas/load/Httpd/lens', 'Httpd.lns')
|
||||
aug.set('/augeas/load/Httpd/incl[last() + 1]', FREEDOMBOX_APACHE_CONFIG)
|
||||
aug.load()
|
||||
|
||||
aug.defvar('conf', '/files' + FREEDOMBOX_APACHE_CONFIG)
|
||||
|
||||
for match in aug.match('/files' + FREEDOMBOX_APACHE_CONFIG +
|
||||
'/directive["RedirectMatch"]'):
|
||||
if aug.get(match + "/arg[1]") == '''"^/$"''':
|
||||
aug.set(match + "/arg[2]", '"/{}"'.format('plinth'))
|
||||
|
||||
aug.save()
|
||||
|
||||
|
||||
def subcommand_set_default_app(arguments):
|
||||
"""Set the default app for this FreedomBox."""
|
||||
conf_file_path = os.path.join('/etc/apache2/conf-available',
|
||||
|
||||
@ -30,7 +30,7 @@ from plinth.modules import firewall
|
||||
from plinth.modules.names import SERVICES
|
||||
from plinth.signals import domain_added
|
||||
|
||||
version = 1
|
||||
version = 2
|
||||
|
||||
is_essential = True
|
||||
|
||||
@ -74,6 +74,8 @@ def get_default_app():
|
||||
if aug.get(match + "/arg[1]") == '''"^/$"''':
|
||||
app_path = aug.get(match + "/arg[2]")
|
||||
|
||||
# match this against the app_id in the entries of frontpage.get_shortcuts()
|
||||
# The underscore is to handle Ikiwiki app_ids
|
||||
return app_path.strip('/"').replace('/', '_')
|
||||
|
||||
|
||||
@ -100,3 +102,22 @@ def init():
|
||||
name=domainname,
|
||||
description=ugettext_lazy('Domain Name'),
|
||||
services=domainname_services)
|
||||
|
||||
|
||||
def setup(helper, old_version=None):
|
||||
"""Install and configure the module."""
|
||||
_migrate_default_app_config()
|
||||
|
||||
|
||||
def _migrate_default_app_config():
|
||||
"""Move the default app configuration to an external file."""
|
||||
|
||||
# Hold the current default app in a variable
|
||||
default_app_path = get_default_app().replace('_', '/')
|
||||
|
||||
# Reset the default app to plinth in freedombox.conf
|
||||
actions.superuser_run('config', ['reset-default-app'])
|
||||
|
||||
# Write the default app setting into the new conf file
|
||||
# This step is run at the end because it reloads the Apache server
|
||||
actions.superuser_run('config', ['set-default-app', default_app_path])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user