docker-entrypoint.sh 3.6 KB

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