From 9aa48091dfc850deddf83357026ad35132569dfa Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Sat, 2 Feb 2019 22:34:30 -0500 Subject: [PATCH] radicale: Handle data migration for upgrade to 2.x Signed-off-by: James Valleroy Reviewed-by: Sunil Mohan Adapa --- actions/radicale | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/actions/radicale b/actions/radicale index a7d01f3ec..6b4c4a7bd 100755 --- a/actions/radicale +++ b/actions/radicale @@ -21,12 +21,17 @@ Configuration helper for Radicale. import argparse import os +import shutil +import subprocess +import tempfile import augeas from plinth import action_utils from plinth.modules import radicale +COLLECTIONS_PATH = '/var/lib/radicale/collections' + CONFIG_FILE = '/etc/radicale/config' DEFAULT_FILE = '/etc/default/radicale' @@ -76,7 +81,22 @@ def subcommand_setup(_): def subcommand_migrate(_): - """Migrate config from radicale 1.x to 2.x.""" + """Migrate from radicale 1.x to 2.x.""" + current_version = radicale.get_package_version() + + # Migrate data from radicale 1.x to radicale 2.x format. + if current_version and current_version < radicale.VERSION_2: + with tempfile.TemporaryDirectory() as temp_directory: + export_location = os.path.join(temp_directory, 'radicale-export') + subprocess.run(['radicale', '--export-storage', export_location], + check=True) + collection_root = os.path.join(export_location, 'collection-root') + shutil.copytree(collection_root, + os.path.join(COLLECTIONS_PATH, 'collection-root')) + subprocess.run( + ['chown', '-R', 'radicale:radicale', COLLECTIONS_PATH], + check=True) + action_utils.webserver_disable('radicale-plinth') aug = load_augeas() @@ -88,7 +108,6 @@ def subcommand_migrate(_): 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') @@ -120,8 +139,8 @@ def subcommand_enable(_): """Start service.""" if radicale.get_package_version() >= radicale.VERSION_2: # Workaround for bug in radicale's uwsgi script (#919339) - if not os.path.exists('/var/lib/radicale/collections'): - os.makedirs('/var/lib/radicale/collections') + if not os.path.exists(COLLECTIONS_PATH): + os.makedirs(COLLECTIONS_PATH) action_utils.service_disable('radicale') action_utils.uwsgi_enable('radicale') action_utils.webserver_enable('proxy_uwsgi', kind='module')