summaryrefslogtreecommitdiff
path: root/amavis/mklists.sh
blob: f7db451b245bb67e4147a9f4cb5943c410f92c01 (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. realmsdir='/etc/local-REDPILL'
  13. domainconfdir='/etc/local-ORG/amavis'
  14. if ! [ -d "$realmsdir" ]; then
  15. echo "WARNING: Realms directory \"$realmsdir\" does not exist."
  16. fi
  17. if ! [ -d "$domainconfdir" ]; then
  18. echo "WARNING: Domain config directory \"$domainconfdir\" does not exist."
  19. fi
  20. catfilefromownrealm() {
  21. file="$1"
  22. [ -d "$realmsdir" ] || exit 0
  23. thisrealm="$(cat /etc/local-ORG/realm || dnsdomainname | tr '[a-z]' '[A-Z]')"
  24. if [ -r /etc/local/"$file"_exceptions ]; then
  25. grep -vFf /etc/local/"$file"_exceptions "$realmsdir/$thisrealm/$file"
  26. else
  27. cat "$realmsdir/$thisrealm/$file"
  28. fi
  29. if [ -r /etc/local/"$file"_additions ]; then
  30. cat /etc/local/"$file"_additions
  31. fi
  32. }
  33. catallfilesfromotherrealms() {
  34. file="$1"
  35. [ -d "$realmsdir" ] || exit 0
  36. [ -f "$realmsdir/realms" ] || exit 0
  37. realms="$(cat "$realmsdir/realms" | sed 's/#.*//')"
  38. thisrealm="$(cat /etc/local-ORG/realm || dnsdomainname | tr '[a-z]' '[A-Z]')"
  39. for realm in $realms; do
  40. if [ "$thisrealm" != "$realm" ]; then
  41. if [ -r /etc/local/$"file"_additions ]; then
  42. grep -vFf /etc/local/"$file"_additions "$realmsdir/$realm/$file"
  43. else
  44. cat "$realmsdir/$realm/$file"
  45. fi
  46. fi
  47. done
  48. if [ -r /etc/local/"$file"_exceptions ]; then
  49. cat /etc/local/"$file"_exceptions
  50. fi
  51. }
  52. catfilefromownrealm maildomains | sort > "$domainconfdir/local_domains"
  53. catallfilesfromotherrealms maildomains | sort > "$domainconfdir/nonlocal_domains"