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 |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 5 | |
| 6 | # Hash current SA rules |
| 7 | if [[ ! -f /etc/rspamd/custom/sa-rules ]]; then |
| 8 | HASH_SA_RULES=0 |
| 9 | else |
| 10 | HASH_SA_RULES=$(cat /etc/rspamd/custom/sa-rules | md5sum | cut -d' ' -f1) |
| 11 | fi |
| 12 | |
| 13 | # Deploy |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 14 | 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 |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 15 | if gzip -t /tmp/sa-rules-heinlein.tar.gz; then |
| 16 | tar xfvz /tmp/sa-rules-heinlein.tar.gz -C /tmp/sa-rules-heinlein |
| 17 | cat /tmp/sa-rules-heinlein/*cf > /etc/rspamd/custom/sa-rules |
| 18 | fi |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 19 | |
| 20 | sed -i -e 's/\([^\\]\)\$\([^\/]\)/\1\\$\2/g' /etc/rspamd/custom/sa-rules |
| 21 | |
| 22 | if [[ "$(cat /etc/rspamd/custom/sa-rules | md5sum | cut -d' ' -f1)" != "${HASH_SA_RULES}" ]]; then |
| 23 | CONTAINER_NAME=rspamd-mailcow |
| 24 | CONTAINER_ID=$(curl --silent --insecure https://dockerapi/containers/json | \ |
| 25 | jq -r ".[] | {name: .Config.Labels[\"com.docker.compose.service\"], project: .Config.Labels[\"com.docker.compose.project\"], id: .Id}" | \ |
| 26 | jq -rc "select( .name | tostring | contains(\"${CONTAINER_NAME}\")) | select( .project | tostring | contains(\"${COMPOSE_PROJECT_NAME,,}\")) | .id") |
| 27 | if [[ ! -z ${CONTAINER_ID} ]]; then |
| 28 | curl --silent --insecure -XPOST --connect-timeout 15 --max-time 120 https://dockerapi/containers/${CONTAINER_ID}/restart |
| 29 | fi |
| 30 | fi |
| 31 | |
| 32 | # Cleanup |
| 33 | rm -rf /tmp/sa-rules-heinlein /tmp/sa-rules-heinlein.tar.gz |