#!/bin/sh
# WARNING: This file was auto-generated. Do not edit!
EZPATH='/usr/local/bin'

# Stupid script to create a list and a digest list. The digest list
# is stored in DIR-digest and called list-digest.
# DIR dot local host digcode: see ezmlm-make.1
# owner: address for remote administrator

ECHO='echo'
CUT='cut'
REV='rev'
EZMAKE="${EZPATH}/ezmlm-make"
EZSUB="${EZPATH}/ezmlm-sub"
FATAL='ezmlm-both: fatal:'
USAGE='ezmlm-both DIR dot local host digcode owner'

# will fail if cut & rev are not available, resulting in DIR=$1 & DOT=$2
# so still ok.

# remove trailing '/' from dir and dot if there is one
  DIR=`${ECHO} $1 | ${REV} | ${CUT} -c1`
  if [ "$DIR" = "/" ]; then
	DIR=`${ECHO} $1 | ${REV} | ${CUT} -c2- |${REV}`
  else
	DIR="$1"
  fi

  DOT=`${ECHO} $2 | ${REV} | ${CUT} -c1`
  if [ "$DOT" = "/" ]; then
	DOT=`${ECHO} $2 | ${REV} | ${CUT} -c2- |${REV}`
  else
	DOT="$2"
  fi

if [ ! -x "$EZMAKE" ]; then
	${ECHO} "$FATAL Please correct the ezmlm-make path in the script"
	exit 100
fi

if [ ! -x "$EZSUB" ]; then
	${ECHO} "$FATAL Please correct the ezmlm-sub path in the script"
	exit 100
fi

if [ -z "$5" ]; then
	${ECHO} "$FATAL $USAGE"
	exit 100
fi

if [ -n "$6" ]; then
	SW1="-rm"
	SW2="-r"
else
	SW1="-RM"
	SW2="-R"
fi

# main list with remote admin: add switches for moderation, etc
# The digest list is non-archived/indexed
${EZMAKE} -dug -5 "$6" "$SW1" "$1" "$2" "$3" "$4" "$5" \
        || { ${ECHO} "${FATAL} list creation failed" && exit 100 ; }

if [ -n "$6" ]; then
	${EZSUB} "$DIR/mod" "$6" || \
	{ ${ECHO} "${FATAL} failed to add $6 as remote admin for $3@$4" && \
		exit 100 ; }
	${EZSUB} "$DIR" "$6" || \
	{ ${ECHO} "${FATAL} failed to add $6 as a list subscriber" && \
		exit 100 ; }
	${EZSUB} "$DIR/digest" "$6" || \
	{ ${ECHO} "${FATAL} failed to add $6 as a digest list subscriber" && \
		exit 100 ; }
fi

${ECHO}
${ECHO} "Created list:        $3@$4"
${ECHO} "and digest list:     $3-digest@$4"
if [ -n "$6" ]; then
	${ECHO}
	${ECHO} "$6 is a remote admin and subscriber of both."
	${ECHO}
fi
${ECHO} "To add non-subscribers, that should be allowed to post:"
${ECHO} "  % ezmlm-sub $1/extra addr1@host1 addr2@host2 ..."
${ECHO}
${ECHO} "Make sure the user receiving mail owns the list directories"
${ECHO} "and their contents. If not, please:"
${ECHO} "  % chown -R user $DIRt"
${ECHO} "  % chown -R group $DIR"
${ECHO}
${ECHO} "[Posting restrictions based on SENDER should keep spam off"
${ECHO} "your list. However, SENDERs are easy to fake.]"
${ECHO}
${ECHO} "Digest will be sent after message 1, then when more than 30 messages,"
${ECHO} " 64 kbytes message body, or 24 h have passed since the last digest."
${ECHO}
if [ -n "$6" ]; then
  ${ECHO} "To enable $6 to get a subscriber list with the -list"
  ${ECHO} "command and to edit text files with the -edit command:"
  ${ECHO} "  % ezmlm-make -emrldn $DIR"
  ${ECHO}
fi
exit 0
