Add docelic's new-user script
[clinton/scripts.git] / mailman-update-exim-db
... / ...
CommitLineData
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
11MMDIR=/var/lib/mailman
12LISTDIR=$MMDIR/lists
13BINDIR=$MMDIR/bin
14TABLE=/etc/exim4/mailmandb
15
16# Use return as separator, never space or tab.
17IFS="
18"
19
20# Create table with the right permissions or clear it.
21if test ! -f $TABLE; then
22 touch $TABLE
23 chown root:mail $TABLE
24 chmod u=rw,g=r,o= $TABLE
25else
26 : > $TABLE
27fi
28
29# Iterate through available lists
30for 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
38done