Mailman Helper Scripts

From CobaltFAQs

Jump to: navigation, search

This script will make the necessary entries into /etc/mail/virtusertable and /etc/mail/aliases.mailman. Run this script before adding a new list via the Mailman UI.

#!/bin/bash
#
# Copyright (c) 2004-2005, Bruce Timberlake <brucetimberlake@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. The name of Bruce Timberlake may not be used to endorse or promote
#    products derived from this software without specific prior written
#    permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

LISTNAME=$1
if [ "$LISTNAME" == "" ]; then
  echo Error: No list name found.
  echo
  echo Usage: addlist listname
  exit
fi

VIRT=/etc/mail/virtusertable
VIRTDB=$VIRT.db
ALIAS=/etc/mail/aliases.mailman
ALIASDB=$ALIAS.db
DOMAIN=www.example.org
MAILMAN_DIR=/home/mailman
MAKEMAP=/usr/bin/makemap

EXISTS=`grep -i $LISTNAME $VIRT`
# The if-test below will be problematic if you are trying
# to create a list that has the name of another existing
# list in the new name (e.g. a list "foo" exists, and you
# are trying to make a new list named "foobar")
if [ "$EXISTS" != "" ]; then
  echo $LISTNAME already appears in $VIRT
else
  echo Making entries in $VIRT
  echo "" >> $VIRT
  echo "## List: $LISTNAME" >> $VIRT
  echo "$LISTNAME@$DOMAIN $LISTNAME" >> $VIRT
  echo "$LISTNAME-admin@$DOMAIN   $LISTNAME-admin" >> $VIRT
  echo "$LISTNAME-bounces@$DOMAIN $LISTNAME-bounces" >> $VIRT
  echo "$LISTNAME-confirm@$DOMAIN $LISTNAME-confirm" >> $VIRT
  echo "$LISTNAME-join@$DOMAIN    $LISTNAME-join" >> $VIRT
  echo "$LISTNAME-leave@$DOMAIN   $LISTNAME-leave" >> $VIRT
  echo "$LISTNAME-owner@$DOMAIN   $LISTNAME-owner" >> $VIRT
  echo "$LISTNAME-request@$DOMAIN $LISTNAME-request" >> $VIRT
  echo "$LISTNAME-subscribe@$DOMAIN       $LISTNAME-subscribe" >> $VIRT
  echo "$LISTNAME-unsubscribe@$DOMAIN     $LISTNAME-unsubscribe" >> $VIRT

  echo Making entries in $ALIAS
  echo "" >> $ALIAS
  echo "## $LISTNAME mailing list" >> $ALIAS
  echo "$LISTNAME:              \"|$MAILMAN_DIR/mail/mailman post $LISTNAME\"" >> $ALIAS
  echo "$LISTNAME-admin:        \"|$MAILMAN_DIR/mail/mailman admin $LISTNAME\"" >> $ALIAS
  echo "$LISTNAME-bounces:      \"|$MAILMAN_DIR/mail/mailman bounces $LISTNAME\"" >> $ALIAS
  echo "$LISTNAME-confirm:      \"|$MAILMAN_DIR/mail/mailman confirm $LISTNAME\"" >> $ALIAS
  echo "$LISTNAME-join:         \"|$MAILMAN_DIR/mail/mailman join $LISTNAME\"" >> $ALIAS
  echo "$LISTNAME-leave:        \"|$MAILMAN_DIR/mail/mailman leave $LISTNAME\"" >> $ALIAS
  echo "$LISTNAME-owner:        \"|$MAILMAN_DIR/mail/mailman owner $LISTNAME\"" >> $ALIAS
  echo "$LISTNAME-request:      \"|$MAILMAN_DIR/mail/mailman request $LISTNAME\"" >> $ALIAS
  echo "$LISTNAME-subscribe:    \"|$MAILMAN_DIR/mail/mailman subscribe $LISTNAME\"" >> $ALIAS
  echo "$LISTNAME-unsubscribe:  \"|$MAILMAN_DIR/mail/mailman unsubscribe $LISTNAME\"" >> $ALIAS

  echo Rebuilding $VIRT
  $MAKEMAP hash $VIRTDB < $VIRT

  echo Rebuilding $ALIAS
  $MAKEMAP hash $ALIASDB < $ALIAS

  echo All entries for list $LISTNAME are completed. You may now add the list
  echo $LISTNAME via the Mailman UI.
fi
Personal tools