sa-rules.sh 1.2 KB

12345678910111213141516171819202122232425
  1. #!/bin/bash
  2. [[ ! -d /tmp/sa-rules-heinlein ]] && mkdir -p /tmp/sa-rules-heinlein
  3. if [[ ! -f /etc/rspamd/custom/sa-rules-heinlein ]]; then
  4. HASH_SA_RULES=0
  5. else
  6. HASH_SA_RULES=$(cat /etc/rspamd/custom/sa-rules-heinlein | md5sum | cut -d' ' -f1)
  7. fi
  8. curl http://www.spamassassin.heinlein-support.de/$(dig txt 1.4.3.spamassassin.heinlein-support.de +short | tr -d '"').tar.gz --output /tmp/sa-rules.tar.gz
  9. if [[ -f /tmp/sa-rules.tar.gz ]]; then
  10. tar xfvz /tmp/sa-rules.tar.gz -C /tmp/sa-rules-heinlein
  11. # create complete list of rules in a single file
  12. cat /tmp/sa-rules-heinlein/*cf > /etc/rspamd/custom/sa-rules-heinlein
  13. # Only restart rspamd-mailcow when rules changed
  14. if [[ $(cat /etc/rspamd/custom/sa-rules-heinlein | md5sum | cut -d' ' -f1) != ${HASH_SA_RULES} ]]; then
  15. CONTAINER_NAME=rspamd-mailcow
  16. CONTAINER_ID=$(curl --silent --insecure https://dockerapi/containers/json | \
  17. jq -r ".[] | {name: .Config.Labels[\"com.docker.compose.service\"], id: .Id}" | \
  18. jq -rc "select( .name | tostring | contains(\"${CONTAINER_NAME}\")) | .id")
  19. if [[ ! -z ${CONTAINER_ID} ]]; then
  20. curl --silent --insecure -XPOST https://dockerapi/containers/${CONTAINER_ID}/restart
  21. fi
  22. fi
  23. fi
  24. rm -r /tmp/sa-rules-heinlein /tmp/sa-rules.tar.gz