mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
- Update link in copyright file to the logo. - Update paths to configuration file. Drop hack to load old configuration path. Migrate old configuration file to new path. - Use newer package name instead of transitional package name. - Use newer systemd unit name instead of aliased one. - Update backup/restore paths. - Drop code to handle configuration file update. This upgrade was done during Bookworm cycle. It is not needed for upgrade from Bookworm to Trixie. - Fix understanding of default values for keys not present in the configuration file. These values are picked up from source code as the documentation does not mention them. Tests: - Run unit and minetest functional tests. - After the app is freshly installed. Max users is 15. PvP is enabled. Create mode is disabled. Damaged is enabled. - Changes in configuration are reflected. - Play a game and make some changes. Update configuration. Backup. Uninstall and restore. The player data is restored. Configuration is restored. - Install without the changes. Make configuration changes. Apply changes and remove obsolete files. Restart service. App is updated. Notice that configuration file is migrated to new path. Configuration options are retained. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""Configure Minetest server."""
|
|
|
|
import pathlib
|
|
import shutil
|
|
|
|
import augeas
|
|
|
|
from plinth import action_utils
|
|
from plinth.actions import privileged
|
|
|
|
old_config_file = pathlib.Path('/etc/minetest/minetest.conf')
|
|
config_file = pathlib.Path('/etc/luanti/default.conf')
|
|
AUG_PATH = '/files' + str(config_file) + '/.anon'
|
|
|
|
|
|
@privileged
|
|
def setup() -> None:
|
|
"""Migrate old configuration file."""
|
|
if old_config_file.exists():
|
|
old_config_file.rename(config_file)
|
|
action_utils.service_daemon_reload()
|
|
action_utils.service_try_restart('luanti-server')
|
|
|
|
|
|
@privileged
|
|
def configure(max_players: int | None = None, enable_pvp: bool | None = None,
|
|
creative_mode: bool | None = None,
|
|
enable_damage: bool | None = None):
|
|
"""Update configuration file and restart daemon if necessary."""
|
|
config_file.parent.mkdir(exist_ok=True)
|
|
aug = load_augeas()
|
|
if max_players is not None:
|
|
aug.set(AUG_PATH + '/max_users', str(max_players))
|
|
|
|
if enable_pvp is not None:
|
|
aug.set(AUG_PATH + '/enable_pvp', str(enable_pvp).lower())
|
|
|
|
if creative_mode is not None:
|
|
aug.set(AUG_PATH + '/creative_mode', str(creative_mode).lower())
|
|
|
|
if enable_damage is not None:
|
|
aug.set(AUG_PATH + '/enable_damage', str(enable_damage).lower())
|
|
|
|
aug.save()
|
|
action_utils.service_try_restart('luanti-server')
|
|
|
|
|
|
def load_augeas():
|
|
"""Initialize Augeas."""
|
|
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
|
augeas.Augeas.NO_MODL_AUTOLOAD)
|
|
aug.set('/augeas/load/Php/lens', 'Php.lns')
|
|
aug.set('/augeas/load/Php/incl[last() + 1]', str(config_file))
|
|
aug.load()
|
|
return aug
|
|
|
|
|
|
@privileged
|
|
def uninstall() -> None:
|
|
"""Remove the data directory that luanti-server package fails to remove.
|
|
|
|
See: https://bugs.debian.org/1122677
|
|
"""
|
|
shutil.rmtree('/var/lib/private/luanti/default/')
|