From: Siva Mahadevan Date: Wed, 14 Jun 2023 03:30:32 +0000 (-0400) Subject: mlmmj-make-ml: implement non-interactive mailing list creation X-Git-Tag: RELEASE_1_4_0rc1~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d839af843cdb703ec710fa5f6e69bee947e02fc1;p=thirdparty%2Fmlmmj.git mlmmj-make-ml: implement non-interactive mailing list creation --- diff --git a/src/mlmmj-make-ml.in b/src/mlmmj-make-ml.in index 273a0b0d..f74699a8 100755 --- a/src/mlmmj-make-ml.in +++ b/src/mlmmj-make-ml.in @@ -3,39 +3,62 @@ # mlmmj-make-ml - henne@hennevogel.de # -VERSION="0.1" -DEFAULTDIR="/var/spool/mlmmj" +VERSION="0.2" ALIASFILE=/etc/aliases +CRONTAB=/etc/crontab +TEXTLIBDIR="@textlibdir@" USAGE="mlmmj-make-ml $VERSION -$0 - [-h] [-L listname] [-s spooldir] [-a] [-c user] [-z] - -h: display this help text - -L: the name of the mailing list - -s: your spool directory (default $DEFAULTDIR) + +$0 + +options: + -L listname: the name of the mailing list -a: create the needed entries in your $ALIASFILE file - -c: user to chown the spool directory to (default not to chown at all) + -b: add needed entry to $CRONTAB + -c user: user to chown the spool directory to + -d fqdn: fully qualified domain name of the mailing list + -f answerfile: use answerfile to create mailing list non-interactively + -h: display this help text + -n answerfile: Do nothing. Instead, create answer file for later non-interactive use with -f + -s spooldir: mlmmj spool directory + -t lang: list text directory relative to $TEXTLIBDIR for given language " -while getopts ":hL:s:ac:" Option +while getopts ":L:abc:d:f:hn:s:t:" Option do case "$Option" in + L ) + LISTNAME="$OPTARG" + ;; + a ) + ADDALIAS="y" + ;; + b ) + ADDCRON="y" + ;; + c ) + DO_CHOWN="y" + CHOWN="$OPTARG" + ;; + d ) + FQDN="$OPTARG" + ;; + f ) + ANSWERFILEIN="$OPTARG" + ;; h ) echo "$USAGE" exit 0 ;; - L ) - LISTNAME="$OPTARG" + n ) + ANSWERFILEOUT="$OPTARG" ;; s ) SPOOLDIR="$OPTARG" ;; - a ) - A_CREATE="YES" - ;; - c ) - DO_CHOWN=1 - CHOWN="$OPTARG" + t ) + TEXTLANG="$OPTARG" ;; * ) echo "$0: invalid option" @@ -46,87 +69,77 @@ done SHIFTVAL=$((OPTIND-1)) shift $SHIFTVAL -if [ -z "$SPOOLDIR" ]; then - SPOOLDIR="$DEFAULTDIR" +if [ -r "$ANSWERFILEIN" ]; then + # shellcheck source=/dev/null + . "$ANSWERFILEIN" fi -echo "Creating Directories below $SPOOLDIR. Use '-s spooldir' to change" +if [ ! -d "$SPOOLDIR" ]; then + SPOOLDIRDEF=/var/spool/mlmmj + printf 'mlmmj spool directory under which to create new mailing list [%s] : ' "$SPOOLDIRDEF" + read -r SPOOLDIR + if [ ! -d "$SPOOLDIR" ]; then + SPOOLDIR="$SPOOLDIRDEF" + fi +fi if [ -z "$LISTNAME" ]; then - printf 'What should the name of the Mailinglist be? [mlmmj-test] : ' + LISTNAMEDEF="mlmmj-test" + printf 'What should the name of the Mailinglist be? [%s] : ' "$LISTNAMEDEF" read -r LISTNAME if [ -z "$LISTNAME" ]; then - LISTNAME="mlmmj-test" + LISTNAME="$LISTNAMEDEF" fi fi - LISTDIR="$SPOOLDIR/$LISTNAME" -mkdir -p "$LISTDIR" - -for DIR in incoming queue queue/discarded archive text subconf unsubconf \ - bounce control moderation subscribers.d digesters.d requeue \ - nomailsubs.d -do - mkdir "$LISTDIR/$DIR" -done - -test -f "$LISTDIR/index" || touch "$LISTDIR/index" - -printf 'The Domain for the List? [] : ' -read -r FQDN if [ -z "$FQDN" ]; then - FQDN="$(domainname -f)" + printf 'The Fully Qualified Domain Name (FQDN) for the List? [] : ' + read -r FQDN + if [ -z "$FQDN" ]; then + FQDN="$(domainname -f)" + fi fi -printf 'The emailaddress of the list owner? [postmaster] : ' -read -r OWNER if [ -z "$OWNER" ]; then - OWNER="postmaster" + OWNERDEF="postmaster" + printf 'The emailaddress of the list owner? [%s] : ' "$OWNERDEF" + read -r OWNER + if [ -z "$OWNER" ]; then + OWNER="$OWNERDEF" + fi fi -echo "$OWNER" > "$LISTDIR/control/owner" -TEXTLIBDIR="@textlibdir@" +if [ -d "$TEXTLIBDIR" ]; then + if [ -z "$TEXTLANG" ]; then + cat <&2 - exit 1 -fi +You can choose between the following languages for the list texts. -echo -echo "For the list texts you can choose between the following languages or" -echo "give a absolute path to a directory containing the texts." -echo -echo "Available languages:" -ls "$TEXTLIBDIR" - -TEXTPATHDEF=en -printf 'The path to texts for the list? [%s] : ' $TEXTPATHDEF -read -r TEXTPATHIN -if [ -z "$TEXTPATHIN" ] ; then - TEXTPATH="$TEXTPATHDEF" -else - TEXTPATH="$TEXTPATHIN" -fi +Available languages: +EOF + ls "$TEXTLIBDIR" -case "$TEXTPATH" in - /*) ;; - *) - TEXTPATH="$TEXTLIBDIR/$TEXTPATH" -esac + TEXTLANGDEF=en + printf 'mailing list texts language? [%s] : ' $TEXTLANGDEF + read -r TEXTLANG + if [ -z "$TEXTLANG" ] ; then + TEXTLANG="$TEXTLANGDEF" + fi + fi -if [ -d "$TEXTPATH" ]; then - cp "$TEXTPATH"/* "$LISTDIR/text" + TEXTPATH="$TEXTLIBDIR/$TEXTLANG" else - echo - echo "**NOTE** Could not copy the texts for the list" - echo "Please manually copy the files from the listtexts/ directory" - echo "in the source distribution of mlmmj." - sleep 2 + cat < "$LISTDIR/control/listaddress" MLMMJRECEIVE=$(which mlmmj-receive 2>/dev/null) if [ -z "$MLMMJRECEIVE" ]; then @@ -138,55 +151,107 @@ if [ -z "$MLMMJMAINTD" ]; then MLMMJMAINTD="/path/to/mlmmj-maintd" fi -ALIAS="$LISTNAME: \"|$MLMMJRECEIVE -L $SPOOLDIR/$LISTNAME/\"" -CRONENTRY="0 */2 * * * \"$MLMMJMAINTD -F -L $SPOOLDIR/$LISTNAME/\"" +ALIAS="$LISTNAME: \"|$MLMMJRECEIVE -L $LISTDIR/\"" +CRONENTRY="0 */2 * * * \"$MLMMJMAINTD -F -L $LISTDIR/\"" -if [ -n "$A_CREATE" ]; then - echo "I want to add the following to your $ALIASFILE file:" - echo "$ALIAS" - printf 'is this ok? [y/N] : ' - read -r OKIDOKI - case $OKIDOKI in - y|Y) - echo "$ALIAS" >> $ALIASFILE - ;; - n|N) - exit 0 - ;; - *) - echo "Options was: y, Y, n or N" - esac -else - echo - echo "Don't forget to add this to $ALIASFILE:" - echo "$ALIAS" +if [ -z "$ADDALIAS" ]; then + cat < "$ANSWERFILEOUT" < "$LISTDIR/control/owner" + echo "$LISTADDRESS" > "$LISTDIR/control/listaddress" + + if [ -d "$TEXTPATH" ]; then + cp "$TEXTPATH"/* "$LISTDIR/text" + else + echo "WARNING: List text language '$TEXTLANG' not found." + echo "Proceeding without copying list texts." + fi + + case "$ADDALIAS" in y|Y) - chown -R "$CHOWN" "$SPOOLDIR/$LISTNAME" - ;; - n|N) - exit 0 - ;; - *) - echo "option is: y, Y, n, N" - ;; + echo "$ALIAS" >> $ALIASFILE esac + + case "$DO_CHOWN" in + y|Y) + if [ -n "$CHOWN" ]; then + chown -R "$CHOWN" "$LISTDIR" + fi + esac + + case "$ADDCRON" in + y|Y) + echo "$CRONENTRY" >> $CRONTAB + esac + + echo + echo "Mailing list $LISTDIR was created successfully." fi -echo -echo "If you're not starting mlmmj-maintd in daemon mode," -echo "don't forget to add this to your crontab:" -echo "$CRONENTRY" +cat <