# SPDX-FileCopyrightText: 2016-2017 Helmut Pozimski # # SPDX-License-Identifier: GPL-2.0-only # -*- coding: utf8 -*- """ Main function of acme-updater, parses command line arguments, sets up logging and executes the modules. """ import argparse import logging import json import sys from amulib.helpers import get_log_level from amulib import apache from amulib import postfix from amulib import dovecot from amulib import ejabberd def main(): """ Main function of acme-updater. """ config = None parser = argparse.ArgumentParser() parser.add_argument("--apache", help="use the apache module", action="store_true") parser.add_argument("--postfix", help="use the postfix module", action="store_true") parser.add_argument("--dovecot", help="use the dovecot module", action="store_true") parser.add_argument("--ejabberd", help="use the ejabberd module", action="store_true") parser.add_argument("--verbose", "-V", help="be verbose, enables debug " "output", action="store_true") parser.add_argument("--config", "-C", help="path to the configuration " "file", type=str) args = parser.parse_args() logger = logging.getLogger("acme-updater") logger.addHandler(logging.StreamHandler()) if args.config: try: with open(args.config, "r") as fobj: config = json.load(fobj) except IOError: logger.error("Error: Could not open configuration file") sys.exit(1) except json.JSONDecodeError: logger.error("Error: Could not parse configuration file") sys.exit(1) if args.verbose: logger.setLevel(logging.DEBUG) elif config: logger.setLevel(get_log_level(config["loglevel"])) else: logger.setLevel(logging.INFO) if args.apache: if config: apache.run(config["apache"], config["acme_dir"], config["named_key_path"], config["dns_server"]) else: apache.run() if args.postfix: if config: postfix.run(config["postfix"], config["acme_dir"], config["named_key_path"], config["dns_server"]) else: postfix.run() if args.dovecot: if config: dovecot.run(config["dovecot"], config["acme_dir"], config["named_key_path"], config["dns_server"]) else: dovecot.run() if args.ejabberd: if config: ejabberd.run(config["ejabberd"], config["acme_dir"], config["named_key_path"], config["dns_server"]) else: ejabberd.run()