mailman-update-exim-db: New script that builds a Mailman lookup table for Exim
[hcoop/scripts.git] / mailman-update-exim-db
1 #!/bin/bash
2 #
3 # mailman-update-table: Make an associated list mapping list names and
4 # the domain that they are associated with.
5 #
6 # This table is then used by Exim to verify that the list name and
7 # domain are correct.
8 #
9 # This script is meant to be called from a cron job.
10
11 MMDIR=/var/lib/mailman
12 LISTDIR=$MMDIR/lists
13 BINDIR=$MMDIR/bin
14 TABLE=/etc/exim4/mailmandb
15
16 # Use return as separator, never space or tab.
17 IFS="
18 "
19
20 # Create table with the right permissions or clear it.
21 if test ! -f $TABLE; then
22 touch $TABLE
23 chown root:mail $TABLE
24 chmod u=rw,g=r,o= $TABLE
25 else
26 : > $TABLE
27 fi
28
29 # Iterate through available lists
30 for i in $(find $LISTDIR -mindepth 1 -maxdepth 1 -type d -print); do
31 LIST=$(basename $i)
32 DOMAIN=$(su list -c "$BINDIR/config_list -o - $LIST" | \
33 grep -E "^host_name = '.+'" 2>/dev/null | \
34 sed -r -e "s/host_name = '(.+)'/\\1/")
35 if test -n "$LIST" && test -n "$DOMAIN"; then
36 echo "$LIST: $DOMAIN" >> $TABLE
37 fi
38 done