2017-06-22 23:12:13 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-10-30 02:58:34 +08:00
|
|
|
until nc phpfpm 9001 -z; do
|
|
|
|
echo "Waiting for PHP on port 9001..."
|
|
|
|
sleep 3
|
|
|
|
done
|
|
|
|
|
|
|
|
until nc phpfpm 9002 -z; do
|
|
|
|
echo "Waiting for PHP on port 9002..."
|
|
|
|
sleep 3
|
|
|
|
done
|
|
|
|
|
2019-05-06 18:18:37 +08:00
|
|
|
mkdir -p /etc/rspamd/plugins.d \
|
|
|
|
/etc/rspamd/custom
|
|
|
|
|
|
|
|
touch /etc/rspamd/rspamd.conf.local \
|
|
|
|
/etc/rspamd/rspamd.conf.override
|
|
|
|
|
2019-05-19 04:44:30 +08:00
|
|
|
chmod 755 /var/lib/rspamd
|
|
|
|
|
2019-10-29 15:39:57 +08:00
|
|
|
|
2019-07-08 13:56:41 +08:00
|
|
|
[[ ! -f /etc/rspamd/override.d/worker-controller-password.inc ]] && echo '# Autogenerated by mailcow' > /etc/rspamd/override.d/worker-controller-password.inc
|
2019-05-19 04:44:30 +08:00
|
|
|
|
2020-01-12 19:23:11 +08:00
|
|
|
echo ${IPV4_NETWORK}.0/24 > /etc/rspamd/custom/mailcow_networks.map
|
|
|
|
echo ${IPV6_NETWORK} >> /etc/rspamd/custom/mailcow_networks.map
|
|
|
|
|
2019-05-19 04:44:30 +08:00
|
|
|
DOVECOT_V4=
|
|
|
|
DOVECOT_V6=
|
|
|
|
until [[ ! -z ${DOVECOT_V4} ]]; do
|
|
|
|
DOVECOT_V4=$(dig a dovecot +short)
|
|
|
|
DOVECOT_V6=$(dig aaaa dovecot +short)
|
|
|
|
[[ ! -z ${DOVECOT_V4} ]] && break;
|
2020-01-11 03:39:11 +08:00
|
|
|
echo "Waiting for Dovecot..."
|
2019-05-19 04:44:30 +08:00
|
|
|
sleep 3
|
|
|
|
done
|
|
|
|
echo ${DOVECOT_V4}/32 > /etc/rspamd/custom/dovecot_trusted.map
|
|
|
|
if [[ ! -z ${DOVECOT_V6} ]]; then
|
|
|
|
echo ${DOVECOT_V6}/128 >> /etc/rspamd/custom/dovecot_trusted.map
|
|
|
|
fi
|
|
|
|
|
2020-01-11 03:39:11 +08:00
|
|
|
RSPAMD_V4=
|
|
|
|
RSPAMD_V6=
|
|
|
|
until [[ ! -z ${RSPAMD_V4} ]]; do
|
|
|
|
RSPAMD_V4=$(dig a rspamd +short)
|
|
|
|
RSPAMD_V6=$(dig aaaa rspamd +short)
|
|
|
|
[[ ! -z ${RSPAMD_V4} ]] && break;
|
|
|
|
echo "Waiting for Rspamd..."
|
|
|
|
sleep 3
|
|
|
|
done
|
|
|
|
echo ${RSPAMD_V4}/32 > /etc/rspamd/custom/rspamd_trusted.map
|
|
|
|
if [[ ! -z ${RSPAMD_V6} ]]; then
|
|
|
|
echo ${RSPAMD_V6}/128 >> /etc/rspamd/custom/rspamd_trusted.map
|
|
|
|
fi
|
|
|
|
|
2020-02-05 17:58:52 +08:00
|
|
|
if [[ ! -z ${REDIS_SLAVEOF_IP} ]]; then
|
|
|
|
cat <<EOF > /etc/rspamd/local.d/redis.conf
|
|
|
|
read_servers = "redis:6379";
|
|
|
|
write_servers = "${REDIS_SLAVEOF_IP}:${REDIS_SLAVEOF_PORT}";
|
|
|
|
timeout = 10;
|
|
|
|
EOF
|
|
|
|
until [[ $(redis-cli -h redis-mailcow PING) == "PONG" ]]; do
|
|
|
|
echo "Waiting for Redis slave..."
|
|
|
|
sleep 2
|
|
|
|
done
|
|
|
|
until [[ $(redis-cli -h ${REDIS_SLAVEOF_IP} -p ${REDIS_SLAVEOF_PORT} PING) == "PONG" ]]; do
|
|
|
|
echo "Waiting for Redis master..."
|
|
|
|
sleep 2
|
|
|
|
done
|
|
|
|
redis-cli -h redis-mailcow SLAVEOF ${REDIS_SLAVEOF_IP} ${REDIS_SLAVEOF_PORT}
|
|
|
|
else
|
|
|
|
cat <<EOF > /etc/rspamd/local.d/redis.conf
|
|
|
|
servers = "redis:6379";
|
|
|
|
timeout = 10;
|
|
|
|
EOF
|
|
|
|
until [[ $(redis-cli -h redis-mailcow PING) == "PONG" ]]; do
|
|
|
|
echo "Waiting for Redis slave..."
|
|
|
|
sleep 2
|
|
|
|
done
|
|
|
|
redis-cli -h redis-mailcow SLAVEOF NO ONE
|
|
|
|
fi
|
|
|
|
|
2019-05-06 18:18:37 +08:00
|
|
|
chown -R _rspamd:_rspamd /var/lib/rspamd \
|
|
|
|
/etc/rspamd/local.d \
|
|
|
|
/etc/rspamd/override.d \
|
|
|
|
/etc/rspamd/rspamd.conf.local \
|
|
|
|
/etc/rspamd/rspamd.conf.override \
|
|
|
|
/etc/rspamd/plugins.d
|
|
|
|
|
2019-10-25 14:31:31 +08:00
|
|
|
# Fix missing default global maps, if any
|
|
|
|
# These exists in mailcow UI and should not be removed
|
|
|
|
touch /etc/rspamd/custom/global_mime_from_blacklist.map \
|
|
|
|
/etc/rspamd/custom/global_rcpt_blacklist.map \
|
|
|
|
/etc/rspamd/custom/global_smtp_from_blacklist.map \
|
|
|
|
/etc/rspamd/custom/global_mime_from_whitelist.map \
|
|
|
|
/etc/rspamd/custom/global_rcpt_whitelist.map \
|
|
|
|
/etc/rspamd/custom/global_smtp_from_whitelist.map \
|
2019-12-23 17:20:34 +08:00
|
|
|
/etc/rspamd/custom/bad_languages.map \
|
2019-10-25 14:31:31 +08:00
|
|
|
/etc/rspamd/custom/sa-rules \
|
|
|
|
/etc/rspamd/custom/dovecot_trusted.map \
|
2020-01-11 03:39:11 +08:00
|
|
|
/etc/rspamd/custom/rspamd_trusted.map \
|
2020-01-12 19:23:11 +08:00
|
|
|
/etc/rspamd/custom/mailcow_networks.map \
|
2019-10-25 14:31:31 +08:00
|
|
|
/etc/rspamd/custom/ip_wl.map \
|
|
|
|
/etc/rspamd/custom/fishy_tlds.map \
|
|
|
|
/etc/rspamd/custom/bad_words.map \
|
|
|
|
/etc/rspamd/custom/bad_asn.map \
|
2020-03-06 14:14:06 +08:00
|
|
|
/etc/rspamd/custom/bad_words_de.map \
|
|
|
|
/etc/rspamd/custom/bulk_headers.map
|
2019-10-25 14:31:31 +08:00
|
|
|
|
|
|
|
# www-data (82) group needs to write to these files
|
2019-10-30 21:40:00 +08:00
|
|
|
chown _rspamd:_rspamd /etc/rspamd/custom/
|
2019-10-31 03:07:58 +08:00
|
|
|
chmod 0755 /etc/rspamd/custom/.
|
|
|
|
chown -R 82:82 /etc/rspamd/custom/*
|
|
|
|
chmod 644 -R /etc/rspamd/custom/*
|
2019-10-25 14:31:31 +08:00
|
|
|
|
2019-10-18 18:01:47 +08:00
|
|
|
# Run hooks
|
|
|
|
for file in /hooks/*; do
|
|
|
|
if [ -x "${file}" ]; then
|
|
|
|
echo "Running hook ${file}"
|
|
|
|
"${file}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2018-07-13 18:04:32 +08:00
|
|
|
exec "$@"
|