blob: 24f09d422c749bcc4197793187cdd90fa78a9b4b (
plain)
- #!/bin/sh
- #
- # Tweak SpamAssassin settings internal_networks trusted_networks
- set -e
- exit1() {
- response="${1:+Error: }${1:-Internal error!}"
- echo "$response" >&2
- exit 1
- }
- firstitem() {
- file="$1"
- cat "$file" | grep -v '^#' | sed 's/#.*//' | head -n 1
- }
- items() {
- file="$1"
- cat "$file" | grep -v '^#' | sed 's/#.*//'
- }
- items_singleline() {
- perl -0777 -ne 'print join " ",m/^\s*([^#\s]+)/gm' "$1"
- }
- addoroverwritewithindents() {
- set -e
- file="$1"
- export token="$2"
- # provide replacement as STDIN
- perl -0777 -pi \
- -E 'BEGIN{ $s=<STDIN>; chomp $s }'\
- -E 's/$ENV{"token"}.*(?:\n\h.*)+\n/$s/m and $seen=1;'\
- -E 'END{ unless ($seen) { print $s } }'\
- "$file"
- }
- REDPILL=$(firstitem "/etc/local-ORG/redpill")
- redpilldir="/etc/local-$REDPILL/"
- REALMS="$(items "$redpilldir/realms")"
- REALM="$(cat /etc/local-ORG/realm || dnsdomainname | tr '[a-z]' '[A-Z]')"
- for realm in $REALMS; do
- realmdir="$redpilldir/$realm"
- [ -d "$realmdir" ] || continue
- mailnets=$(items_singleline "$realmdir/mailnetworks") #'
- if [ "$REALM" = "$realm" ]; then
- ournets="${ournets:+$ournets }$mailnets"
- [ ! -f "$realmdir/localnetworks" ] || ournets="${ournets:+$ournets }$(items "$realmdir/localnetworks")"
- else
- redpillnets="${redpillnets:+$redpillnets }$mailnets"
- redpillhosts="${redpillhosts:+$redpillhosts }$(items "$realmdir/mailhost")"
- fi
- done
- echo "FIXME: Add these to /etc/spamassassin/local.cf:"
- echo "internal_networks $ournets"
- echo "trusted_networks $ournets $redpillnets"
- echo "whitelist_bounce_relays $redpillhosts"
|