#!/bin/sh
set -eux

# We wrap the default entrypoint script and generate the configuration file and
# other secret files from environment variables, but only if we're running the
# homeserver.
if [ "$#" -eq 0 ] || [ "$1" = run ]
then
    if [ -n "${SIGNING_KEY:-}" ]
    then
        echo "$SIGNING_KEY" > "/conf/${SYNAPSE_SERVER_NAME}.signing.key"
        chmod 644 "/conf/${SYNAPSE_SERVER_NAME}.signing.key"
    fi
    /start.py migrate_config
    cat /conf/homeserver.yaml
    python3 -m synapse.config -c /conf/homeserver.yaml
fi

exec /start.py "$@"