Sync hcoop-backup changes from megacz
[clinton/scripts.git] / mailman-update-exim-db
1 #!/bin/bash
2 #
3 # mailman-update-exim-db: Make an associated list mapping list names
4 # and 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, and run as root.
10
11 MMDIR=/var/lib/mailman
12 LISTDIR=$MMDIR/lists
13 BINDIR=$MMDIR/bin
14 TABLE=/etc/exim4/mailmandb
15 TABLE_EXT=/etc/exim4/mailmandb-ext
16
17 # Use return as separator, never space or tab.
18 IFS="
19 "
20
21 # Create table with the right permissions or clear it.
22 if test ! -f $TABLE; then
23 touch $TABLE
24 chown root:mail $TABLE
25 chmod u=rw,g=r,o= $TABLE
26 else
27 : > $TABLE
28 fi
29
30 # Iterate through available lists
31 for i in $(find $LISTDIR -mindepth 1 -maxdepth 1 -type d -print); do
32 LIST=$(basename $i)
33 DOMAIN=$(su list -c "$BINDIR/config_list -o - $LIST" | \
34 grep -E "^host_name = '.+'" 2>/dev/null | \
35 sed -r -e "s/host_name = '(.+)'/\\1/")
36 if test -n "$LIST" && test -n "$DOMAIN"; then
37 echo "$LIST@$DOMAIN: true" >> $TABLE
38 fi
39 done
40
41 # Add extras file, for aliases of domains and whatnot
42 if test -f $TABLE_EXT; then
43 cat $TABLE_EXT >> $TABLE
44 fi