mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
radicale: Handle migration from 1.x to 2.x
When radicale 2.x is available in testing, the migration can be triggered by bumping the module's version. Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
62b4f67a2e
commit
3941ec10fe
@ -38,6 +38,7 @@ def parse_arguments():
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
subparsers.add_parser('setup', help='Setup Radicale configuration')
|
||||
subparsers.add_parser('migrate', help='Migrate config to radicale 2.x')
|
||||
subparsers.add_parser('enable', help='Enable Radicale service')
|
||||
subparsers.add_parser('disable', help='Disable Radicale service')
|
||||
configure = subparsers.add_parser('configure',
|
||||
@ -74,6 +75,26 @@ def subcommand_setup(_):
|
||||
subcommand_enable(None)
|
||||
|
||||
|
||||
def subcommand_migrate(_):
|
||||
"""Migrate config from radicale 1.x to 2.x."""
|
||||
action_utils.webserver_disable('radicale-plinth')
|
||||
|
||||
aug = load_augeas()
|
||||
|
||||
# Revert the config to package's original.
|
||||
aug.remove('/files' + DEFAULT_FILE + '/ENABLE_RADICALE')
|
||||
aug.remove('/files' + CONFIG_FILE + '/server/hosts')
|
||||
aug.remove('/files' + CONFIG_FILE + '/server/base_prefix')
|
||||
aug.remove('/files' + CONFIG_FILE + '/well-known/caldav')
|
||||
aug.remove('/files' + CONFIG_FILE + '/well-known/carddav')
|
||||
aug.remove('/files' + CONFIG_FILE + '/auth/type')
|
||||
current_version = radicale.get_package_version()
|
||||
if current_version and current_version < radicale.VERSION_2:
|
||||
aug.remove('/files' + CONFIG_FILE + '/rights/type')
|
||||
|
||||
aug.save()
|
||||
|
||||
|
||||
def subcommand_configure(arguments):
|
||||
"""Sets the radicale rights type to a particular value"""
|
||||
current_version = radicale.get_package_version()
|
||||
@ -122,8 +143,8 @@ def subcommand_disable(_):
|
||||
|
||||
def load_augeas():
|
||||
"""Initialize Augeas."""
|
||||
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
||||
augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||
aug = augeas.Augeas(
|
||||
flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||
|
||||
# shell-script config file lens
|
||||
aug.set('/augeas/load/Shellvars/lens', 'Shellvars.lns')
|
||||
|
||||
@ -21,6 +21,7 @@ FreedomBox app for radicale.
|
||||
import subprocess
|
||||
from distutils.version import LooseVersion as LV
|
||||
|
||||
from apt.cache import Cache
|
||||
import augeas
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
@ -84,8 +85,31 @@ def init():
|
||||
|
||||
def setup(helper, old_version=None):
|
||||
"""Install and configure the module."""
|
||||
helper.install(managed_packages)
|
||||
helper.call('post', actions.superuser_run, 'radicale', ['setup'])
|
||||
if old_version == 1:
|
||||
# Check that radicale 2.x is available for install.
|
||||
cache = Cache()
|
||||
candidate = cache['radicale'].candidate
|
||||
if candidate < '2':
|
||||
raise RuntimeError('Radicale 2.x is not available to install.')
|
||||
|
||||
# Try to upgrade radicale 1.x to 2.x.
|
||||
helper.call('pre', actions.superuser_run, 'radicale', ['migrate'])
|
||||
helper.install(managed_packages)
|
||||
|
||||
# Check that radicale 2.x is installed.
|
||||
current_version = get_package_version()
|
||||
if not current_version:
|
||||
raise RuntimeError(
|
||||
'Could not determine installed version of radicale.')
|
||||
elif current_version < VERSION_2:
|
||||
raise RuntimeError('Could not install radicale 2.x.')
|
||||
|
||||
# Enable radicale.
|
||||
helper.call('post', actions.superuser_run, 'radicale', ['setup'])
|
||||
else:
|
||||
helper.install(managed_packages)
|
||||
helper.call('post', actions.superuser_run, 'radicale', ['setup'])
|
||||
|
||||
global service
|
||||
if service is None:
|
||||
service = service_module.Service(managed_services[0], name, ports=[
|
||||
@ -162,8 +186,8 @@ def disable():
|
||||
|
||||
def load_augeas():
|
||||
"""Prepares the augeas."""
|
||||
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
||||
augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||
aug = augeas.Augeas(
|
||||
flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||
|
||||
# INI file lens
|
||||
aug.set('/augeas/load/Puppet/lens', 'Puppet.lns')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user