import-list: Recreate exim mailmandb if domain changed.
[clinton/scripts.git] / mailman-update-exim-db
CommitLineData
1f0c0e80 1#!/bin/bash
2#
940e23ca 3# mailman-update-exim-db: Make an associated list mapping list names
4# and the domain that they are associated with.
1f0c0e80 5#
6# This table is then used by Exim to verify that the list name and
7# domain are correct.
8#
940e23ca 9# This script is meant to be called from a cron job, and run as root.
1f0c0e80 10
11MMDIR=/var/lib/mailman
12LISTDIR=$MMDIR/lists
13BINDIR=$MMDIR/bin
14TABLE=/etc/exim4/mailmandb
de85b0a6 15TABLE_EXT=/etc/exim4/mailmandb-ext
1f0c0e80 16
17# Use return as separator, never space or tab.
18IFS="
19"
20
21# Create table with the right permissions or clear it.
22if test ! -f $TABLE; then
23 touch $TABLE
24 chown root:mail $TABLE
25 chmod u=rw,g=r,o= $TABLE
26else
27 : > $TABLE
28fi
29
30# Iterate through available lists
31for 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
de85b0a6 37 echo "$LIST@$DOMAIN: true" >> $TABLE
1f0c0e80 38 fi
39done
de85b0a6 40
41# Add extras file, for aliases of domains and whatnot
42if test -f $TABLE_EXT; then
43 cat $TABLE_EXT >> $TABLE
44fi