Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | until nc phpfpm 9001 -z; do |
| 4 | echo "Waiting for PHP on port 9001..." |
| 5 | sleep 3 |
| 6 | done |
| 7 | |
| 8 | until nc phpfpm 9002 -z; do |
| 9 | echo "Waiting for PHP on port 9002..." |
| 10 | sleep 3 |
| 11 | done |
| 12 | |
| 13 | mkdir -p /etc/rspamd/plugins.d \ |
| 14 | /etc/rspamd/custom |
| 15 | |
| 16 | touch /etc/rspamd/rspamd.conf.local \ |
| 17 | /etc/rspamd/rspamd.conf.override |
| 18 | |
| 19 | chmod 755 /var/lib/rspamd |
| 20 | |
| 21 | |
| 22 | [[ ! -f /etc/rspamd/override.d/worker-controller-password.inc ]] && echo '# Autogenerated by mailcow' > /etc/rspamd/override.d/worker-controller-password.inc |
| 23 | |
| 24 | echo ${IPV4_NETWORK}.0/24 > /etc/rspamd/custom/mailcow_networks.map |
| 25 | echo ${IPV6_NETWORK} >> /etc/rspamd/custom/mailcow_networks.map |
| 26 | |
| 27 | DOVECOT_V4= |
| 28 | DOVECOT_V6= |
| 29 | until [[ ! -z ${DOVECOT_V4} ]]; do |
| 30 | DOVECOT_V4=$(dig a dovecot +short) |
| 31 | DOVECOT_V6=$(dig aaaa dovecot +short) |
| 32 | [[ ! -z ${DOVECOT_V4} ]] && break; |
| 33 | echo "Waiting for Dovecot..." |
| 34 | sleep 3 |
| 35 | done |
| 36 | echo ${DOVECOT_V4}/32 > /etc/rspamd/custom/dovecot_trusted.map |
| 37 | if [[ ! -z ${DOVECOT_V6} ]]; then |
| 38 | echo ${DOVECOT_V6}/128 >> /etc/rspamd/custom/dovecot_trusted.map |
| 39 | fi |
| 40 | |
| 41 | RSPAMD_V4= |
| 42 | RSPAMD_V6= |
| 43 | until [[ ! -z ${RSPAMD_V4} ]]; do |
| 44 | RSPAMD_V4=$(dig a rspamd +short) |
| 45 | RSPAMD_V6=$(dig aaaa rspamd +short) |
| 46 | [[ ! -z ${RSPAMD_V4} ]] && break; |
| 47 | echo "Waiting for Rspamd..." |
| 48 | sleep 3 |
| 49 | done |
| 50 | echo ${RSPAMD_V4}/32 > /etc/rspamd/custom/rspamd_trusted.map |
| 51 | if [[ ! -z ${RSPAMD_V6} ]]; then |
| 52 | echo ${RSPAMD_V6}/128 >> /etc/rspamd/custom/rspamd_trusted.map |
| 53 | fi |
| 54 | |
| 55 | if [[ ! -z ${REDIS_SLAVEOF_IP} ]]; then |
| 56 | cat <<EOF > /etc/rspamd/local.d/redis.conf |
| 57 | read_servers = "redis:6379"; |
| 58 | write_servers = "${REDIS_SLAVEOF_IP}:${REDIS_SLAVEOF_PORT}"; |
| 59 | timeout = 10; |
| 60 | EOF |
| 61 | until [[ $(redis-cli -h redis-mailcow PING) == "PONG" ]]; do |
| 62 | echo "Waiting for Redis @redis-mailcow..." |
| 63 | sleep 2 |
| 64 | done |
| 65 | until [[ $(redis-cli -h ${REDIS_SLAVEOF_IP} -p ${REDIS_SLAVEOF_PORT} PING) == "PONG" ]]; do |
| 66 | echo "Waiting for Redis @${REDIS_SLAVEOF_IP}..." |
| 67 | sleep 2 |
| 68 | done |
| 69 | redis-cli -h redis-mailcow SLAVEOF ${REDIS_SLAVEOF_IP} ${REDIS_SLAVEOF_PORT} |
| 70 | else |
| 71 | cat <<EOF > /etc/rspamd/local.d/redis.conf |
| 72 | servers = "redis:6379"; |
| 73 | timeout = 10; |
| 74 | EOF |
| 75 | until [[ $(redis-cli -h redis-mailcow PING) == "PONG" ]]; do |
| 76 | echo "Waiting for Redis slave..." |
| 77 | sleep 2 |
| 78 | done |
| 79 | redis-cli -h redis-mailcow SLAVEOF NO ONE |
| 80 | fi |
| 81 | |
| 82 | chown -R _rspamd:_rspamd /var/lib/rspamd \ |
| 83 | /etc/rspamd/local.d \ |
| 84 | /etc/rspamd/override.d \ |
| 85 | /etc/rspamd/rspamd.conf.local \ |
| 86 | /etc/rspamd/rspamd.conf.override \ |
| 87 | /etc/rspamd/plugins.d |
| 88 | |
| 89 | # Fix missing default global maps, if any |
| 90 | # These exists in mailcow UI and should not be removed |
| 91 | touch /etc/rspamd/custom/global_mime_from_blacklist.map \ |
| 92 | /etc/rspamd/custom/global_rcpt_blacklist.map \ |
| 93 | /etc/rspamd/custom/global_smtp_from_blacklist.map \ |
| 94 | /etc/rspamd/custom/global_mime_from_whitelist.map \ |
| 95 | /etc/rspamd/custom/global_rcpt_whitelist.map \ |
| 96 | /etc/rspamd/custom/global_smtp_from_whitelist.map \ |
| 97 | /etc/rspamd/custom/bad_languages.map \ |
| 98 | /etc/rspamd/custom/sa-rules \ |
| 99 | /etc/rspamd/custom/dovecot_trusted.map \ |
| 100 | /etc/rspamd/custom/rspamd_trusted.map \ |
| 101 | /etc/rspamd/custom/mailcow_networks.map \ |
| 102 | /etc/rspamd/custom/ip_wl.map \ |
| 103 | /etc/rspamd/custom/fishy_tlds.map \ |
| 104 | /etc/rspamd/custom/bad_words.map \ |
| 105 | /etc/rspamd/custom/bad_asn.map \ |
| 106 | /etc/rspamd/custom/bad_words_de.map \ |
| 107 | /etc/rspamd/custom/bulk_header.map |
| 108 | |
| 109 | # www-data (82) group needs to write to these files |
| 110 | chown _rspamd:_rspamd /etc/rspamd/custom/ |
| 111 | chmod 0755 /etc/rspamd/custom/. |
| 112 | chown -R 82:82 /etc/rspamd/custom/* |
| 113 | chmod 644 -R /etc/rspamd/custom/* |
| 114 | |
| 115 | # Run hooks |
| 116 | for file in /hooks/*; do |
| 117 | if [ -x "${file}" ]; then |
| 118 | echo "Running hook ${file}" |
| 119 | "${file}" |
| 120 | fi |
| 121 | done |
| 122 | |
| 123 | exec "$@" |