25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00
xmpp.chapril.org-ejabberd/docker/scripts/pre/01_write_certifiates_from_env.sh

34 lines
1.0 KiB
Bash
Raw Normal View History

2016-11-11 00:12:54 +01:00
#!/bin/bash
set -e
source "${EJABBERD_HOME}/scripts/lib/base_config.sh"
source "${EJABBERD_HOME}/scripts/lib/config.sh"
source "${EJABBERD_HOME}/scripts/lib/base_functions.sh"
source "${EJABBERD_HOME}/scripts/lib/functions.sh"
2016-11-11 00:12:54 +01:00
# Instead of having to mount a direction, specify the ssl certs
# via environment variables:
# `EJABBERD_SSLCERT_HOST` and `EJABBERD_SSLCERT_{domain_name}`.
# For example: `EJABBERD_SSLCERT_EXAMPLE_COM`.
write_file_from_env() {
echo "Writing $1 to $2"
2016-11-11 00:12:54 +01:00
mkdir -p "$(dirname $2)"
echo "${!1}" > $2
2016-11-11 00:12:54 +01:00
}
# Write the host certificate
is_set ${EJABBERD_SSLCERT_HOST} \
&& write_file_from_env "EJABBERD_SSLCERT_HOST" ${SSLCERTHOST}
# Write the domain certificates for each XMPP_DOMAIN
for xmpp_domain in ${XMPP_DOMAIN} ; do
var="EJABBERD_SSLCERT_$(echo $xmpp_domain | awk '{print toupper($0)}' | sed 's/\./_/g;s/-/_/g')"
if is_set ${!var} ; then
file_exist "${SSLCERTDIR}/${xmpp_domain}.pem" \
|| write_file_from_env "$var" "${SSLCERTDIR}/${xmpp_domain}.pem"
fi
done
exit 0