mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
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 <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
ebdbd8cd69
commit
0c6335b9df
2
debian/copyright
vendored
2
debian/copyright
vendored
@ -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
|
||||
|
||||
@ -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 = {
|
||||
|
||||
@ -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'
|
||||
@ -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')]
|
||||
|
||||
@ -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/')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user