2019-06-28 04:19:09 -04:00
|
|
|
#!/usr/bin/env python3
|
2018-12-21 10:04:57 -05:00
|
|
|
|
|
|
|
import argparse
|
2019-03-04 12:14:58 -05:00
|
|
|
import shutil
|
2018-12-21 10:04:57 -05:00
|
|
|
import sys
|
|
|
|
|
|
|
|
from synapse.config.homeserver import HomeServerConfig
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
"--config-dir",
|
|
|
|
default="CONFDIR",
|
|
|
|
help="The path where the config files are kept. Used to create filenames for "
|
2021-05-14 06:46:35 -04:00
|
|
|
"things like the log config and the signing key. Default: %(default)s",
|
2018-12-21 10:04:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--data-dir",
|
|
|
|
default="DATADIR",
|
|
|
|
help="The path where the data files are kept. Used to create filenames for "
|
2021-05-14 06:46:35 -04:00
|
|
|
"things like the database and media store. Default: %(default)s",
|
2018-12-21 10:04:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--server-name",
|
|
|
|
default="SERVERNAME",
|
|
|
|
help="The server name. Used to initialise the server_name config param, but also "
|
2021-05-14 06:46:35 -04:00
|
|
|
"used in the names of some of the config files. Default: %(default)s",
|
2018-12-21 10:04:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--report-stats",
|
|
|
|
action="store",
|
|
|
|
help="Whether the generated config reports anonymized usage statistics",
|
|
|
|
choices=["yes", "no"],
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--generate-secrets",
|
|
|
|
action="store_true",
|
|
|
|
help="Enable generation of new secrets for things like the macaroon_secret_key."
|
2021-05-14 06:46:35 -04:00
|
|
|
"By default, these parameters will be left unset.",
|
2018-12-21 10:04:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
2021-05-14 06:46:35 -04:00
|
|
|
"-o",
|
|
|
|
"--output-file",
|
|
|
|
type=argparse.FileType("w"),
|
2018-12-21 10:04:57 -05:00
|
|
|
default=sys.stdout,
|
|
|
|
help="File to write the configuration to. Default: stdout",
|
|
|
|
)
|
|
|
|
|
2019-03-04 12:14:58 -05:00
|
|
|
parser.add_argument(
|
|
|
|
"--header-file",
|
2021-05-14 06:46:35 -04:00
|
|
|
type=argparse.FileType("r"),
|
2019-03-04 12:14:58 -05:00
|
|
|
help="File from which to read a header, which will be printed before the "
|
2021-05-14 06:46:35 -04:00
|
|
|
"generated config.",
|
2019-03-04 12:14:58 -05:00
|
|
|
)
|
|
|
|
|
2018-12-21 10:04:57 -05:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
report_stats = args.report_stats
|
|
|
|
if report_stats is not None:
|
|
|
|
report_stats = report_stats == "yes"
|
|
|
|
|
|
|
|
conf = HomeServerConfig().generate_config(
|
|
|
|
config_dir_path=args.config_dir,
|
|
|
|
data_dir_path=args.data_dir,
|
|
|
|
server_name=args.server_name,
|
|
|
|
generate_secrets=args.generate_secrets,
|
|
|
|
report_stats=report_stats,
|
|
|
|
)
|
|
|
|
|
2019-03-04 12:14:58 -05:00
|
|
|
if args.header_file:
|
|
|
|
shutil.copyfileobj(args.header_file, args.output_file)
|
|
|
|
|
2018-12-21 10:04:57 -05:00
|
|
|
args.output_file.write(conf)
|