#!/bin/sh

# Volumes
DATAPUSHER_CONF="${VOLUMES_DIR}/ckan/datapusher_conf"
CKAN_CONF="${VOLUMES_DIR}/ckan/ckan_conf"

# Variables
HTTP_HOST="${HOST}"
[ "${PORT}" != "443" ] && HTTP_HOST="${HTTP_HOST}:${PORT}"

# Replacements
sed -i "s|\(^ckan\.site_url = \).*|\1https://${HTTP_HOST}|" ${CKAN_CONF}/ckan.ini
sed -i "s|\(^smtp\.mail_from = \).*|\1${EMAIL}|" ${CKAN_CONF}/ckan.ini
sed -i "s|\(^ckanext\.geoview\.gapi_key = \).*|\1${GMAPS_API_KEY}|" ${CKAN_CONF}/ckan.ini

cat <<EOF >${DATAPUSHER_CONF}/add-ca-cert.env
HOST=${HOST}
PORT=${PORT}
EOF
sed -i "s|\(^FROM_EMAIL = \).*|\1'${EMAIL}'|" ${DATAPUSHER_CONF}/datapusher_settings.py
