config: Drop legacy migration of Apache homepage settings

- Initial implementation of home page setting used the file
/etc/apache2/conf-available/freedombox.conf and edited the file. Since this file
is shipped by the freedombox package, it lead to package getting stuck with
conf-file prompt. FreedomBox v19.10 first fix this by carefully undoing the
edits in this file and making them elsewhere.

- This fix is present in Debian present old stable (with backports) and current
stable, the migration is not needed in almost all the of cases.

Tests:

- First setup of FreedomBox works.

- Setting home page works are expected.

- Functional tests for config module works.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2022-09-19 11:30:06 -07:00 committed by James Valleroy
parent 158366feea
commit e3a67da8ec
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 3 additions and 44 deletions

View File

@ -76,7 +76,6 @@ class ConfigApp(app_module.App):
def setup(self, old_version):
"""Install and configure the app."""
super().setup(old_version)
_migrate_home_page_config()
if old_version <= 3:
privileged.set_logging_mode('volatile')
@ -148,8 +147,9 @@ def _home_page_scid2url(shortcut_id):
return url
def _get_home_page_url(conf_file):
def _get_home_page_url():
"""Get the default application for the domain."""
conf_file = privileged.APACHE_HOMEPAGE_CONFIG
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
augeas.Augeas.NO_MODL_AUTOLOAD)
aug.set('/augeas/load/Httpd/lens', 'Httpd.lns')
@ -168,11 +168,7 @@ def _get_home_page_url(conf_file):
def get_home_page():
"""Return the shortcut ID that is set as current home page."""
CONF_FILE = privileged.APACHE_HOMEPAGE_CONFIG if os.path.exists(
privileged.APACHE_HOMEPAGE_CONFIG
) else privileged.FREEDOMBOX_APACHE_CONFIG
url = _get_home_page_url(CONF_FILE)
url = _get_home_page_url()
return home_page_url2scid(url)
@ -196,16 +192,3 @@ def set_advanced_mode(advanced_mode):
"""Turn on/off advanced mode."""
from plinth import kvstore
kvstore.set(ADVANCED_MODE_KEY, advanced_mode)
def _migrate_home_page_config():
"""Move the home page configuration to an external file."""
# Hold the current home page in a variable
home_page = get_home_page()
# Reset the home page to plinth in freedombox.conf
privileged.reset_home_page()
# Write the home page setting into the new conf file
# This step is run at the end because it reloads the Apache server
change_home_page(home_page)

View File

@ -15,8 +15,6 @@ APACHE_CONF_ENABLED_DIR = '/etc/apache2/conf-enabled'
APACHE_HOMEPAGE_CONF_FILE_NAME = 'freedombox-apache-homepage.conf'
APACHE_HOMEPAGE_CONFIG = os.path.join(APACHE_CONF_ENABLED_DIR,
APACHE_HOMEPAGE_CONF_FILE_NAME)
FREEDOMBOX_APACHE_CONFIG = os.path.join(APACHE_CONF_ENABLED_DIR,
'freedombox.conf')
JOURNALD_FILE = pathlib.Path('/etc/systemd/journald.conf.d/50-freedombox.conf')
@ -115,25 +113,3 @@ def set_home_page(homepage: str):
conf_file.write(redirect_rule)
action_utils.webserver_enable('freedombox-apache-homepage')
@privileged
def reset_home_page():
"""Set the Apache web server's home page to the default - /plinth."""
config_file = FREEDOMBOX_APACHE_CONFIG
default_path = 'plinth'
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]', config_file)
aug.load()
aug.defvar('conf', '/files' + config_file)
for match in aug.match('/files' + config_file +
'/directive["RedirectMatch"]'):
if aug.get(match + "/arg[1]") == '''"^/$"''':
aug.set(match + "/arg[2]", '"/{}"'.format(default_path))
aug.save()