2017-03-02 18:23:23 +08:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2018-06-08 15:11:03 +08:00
|
|
|
function array_by_comma { local IFS=","; echo "$*"; }
|
2017-03-02 18:23:23 +08:00
|
|
|
|
2017-05-08 21:35:24 +08:00
|
|
|
# Wait for containers
|
2018-10-11 17:53:22 +08:00
|
|
|
while ! mysqladmin status --socket=/var/run/mysqld/mysqld.sock -u${DBUSER} -p${DBPASS} --silent; do
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-30 04:01:23 +08:00
|
|
|
echo "Waiting for SQL..."
|
2017-05-08 21:35:24 +08:00
|
|
|
sleep 2
|
|
|
|
done
|
|
|
|
|
2018-07-04 17:41:43 +08:00
|
|
|
until [[ $(redis-cli -h redis-mailcow PING) == "PONG" ]]; do
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-30 04:01:23 +08:00
|
|
|
echo "Waiting for Redis..."
|
2017-05-08 21:35:24 +08:00
|
|
|
sleep 2
|
|
|
|
done
|
|
|
|
|
2018-12-10 20:22:25 +08:00
|
|
|
# Set a default release format
|
|
|
|
|
2018-12-06 23:49:14 +08:00
|
|
|
if [[ -z $(redis-cli --raw -h redis-mailcow GET Q_RELEASE_FORMAT) ]]; then
|
|
|
|
redis-cli --raw -h redis-mailcow SET Q_RELEASE_FORMAT raw
|
|
|
|
fi
|
|
|
|
|
2018-12-10 20:22:25 +08:00
|
|
|
# Check of mysql_upgrade
|
|
|
|
|
|
|
|
CONTAINER_ID=
|
|
|
|
CONTAINER_ID=$(curl --silent --insecure https://dockerapi/containers/json | jq -r ".[] | {name: .Config.Labels[\"com.docker.compose.service\"], id: .Id}" | jq -rc "select( .name | tostring | contains(\"mysql-mailcow\")) | .id")
|
|
|
|
if [[ ! -z ${CONTAINER_ID} ]]; then
|
|
|
|
SQL_UPGRADE_RETURN=$(curl --silent --insecure -XPOST https://dockerapi/containers/${CONTAINER_ID}/exec -d '{"cmd":"system", "task":"mysql_upgrade"}' --silent -H 'Content-type: application/json' | jq -r .type)
|
|
|
|
if [[ ${SQL_UPGRADE_RETURN} == 'warning' ]]; then
|
|
|
|
echo "MySQL applied an upgrade, restarting PHP-FPM..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-10-11 17:53:22 +08:00
|
|
|
# Trigger db init
|
|
|
|
echo "Running DB init..."
|
|
|
|
php -c /usr/local/etc/php -f /web/inc/init_db.inc.php
|
|
|
|
|
2017-05-08 21:35:24 +08:00
|
|
|
# Migrate domain map
|
|
|
|
declare -a DOMAIN_ARR
|
|
|
|
redis-cli -h redis-mailcow DEL DOMAIN_MAP
|
|
|
|
while read line
|
|
|
|
do
|
|
|
|
DOMAIN_ARR+=("$line")
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-30 04:01:23 +08:00
|
|
|
done < <(mysql --socket=/var/run/mysqld/mysqld.sock -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "SELECT domain FROM domain" -Bs)
|
2018-01-17 22:23:33 +08:00
|
|
|
while read line
|
|
|
|
do
|
|
|
|
DOMAIN_ARR+=("$line")
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-30 04:01:23 +08:00
|
|
|
done < <(mysql --socket=/var/run/mysqld/mysqld.sock -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "SELECT alias_domain FROM alias_domain" -Bs)
|
2018-01-17 22:23:33 +08:00
|
|
|
|
2017-05-08 21:35:24 +08:00
|
|
|
if [[ ! -z ${DOMAIN_ARR} ]]; then
|
|
|
|
for domain in "${DOMAIN_ARR[@]}"; do
|
|
|
|
redis-cli -h redis-mailcow HSET DOMAIN_MAP ${domain} 1
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2018-06-08 15:11:03 +08:00
|
|
|
# Set API options if env vars are not empty
|
|
|
|
|
2018-06-10 20:30:30 +08:00
|
|
|
if [[ ${API_ALLOW_FROM} != "invalid" ]] && \
|
|
|
|
[[ ${API_KEY} != "invalid" ]] && \
|
|
|
|
[[ ! -z ${API_KEY} ]] && \
|
|
|
|
[[ ! -z ${API_ALLOW_FROM} ]]; then
|
2018-06-08 15:11:03 +08:00
|
|
|
IFS=',' read -r -a API_ALLOW_FROM_ARR <<< "${API_ALLOW_FROM}"
|
|
|
|
declare -a VALIDATED_API_ALLOW_FROM_ARR
|
|
|
|
REGEX_IP6='^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$'
|
|
|
|
REGEX_IP4='^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
|
|
|
|
|
|
|
|
for IP in "${API_ALLOW_FROM_ARR[@]}"; do
|
|
|
|
if [[ ${IP} =~ ${REGEX_IP6} ]] || [[ ${IP} =~ ${REGEX_IP4} ]]; then
|
|
|
|
VALIDATED_API_ALLOW_FROM_ARR+=("${IP}")
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
VALIDATED_IPS=$(array_by_comma ${VALIDATED_API_ALLOW_FROM_ARR[*]})
|
|
|
|
if [[ ! -z ${VALIDATED_IPS} ]]; then
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-30 04:01:23 +08:00
|
|
|
mysql --socket=/var/run/mysqld/mysqld.sock -u ${DBUSER} -p${DBPASS} ${DBNAME} << EOF
|
2018-10-11 17:53:22 +08:00
|
|
|
DELETE FROM api;
|
|
|
|
INSERT INTO api (api_key, active, allow_from) VALUES ("${API_KEY}", "1", "${VALIDATED_IPS}");
|
2018-06-08 15:11:03 +08:00
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-03-02 18:23:23 +08:00
|
|
|
exec "$@"
|