sa-rules.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. # Create temp directories
  3. [[ ! -d /tmp/sa-rules-heinlein ]] && mkdir -p /tmp/sa-rules-heinlein
  4. # Hash current SA rules
  5. if [[ ! -f /etc/rspamd/custom/sa-rules ]]; then
  6. HASH_SA_RULES=0
  7. else
  8. HASH_SA_RULES=$(cat /etc/rspamd/custom/sa-rules | md5sum | cut -d' ' -f1)
  9. fi
  10. # Deploy
  11. curl --connect-timeout 15 --retry 10 --max-time 30 http://www.spamassassin.heinlein-support.de/$(dig txt 1.4.3.spamassassin.heinlein-support.de +short | tr -d '"' | tr -dc '0-9').tar.gz --output /tmp/sa-rules-heinlein.tar.gz
  12. if gzip -t /tmp/sa-rules-heinlein.tar.gz; then
  13. tar xfvz /tmp/sa-rules-heinlein.tar.gz -C /tmp/sa-rules-heinlein
  14. cat /tmp/sa-rules-heinlein/*cf > /etc/rspamd/custom/sa-rules
  15. fi
  16. sed -i -e 's/\([^\\]\)\$\([^\/]\)/\1\\$\2/g' /etc/rspamd/custom/sa-rules
  17. if [[ "$(cat /etc/rspamd/custom/sa-rules | md5sum | cut -d' ' -f1)" != "${HASH_SA_RULES}" ]]; then
  18. CONTAINER_NAME=rspamd-mailcow
  19. CONTAINER_ID=$(curl --silent --insecure https://dockerapi/containers/json | \
  20. jq -r ".[] | {name: .Config.Labels[\"com.docker.compose.service\"], project: .Config.Labels[\"com.docker.compose.project\"], id: .Id}" | \
  21. jq -rc "select( .name | tostring | contains(\"${CONTAINER_NAME}\")) | select( .project | tostring | contains(\"${COMPOSE_PROJECT_NAME,,}\")) | .id")
  22. if [[ ! -z ${CONTAINER_ID} ]]; then
  23. curl --silent --insecure -XPOST --connect-timeout 15 --max-time 120 https://dockerapi/containers/${CONTAINER_ID}/restart
  24. fi
  25. fi
  26. # Cleanup
  27. rm -rf /tmp/sa-rules-heinlein /tmp/sa-rules-heinlein.tar.gz