mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +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 argparse
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import augeas
|
||||||
|
|
||||||
from plinth import action_utils
|
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():
|
def parse_arguments():
|
||||||
@ -35,11 +38,31 @@ def parse_arguments():
|
|||||||
'set-default-app',
|
'set-default-app',
|
||||||
help='Set the default app for this FreedomBox instance.')
|
help='Set the default app for this FreedomBox instance.')
|
||||||
set_default_app.add_argument('app', help='name of the default app')
|
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
|
subparsers.required = True
|
||||||
return parser.parse_args()
|
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):
|
def subcommand_set_default_app(arguments):
|
||||||
"""Set the default app for this FreedomBox."""
|
"""Set the default app for this FreedomBox."""
|
||||||
conf_file_path = os.path.join('/etc/apache2/conf-available',
|
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.modules.names import SERVICES
|
||||||
from plinth.signals import domain_added
|
from plinth.signals import domain_added
|
||||||
|
|
||||||
version = 1
|
version = 2
|
||||||
|
|
||||||
is_essential = True
|
is_essential = True
|
||||||
|
|
||||||
@ -74,6 +74,8 @@ def get_default_app():
|
|||||||
if aug.get(match + "/arg[1]") == '''"^/$"''':
|
if aug.get(match + "/arg[1]") == '''"^/$"''':
|
||||||
app_path = aug.get(match + "/arg[2]")
|
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('/', '_')
|
return app_path.strip('/"').replace('/', '_')
|
||||||
|
|
||||||
|
|
||||||
@ -100,3 +102,22 @@ def init():
|
|||||||
name=domainname,
|
name=domainname,
|
||||||
description=ugettext_lazy('Domain Name'),
|
description=ugettext_lazy('Domain Name'),
|
||||||
services=domainname_services)
|
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