-#!/bin/sh -e
+#!/bin/bash -e
#
# Make a new mailing list. Run as root on deleuze.
#
-# Usage: listnew LISTNAME LISTDOMAIN USER RANDOM_PASSWORD
+# Usage: listnew LISTNAME LISTDOMAIN LISTURL USER INITIAL_PASSWORD
BIN=/var/lib/mailman/bin
-DEFAULT_URL=https://lists.hcoop.net
-sudo -u list $BIN/newlist $1@$2 $3@hcoop.net $4 </dev/null
+function usage() {
+ echo "Usage: listnew list_name domain list_url user initial_password"
+}
+
+if test -n "$6"; then
+ echo "Too many arguments"
+ usage
+ exit 1
+elif test -z "$5"; then
+ echo "Not enough arguments"
+ usage
+ exit 1
+elif test "$UID" != "0"; then
+ echo "This program must be run as root"
+ usage
+ exit 1
+else
+ LIST_NAME=$1
+ LIST_DOMAIN=$2
+ LIST_URL=$3
+ LIST_USER=$4
+ LIST_PASS=$5
+fi
+
+# If DOMAIN is hcoop.net, force it to be lists.hcoop.net.
+if test "$LIST_DOMAIN" = "hcoop.net"; then
+ LIST_DOMAIN=lists.hcoop.net
+fi
+
+sudo -u list $BIN/newlist \
+ $LIST_NAME@$LIST_DOMAIN $LIST_USER@hcoop.net $LIST_PASS </dev/null
# By default, use our list admin website for the public interface.
# This can be changed after the user has set up their mailMan
# directive. We do this because the default is
# http://lists.hcoop.net, without SSL, which makes list admin not work
# at all.
-/afs/hcoop.net/common/etc/scripts/change-list-url $1 $DEFAULT_URL
+/afs/hcoop.net/common/etc/scripts/change-list-url $LIST_NAME $LIST_URL
-echo "Sucessfully created list $1"
+echo "Sucessfully created list $LIST_NAME"