From 0c6335b9dfa7498a53439d8165bf4318ce736ba8 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 12 Dec 2025 13:27:42 +0530 Subject: [PATCH] minetest: Remove legacy code, use new name, conf, etc. - 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 Reviewed-by: James Valleroy --- debian/copyright | 2 +- plinth/modules/minetest/__init__.py | 62 ++++++++----------- .../minetest-server.service.d/freedombox.conf | 4 -- plinth/modules/minetest/manifest.py | 6 +- plinth/modules/minetest/privileged.py | 30 +++++++-- 5 files changed, 56 insertions(+), 48 deletions(-) delete mode 100644 plinth/modules/minetest/data/usr/lib/systemd/system/minetest-server.service.d/freedombox.conf diff --git a/debian/copyright b/debian/copyright index 8e37e5817..7dcacf8da 100644 --- a/debian/copyright +++ b/debian/copyright @@ -183,7 +183,7 @@ License: CC-BY-SA-3.0 Files: plinth/modules/minetest/static/icons/minetest.svg Copyright: 2015 Calinou, Nils Dagsson Moskopp -Comment: https://github.com/minetest/minetest/blob/master/misc/minetest.svg +Comment: https://github.com/luanti-org/luanti/blob/master/misc/luanti.svg License: CC-BY-SA-3.0 Files: plinth/modules/miniflux/static/icons/miniflux.png diff --git a/plinth/modules/minetest/__init__.py b/plinth/modules/minetest/__init__.py index 4a5bb33a4..b287aa802 100644 --- a/plinth/modules/minetest/__init__.py +++ b/plinth/modules/minetest/__init__.py @@ -11,8 +11,8 @@ from plinth.daemon import Daemon from plinth.modules.backups.components import BackupRestore from plinth.modules.firewall.components import Firewall from plinth.modules.users.components import UsersAndGroups -from plinth.package import Package, Packages, install -from plinth.utils import Version, format_lazy +from plinth.package import Package, Packages +from plinth.utils import format_lazy from . import manifest, privileged @@ -38,7 +38,7 @@ _description = [ 'is needed.'), box_name=_(cfg.box_name)), ] -CONFIG_FILE = '/etc/minetest/minetest.conf' +CONFIG_FILE = '/etc/luanti/default.conf' AUG_PATH = '/files' + CONFIG_FILE + '/.anon' @@ -47,18 +47,18 @@ class MinetestApp(app_module.App): app_id = 'minetest' - _version = 2 + _version = 3 def __init__(self) -> None: """Create components for the app.""" super().__init__() - info = app_module.Info( - app_id=self.app_id, version=self._version, name=_('Luanti'), - icon_filename='minetest', description=_description, - manual_page='Minetest', clients=manifest.clients, - tags=manifest.tags, - donation_url='https://www.luanti.org/donate/') + info = app_module.Info(app_id=self.app_id, version=self._version, + name=_('Luanti'), icon_filename='minetest', + description=_description, + manual_page='Minetest', + clients=manifest.clients, tags=manifest.tags, + donation_url='https://www.luanti.org/donate/') self.add(info) menu_item = menu.Menu('menu-minetest', info.name, info.icon_filename, @@ -73,14 +73,14 @@ class MinetestApp(app_module.App): tags=info.tags, login_required=False) self.add(shortcut) - packages = Packages('packages-minetest', ['minetest-server'] + _mods) + packages = Packages('packages-minetest', ['luanti-server'] + _mods) self.add(packages) firewall = Firewall('firewall-minetest', info.name, ports=['minetest-plinth'], is_external=True) self.add(firewall) - daemon = Daemon('daemon-minetest', 'minetest-server', + daemon = Daemon('daemon-minetest', 'luanti-server', listen_ports=[(30000, 'udp4')]) self.add(daemon) @@ -93,27 +93,17 @@ class MinetestApp(app_module.App): **manifest.backup) self.add(backup_restore) - def setup(self, old_version): + def setup(self, old_version) -> None: """Install and configure the app.""" super().setup(old_version) + privileged.setup() if not old_version: self.enable() - def force_upgrade(self, packages): - """Force upgrade minetest to resolve conffile prompt.""" - if 'minetest-server' not in packages: - return False - - # Allow upgrade from 5.3.0 to 5.6.1 - package = packages['minetest-server'] - if Version(package['new_version']) > Version('5.7~'): - return False - - config = get_configuration() - install(['minetest-server'], force_configuration='new') - privileged.configure(**config) - - return True + def uninstall(self) -> None: + """Uninstall the app.""" + super().uninstall() + privileged.uninstall() def load_augeas(): @@ -126,32 +116,34 @@ def load_augeas(): return aug -def get_max_players(aug): +def get_max_players(aug) -> int: """Return the maximum players allowed on the server at one time.""" value = aug.get(AUG_PATH + '/max_users') if value: return int(value) + return 15 # Default value -def is_creative_mode_enabled(aug): + +def is_creative_mode_enabled(aug) -> bool: """Return whether creative mode is enabled.""" value = aug.get(AUG_PATH + '/creative_mode') return value == 'true' -def is_pvp_enabled(aug): +def is_pvp_enabled(aug) -> bool: """Return whether PVP is enabled.""" value = aug.get(AUG_PATH + '/enable_pvp') - return value == 'true' + return value != 'false' -def is_damage_enabled(aug): +def is_damage_enabled(aug) -> bool: """Return whether damage is enabled.""" value = aug.get(AUG_PATH + '/enable_damage') - return value == 'true' + return value != 'false' -def get_configuration(): +def get_configuration() -> dict[str, int | bool]: """Return the current configuration.""" aug = load_augeas() conf = { diff --git a/plinth/modules/minetest/data/usr/lib/systemd/system/minetest-server.service.d/freedombox.conf b/plinth/modules/minetest/data/usr/lib/systemd/system/minetest-server.service.d/freedombox.conf deleted file mode 100644 index 6a3d7483a..000000000 --- a/plinth/modules/minetest/data/usr/lib/systemd/system/minetest-server.service.d/freedombox.conf +++ /dev/null @@ -1,4 +0,0 @@ -# Workaround for Debian bug #1090067 -[Service] -ExecStart= -ExecStart=/usr/bin/sh -c 'if [ -e /etc/minetest/minetest.conf ] ; then CONFIG_FILE=/etc/minetest/minetest.conf; else CONFIG_FILE=/etc/luanti/default.conf; fi; if [ -x /usr/lib/minetest/minetestserver ] ; then /usr/lib/minetest/minetestserver --config $$CONFIG_FILE --logfile /var/log/minetest/minetest.log --gameid minetest_game; else exec /usr/libexec/luanti/luantiserver --config $$CONFIG_FILE --logfile /var/log/luanti/default/server.log --gameid $LUANTI_GAMEID; fi' diff --git a/plinth/modules/minetest/manifest.py b/plinth/modules/minetest/manifest.py index 27c65380d..737a7bc75 100644 --- a/plinth/modules/minetest/manifest.py +++ b/plinth/modules/minetest/manifest.py @@ -38,12 +38,12 @@ clients = [{ backup = { 'config': { - 'files': ['/etc/minetest/minetest.conf'] + 'files': ['/etc/luanti/default.conf'] }, 'data': { - 'directories': ['/var/games/minetest-server/'] + 'directories': ['/var/lib/private/luanti/default/'] }, - 'services': ['minetest-server'] + 'services': ['luanti-server'] } tags = [_('Game server'), _('Block sandbox'), _('Platform')] diff --git a/plinth/modules/minetest/privileged.py b/plinth/modules/minetest/privileged.py index 3bfbd3e40..17745f4d1 100644 --- a/plinth/modules/minetest/privileged.py +++ b/plinth/modules/minetest/privileged.py @@ -2,14 +2,25 @@ """Configure Minetest server.""" import pathlib +import shutil import augeas from plinth import action_utils from plinth.actions import privileged -CONFIG_FILE = '/etc/minetest/minetest.conf' -AUG_PATH = '/files' + CONFIG_FILE + '/.anon' +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 @@ -17,7 +28,7 @@ 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.""" - pathlib.Path(CONFIG_FILE).parent.mkdir(exist_ok=True) + 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)) @@ -32,7 +43,7 @@ def configure(max_players: int | None = None, enable_pvp: bool | None = None, aug.set(AUG_PATH + '/enable_damage', str(enable_damage).lower()) aug.save() - action_utils.service_try_restart('minetest-server') + action_utils.service_try_restart('luanti-server') def load_augeas(): @@ -40,6 +51,15 @@ def load_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]', CONFIG_FILE) + 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/')