summaryrefslogtreecommitdiff
path: root/amavis/mklists.sh
blob: 7a7b4fd27f5ea166c85200b0fbba8a411ed3b4d4 (plain)
  1. #!/bin/sh
  2. #
  3. # /etc/local-COMMON/amavis/mklists.sh
  4. # Copyright 2007 Jonas Smedegaard <dr@jones.dk>
  5. #
  6. # $Id: mklists.sh,v 1.3 2007-10-19 01:14:22 jonas Exp $
  7. #
  8. # Resolve own mail domains and MX backup domains
  9. set -e
  10. # Let's standardize sort
  11. export LC_ALL=C
  12. basedir=${basedir:-/etc}
  13. REDPILL=${REDPILL:-REDPILL}
  14. ORG=${ORG:-ORG}
  15. realmsdir=${realmsdir:-$basedir/local-$REDPILL}
  16. domaindir=${domaindir:-$basedir/local-$ORG}
  17. domainconfdir=${domainconfdir:-$domaindir/amavis}
  18. localdir=${localdir:-$basedir/local}
  19. if ! [ -d "$realmsdir" ]; then
  20. echo "WARNING: Realms directory \"$realmsdir\" does not exist."
  21. fi
  22. if ! [ -d "$domainconfdir" ]; then
  23. echo "WARNING: Domain config directory \"$domainconfdir\" does not exist."
  24. fi
  25. catfilefromownrealm() {
  26. file="$1"
  27. [ -d "$realmsdir" ] || exit 0
  28. thisrealm="$(cat "$domaindir/realm" || dnsdomainname | tr '[a-z]' '[A-Z]')"
  29. if [ -r "$localdir/${file}_exceptions" ]; then
  30. grep -vFf "$localdir/${file}_exceptions" "$realmsdir/$thisrealm/$file"
  31. else
  32. cat "$realmsdir/$thisrealm/$file"
  33. fi
  34. if [ -r "$localdir/${file}_additions" ]; then
  35. cat "$localdir/${file}_additions"
  36. fi
  37. }
  38. catallfilesfromotherrealms() {
  39. file="$1"
  40. [ -d "$realmsdir" ] || exit 0
  41. [ -f "$realmsdir/realms" ] || exit 0
  42. realms="$(cat "$realmsdir/realms" | sed 's/#.*//')"
  43. thisrealm="$(cat "$domaindir/realm" || dnsdomainname | tr '[a-z]' '[A-Z]')"
  44. for realm in $realms; do
  45. if [ "$thisrealm" != "$realm" ]; then
  46. if [ -r "$localdir/${file}_additions" ]; then
  47. grep -vFf "$localdir/${file}_additions" "$realmsdir/$realm/$file"
  48. else
  49. cat "$realmsdir/$realm/$file"
  50. fi
  51. fi
  52. done
  53. if [ -r "$localdir/${file}_exceptions" ]; then
  54. cat "$localdir/${file}_exceptions"
  55. fi
  56. }
  57. catfilefromownrealm maildomains | sort > "$domainconfdir/local_domains"
  58. catallfilesfromotherrealms maildomains | sort > "$domainconfdir/nonlocal_domains"