Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Create temp directories |
| 4 | [[ ! -d /tmp/sa-rules-heinlein ]] && mkdir -p /tmp/sa-rules-heinlein |
| 5 | #[[ ! -d /tmp/sa-rules-schaal ]] && mkdir -p /tmp/sa-rules-schaal |
| 6 | |
| 7 | # Hash current SA rules |
| 8 | if [[ ! -f /etc/rspamd/custom/sa-rules ]]; then |
| 9 | HASH_SA_RULES=0 |
| 10 | else |
| 11 | HASH_SA_RULES=$(cat /etc/rspamd/custom/sa-rules | md5sum | cut -d' ' -f1) |
| 12 | fi |
| 13 | |
| 14 | # Deploy |
| 15 | ## Heinlein |
| 16 | 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 '"').tar.gz --output /tmp/sa-rules-heinlein.tar.gz |
| 17 | if gzip -t /tmp/sa-rules-heinlein.tar.gz; then |
| 18 | tar xfvz /tmp/sa-rules-heinlein.tar.gz -C /tmp/sa-rules-heinlein |
| 19 | cat /tmp/sa-rules-heinlein/*cf > /etc/rspamd/custom/sa-rules |
| 20 | fi |
| 21 | ## Schaal |
| 22 | #curl --connect-timeout 15 --max-time 30 http://sa.schaal-it.net/$(dig txt 1.4.3.sa.schaal-it.net +short | tr -d '"').tar.gz --output /tmp/sa-rules-schaal.tar.gz |
| 23 | #if gzip -t /tmp/sa-rules-schaal.tar.gz; then |
| 24 | # tar xfvz /tmp/sa-rules-schaal.tar.gz -C /tmp/sa-rules-schaal |
| 25 | # # Append, do not overwrite |
| 26 | # cat /tmp/sa-rules-schaal/*cf >> /etc/rspamd/custom/sa-rules |
| 27 | #fi |
| 28 | |
| 29 | sed -i -e 's/\([^\\]\)\$\([^\/]\)/\1\\$\2/g' /etc/rspamd/custom/sa-rules |
| 30 | |
| 31 | if [[ "$(cat /etc/rspamd/custom/sa-rules | md5sum | cut -d' ' -f1)" != "${HASH_SA_RULES}" ]]; then |
| 32 | CONTAINER_NAME=rspamd-mailcow |
| 33 | CONTAINER_ID=$(curl --silent --insecure https://dockerapi/containers/json | \ |
| 34 | jq -r ".[] | {name: .Config.Labels[\"com.docker.compose.service\"], project: .Config.Labels[\"com.docker.compose.project\"], id: .Id}" | \ |
| 35 | jq -rc "select( .name | tostring | contains(\"${CONTAINER_NAME}\")) | select( .project | tostring | contains(\"${COMPOSE_PROJECT_NAME,,}\")) | .id") |
| 36 | if [[ ! -z ${CONTAINER_ID} ]]; then |
| 37 | curl --silent --insecure -XPOST --connect-timeout 15 --max-time 120 https://dockerapi/containers/${CONTAINER_ID}/restart |
| 38 | fi |
| 39 | fi |
| 40 | |
| 41 | # Cleanup |
| 42 | rm -rf /tmp/sa-rules-heinlein /tmp/sa-rules-heinlein.tar.gz |
| 43 | #rm -rf /tmp/sa-rules-schaal /tmp/sa-rules-schaal.tar.gz |