diff --git a/actions/radicale b/actions/radicale index 09487d802..a7d01f3ec 100755 --- a/actions/radicale +++ b/actions/radicale @@ -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') diff --git a/plinth/modules/radicale/__init__.py b/plinth/modules/radicale/__init__.py index 4f10fbf6b..c5f267507 100644 --- a/plinth/modules/radicale/__init__.py +++ b/plinth/modules/radicale/__init__.py @@ -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')