From a7b854f7ce01a150a43ab0de911b071c613c5372 Mon Sep 17 00:00:00 2001 From: andryyy Date: Wed, 17 May 2017 21:16:48 +0200 Subject: [PATCH] Fix Dockerfile, again --- data/Dockerfiles/php-fpm/docker-entrypoint.sh | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/data/Dockerfiles/php-fpm/docker-entrypoint.sh b/data/Dockerfiles/php-fpm/docker-entrypoint.sh index 5e88a89d..9df1dbeb 100755 --- a/data/Dockerfiles/php-fpm/docker-entrypoint.sh +++ b/data/Dockerfiles/php-fpm/docker-entrypoint.sh @@ -51,10 +51,35 @@ for file in $(ls /data/dkim/keys/); do domain=${file%.dkim} if [[ -f /data/dkim/txt/${file} ]]; then redis-cli -h redis-mailcow HSET DKIM_PUB_KEYS "${domain}" "$(cat /data/dkim/txt/${file})" - redis-cli -h redis-mailcow HSET DKIM_PRIV_KEYS "${domain}" "$(cat /data/dkim/keys/${file})" + redis-cli -h redis-mailcow HSET DKIM_PRIV_KEYS "dkim.${domain}" "$(cat /data/dkim/keys/${file})" redis-cli -h redis-mailcow HSET DKIM_SELECTORS "${domain}" "dkim" fi rm /data/dkim/{keys,txt}/${file} done +# Fix DKIM keys + +# Fetch domains +declare -a DOMAIN_ARRAY +while read line +do + DOMAIN_ARRAY+=("$line") +done < <(mysql -h mysql-mailcow -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "SELECT domain FROM domain" -Bs) +while read line +do + DOMAIN_ARRAY+=("$line") +done < <(mysql -h mysql-mailcow -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "SELECT alias_domain FROM alias_domain" -Bs) + +# Loop through array and fix keys +if [[ ! -z ${DOMAIN_ARRAY} ]]; then + for domain in "${DOMAIN_ARRAY[@]}"; do + WRONG_KEY=$(redis-cli -h redis-mailcow HGET DKIM_PRIV_KEYS ${domain} | tr -d \") + if [[ ! -z ${WRONG_KEY} ]]; then + echo "Migrating defect key for domain ${domain}" + redis-cli -h redis-mailcow HSET DKIM_PRIV_KEYS "dkim.${domain}" ${WRONG_KEY} + redis-cli -h redis-mailcow HDEL DKIM_PRIV_KEYS "${domain}" + fi + done +fi + exec "$@"