#!/usr/bin/python3 # SPDX-License-Identifier: AGPL-3.0-or-later """ Configuration helper for Roundcube server. """ import argparse import json import pathlib import re from plinth import action_utils _config_file = pathlib.Path('/etc/roundcube/freedombox-config.php') def parse_arguments(): """Return parsed command line arguments as dictionary.""" parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='subcommand', help='Sub command') subparsers.add_parser('pre-install', help='Perform Roundcube pre-install configuration') subparsers.add_parser('setup', help='Setup basic configuration') subparsers.add_parser('get-config', help='Print current configuration') subparser = subparsers.add_parser('set-config', help='Set configuration') subparser.add_argument('--local-only', choices=['True', 'False'], help='Set current configuration') subparsers.required = True return parser.parse_args() def subcommand_pre_install(_): """Preseed debconf values before packages are installed.""" action_utils.debconf_set_selections([ 'roundcube-core roundcube/dbconfig-install boolean true', 'roundcube-core roundcube/database-type string sqlite3' ]) def subcommand_setup(_): """Add FreedomBox configuration and include from main configuration.""" if not _config_file.exists(): _config_file.write_text('