blob: e6d329b5c3cfc5a01f8c1cfc5da691bba370398f [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001#!/bin/bash
2
3until nc phpfpm 9001 -z; do
4 echo "Waiting for PHP on port 9001..."
5 sleep 3
6done
7
8until nc phpfpm 9002 -z; do
9 echo "Waiting for PHP on port 9002..."
10 sleep 3
11done
12
13mkdir -p /etc/rspamd/plugins.d \
14 /etc/rspamd/custom
15
16touch /etc/rspamd/rspamd.conf.local \
17 /etc/rspamd/rspamd.conf.override
18
19chmod 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
24echo ${IPV4_NETWORK}.0/24 > /etc/rspamd/custom/mailcow_networks.map
25echo ${IPV6_NETWORK} >> /etc/rspamd/custom/mailcow_networks.map
26
27DOVECOT_V4=
28DOVECOT_V6=
29until [[ ! -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
35done
36echo ${DOVECOT_V4}/32 > /etc/rspamd/custom/dovecot_trusted.map
37if [[ ! -z ${DOVECOT_V6} ]]; then
38 echo ${DOVECOT_V6}/128 >> /etc/rspamd/custom/dovecot_trusted.map
39fi
40
41RSPAMD_V4=
42RSPAMD_V6=
43until [[ ! -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
49done
50echo ${RSPAMD_V4}/32 > /etc/rspamd/custom/rspamd_trusted.map
51if [[ ! -z ${RSPAMD_V6} ]]; then
52 echo ${RSPAMD_V6}/128 >> /etc/rspamd/custom/rspamd_trusted.map
53fi
54
55if [[ ! -z ${REDIS_SLAVEOF_IP} ]]; then
56 cat <<EOF > /etc/rspamd/local.d/redis.conf
57read_servers = "redis:6379";
58write_servers = "${REDIS_SLAVEOF_IP}:${REDIS_SLAVEOF_PORT}";
59timeout = 10;
60EOF
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}
70else
71 cat <<EOF > /etc/rspamd/local.d/redis.conf
72servers = "redis:6379";
73timeout = 10;
74EOF
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
80fi
81
82chown -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
91touch /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 \
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200107 /etc/rspamd/custom/bulk_header.map \
108 /etc/rspamd/custom/bad_header.map
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100109
110# www-data (82) group needs to write to these files
111chown _rspamd:_rspamd /etc/rspamd/custom/
112chmod 0755 /etc/rspamd/custom/.
113chown -R 82:82 /etc/rspamd/custom/*
114chmod 644 -R /etc/rspamd/custom/*
115
116# Run hooks
117for file in /hooks/*; do
118 if [ -x "${file}" ]; then
119 echo "Running hook ${file}"
120 "${file}"
121 fi
122done
123
124exec "$@"