From 424c099100e9e0f7982d56f61eb2ba08c299192e Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Sat, 17 Feb 2018 12:45:18 +0000 Subject: Overhaul default hosts configuration. - When no virtualhosts are defined, and the default localhost/localhost is effective, the post-install script now adds DEFAULT_EMAIL_HOST, DEFAULT_URL_HOST, and add_virtualhost() lines to mm_cfg.py. Add corresponding support to remove unchanged configurations to the deinstall script. - While here, overhaul crontab configuration to only request a merge if the crontab had been modified, and unify progress reports. - Merge pkg-deinstall into pkg-install, to avoid duplication of code that might be missed in later maintenance. PR: 225961 Reported by: Terry Kennedy --- UPDATING | 10 ++- mail/mailman/Makefile | 5 +- mail/mailman/files/FreeBSD-post-install-notes | 10 +-- mail/mailman/files/mailman.in | 4 +- mail/mailman/files/pkg-deinstall.in | 59 --------------- mail/mailman/files/pkg-install.in | 102 +++++++++++++++++++++++--- 6 files changed, 110 insertions(+), 80 deletions(-) delete mode 100644 mail/mailman/files/pkg-deinstall.in diff --git a/UPDATING b/UPDATING index dd2074c5d053..2555946dca19 100644 --- a/UPDATING +++ b/UPDATING @@ -70,12 +70,18 @@ you update your ports collection, before attempting any port upgrades. and DEFAULT_URL_HOST to "localhost" statically, and the rc script will check this and refuse to start on next boot. - Users must configure DEFAULT_EMAIL_HOST and DEFAULT_URL_HOST in - Mailman/mm_cfg.py properly. + Users must configure DEFAULT_EMAIL_HOST and DEFAULT_URL_HOST in + Mailman/mm_cfg.py properly and add this line below: + add_virtualhost(DEFAULT_URL_HOST, DEFAULT_EMAIL_HOST) A short example has been added to: ${PREFIX}/local/share/doc/mailman/FreeBSD-post-install-notes. + As of 2.1.26_3, the post-install script will add back the prior + default settings to mm_cfg.py (instead of Defaults.py) if no + virtual hosts have been defined, to cover the normal use cases + and initial installation. + 20180201: AFFECTS: users of editors/emacs* and all ports using Emacs via USES=emacs AUTHOR: jrm@FreeBSD.org diff --git a/mail/mailman/Makefile b/mail/mailman/Makefile index 7c67a5bf5bb5..f210a2b28822 100644 --- a/mail/mailman/Makefile +++ b/mail/mailman/Makefile @@ -3,7 +3,7 @@ PORTNAME= mailman DISTVERSION= 2.1.26 -PORTREVISION= 2 +PORTREVISION= 3 CATEGORIES= mail MASTER_SITES= GNU \ SF/${PORTNAME}/Mailman%202.1%20%28stable%29/${PORTVERSION} \ @@ -57,8 +57,9 @@ GROUPS= ${MM_GROUPNAME} MAILMANDIR= ${PREFIX}/${MM_DIR} PLIST_SUB= MMDIR=${MM_DIR} IMGDIR=${IMGDIR} MM_USERNAME=${MM_USERNAME} MM_GROUPNAME=${MM_GROUPNAME} -SUB_FILES= pkg-message pkg-install pkg-deinstall mailman.newsyslog.sample +SUB_FILES= pkg-message pkg-install mailman.newsyslog.sample SUB_LIST= MAILMANDIR=${MAILMANDIR} USER=${MM_USERNAME} GROUP=${MM_GROUPNAME} PYTHON_CMD="${PYTHON_CMD}" +PKGDEINSTALL= ${PKGINSTALL} PORTDOCS= ACKNOWLEDGMENTS BUGS FAQ INSTALL NEWS README README-I18N.en \ README.CONTRIB README.NETSCAPE \ diff --git a/mail/mailman/files/FreeBSD-post-install-notes b/mail/mailman/files/FreeBSD-post-install-notes index 020d833b015a..9d99b7accaa2 100644 --- a/mail/mailman/files/FreeBSD-post-install-notes +++ b/mail/mailman/files/FreeBSD-post-install-notes @@ -38,11 +38,11 @@ package) can help with that. many of the steps you may read about in these files. Also, not everything in these files is necessarily relevant to the FreeBSD port. - In most cases, you will want to override the host name settings (which - default to 'localhost') by adding these lines to Mailman/mm_cfg.py: - (the documentation is in Mailman/Defaults.py, but you need to override - the defaults in mm_cfg.py instead, changes to Defaults.py are lost on - upgrades): + In most cases, you need to override the host name settings (which + default to 'localhost') by adding or changing these lines to/in + Mailman/mm_cfg.py: (the documentation is in Mailman/Defaults.py, but you + need to override the defaults in mm_cfg.py instead, changes to Defaults.py + are lost on upgrades): # adjust and add this to Mailman/mm_cfg.py: DEFAULT_URL_HOST = 'CHANGE_ME.example.org' diff --git a/mail/mailman/files/mailman.in b/mail/mailman/files/mailman.in index 8efe3a675309..70dcec2eec9d 100644 --- a/mail/mailman/files/mailman.in +++ b/mail/mailman/files/mailman.in @@ -51,8 +51,8 @@ mailman_prestart() { ### check if the default configuration is plausible vhosts=$(PYTHONPATH="%%MAILMANDIR%%/bin" "%%PYTHON_CMD%%" -c 'import paths;from Mailman import mm_cfg;_x=dict(mm_cfg.VIRTUAL_HOSTS);print repr(_x);') if [ "${vhosts}" = "{'localhost': 'localhost'}" ] ; then - warn 'Be sure to change the default hosts in Mailman/mm_cfg.py!' - warn 'Review %%DOCSDIR%%/FreeBSD-post-install-notes for instructions.' + warn 'No DEFAULT or virtual hosts configured.' + warn 'Review %%DOCSDIR%%/FreeBSD-post-install-notes #1 for instructions.' if ! checkyesno mailman_run_localhost ; then err 78 "Start of mailman refused due to insufficient configuration." fi diff --git a/mail/mailman/files/pkg-deinstall.in b/mail/mailman/files/pkg-deinstall.in deleted file mode 100644 index 55725c4ea22a..000000000000 --- a/mail/mailman/files/pkg-deinstall.in +++ /dev/null @@ -1,59 +0,0 @@ -#! /bin/sh -# -# $FreeBSD$ - -PATH=/bin:/usr/bin:/usr/sbin - -case "$2" in -DEINSTALL) - echo "---> Starting deinstall script" - - if /usr/bin/crontab -u "%%USER%%" -l | \ - /usr/bin/diff -B -b - "%%MAILMANDIR%%/cron/crontab.in" >/dev/null 2>&1 ; then - echo "---> Zeroing crontab for \"%%USER%%\"" - /usr/bin/crontab -u "%%USER%%" -r /var/cron/allow.new$$ - mv /var/cron/allow.new$$ /var/cron/allow - fi - else - echo "---> Crontab for \"%%USER%%\" modified, not removed: please deinstall" - echo "---> it manually if you no longer wish to use Mailman. E.g.:" - echo "---> /usr/bin/crontab -u \"%%USER%%\" -r" - fi - - echo "---> Preserving the \"last_mailman_version\" file" - /bin/mv -f "%%MAILMANDIR%%/data/last_mailman_version" /var/tmp/ || : - - # If the errorlog is the only existing logfile, delete it. (If Mailman's - # qrunner had not been running, then the process of trying to stop the - # qrunner (above) will cause the errorlog to be written to. Hence, even if - # the Mailman port/package is installed and immediately deinstalled, the - # errorlog will exist.) - if [ "`echo %%MAILMANDIR%%/logs/*`" = "%%MAILMANDIR%%/logs/error" ]; then - echo "---> Deleting errorlog (It is the only existing logfile.)" - /bin/rm -f "%%MAILMANDIR%%/logs/error" - fi - - # attempt removal, but do not care if it is not empty - /bin/rmdir "%%MAILMANDIR%%/archives/private/" 2>/dev/null || : - ;; - -POST-DEINSTALL) - echo "---> Starting post-deinstall script" - - set -- "%%MAILMANDIR%%/lists"/* - if [ $# -gt 1 ] || [ "x$1" != "x%%MAILMANDIR%%/lists/*" ] ; then - echo '---> %%MAILMANDIR%%/lists is not empty - this installation may have active lists! Listing max. 10:' - find "%%MAILMANDIR%%/lists" -mindepth 1 -maxdepth 1 | head -n 10 || : - echo "---> Restoring \"last_mailman_version\" file" - if test -d "%%MAILMANDIR%%" ; then - /bin/mkdir -p "%%MAILMANDIR%%/data" && \ - /bin/mv -f /var/tmp/last_mailman_version "%%MAILMANDIR%%/data/" - else - /bin/rm -f /var/tmp/last_mailman_version - fi - fi - - ;; -esac diff --git a/mail/mailman/files/pkg-install.in b/mail/mailman/files/pkg-install.in index 90d4f0584318..8aa1bc79a1fa 100644 --- a/mail/mailman/files/pkg-install.in +++ b/mail/mailman/files/pkg-install.in @@ -19,18 +19,28 @@ check_rcfile_fix_perms() { ) } +add_default_virtuals() { + cat >>"$1" <<_EOF + +# This and the next three lines added by FreeBSD's post-install script +DEFAULT_EMAIL_HOST="$(hostname -f)" +DEFAULT_URL_HOST="$(hostname -f)" +add_virtualhost(DEFAULT_URL_HOST, DEFAULT_EMAIL_HOST) + +_EOF +} + set -e -case "$2" in +MYTMP="$(mktemp -d "${TMPDIR-/tmp}/mminstall.XXXXXXXXXX")" +trap "rm -rf \"$MYTMP\"" EXIT +case "$2" in POST-INSTALL) echo "---> Starting post-install script" LC_ALL=C export LC_ALL - MYTMP="$(mktemp -d "${TMPDIR-/tmp}/mminstall.XXXXXXXXXX")" - trap "rm -rf \"$MYTMP\"" EXIT - - # fix up permissions - this is under investigation; pkg or libarchive + # fix up permissions - this is under investigation; pkg or libarchive # goof up the group writable and/or setgid bits /usr/bin/find "%%MAILMANDIR%%/qfiles" -maxdepth 1 -type d -exec \ /bin/chmod u+rwx,g+rwsx,o-w "{}" + @@ -83,17 +93,18 @@ POST-INSTALL) printf '%s\n' "%%USER%%" >> /var/cron/allow fi - if /usr/bin/crontab -u "%%USER%%" -l >"$MYTMP/crontab" 2>&1 ; then - if test -s "$MYTMP/crontab"; then - echo "---> \"%%USER%%\" already has a crontab. Not overwriting it" - echo "---> Please merge any changes from the standard crontab file" + if /usr/bin/crontab -u "%%USER%%" -l >"$MYTMP/crontab" ; then + if test -s "$MYTMP/crontab" && ! cmp -s "$MYTMP/crontab" "%%MAILMANDIR%%/cron/crontab.in"; then + echo "---> User \"%%USER%%\" already has a non-default crontab." + echo "---> Not overwriting it." + echo "---> Please review and merge any changes from the standard crontab file" echo "---> %%MAILMANDIR%%/cron/crontab.in" else echo "---> Installing crontab(5) file for user \"%%USER%%\"" /usr/bin/crontab -u "%%USER%%" "%%MAILMANDIR%%/cron/crontab.in" fi else - echo "---> Creating crontab(5) file for user \"%%USER%%\"" + echo "---> Installing crontab(5) file for user \"%%USER%%\"" /usr/bin/crontab -u "%%USER%%" "%%MAILMANDIR%%/cron/crontab.in" fi rm -f "$MYTMP/crontab" @@ -106,6 +117,14 @@ POST-INSTALL) echo "---> rcfile sets mailman_fix_perms to no, skipping check_perms" fi + # check if we need to add our hostname to the configuration: + if cmp -s "%%MAILMANDIR%%/Mailman/mm_cfg.py" "%%MAILMANDIR%%/Mailman/mm_cfg.py.dist" \ + || test "{'localhost': 'localhost'}" = "$(PYTHONPATH="%%MAILMANDIR%%/bin" "%%PYTHON_CMD%%" -c 'import paths;from Mailman import mm_cfg;_x=dict(mm_cfg.VIRTUAL_HOSTS);print repr(_x);')" + then + echo "---> adding default host configuration to %%MAILMANDIR%%/Mailman/mm_cfg.py." + add_default_virtuals "%%MAILMANDIR%%/Mailman/mm_cfg.py" + fi + echo "---> Running assorted other checks" if egrep -q "^[ \t]*MTA.*=.*Postfix" "%%MAILMANDIR%%/Mailman/mm_cfg.py" ; then # run Postfix-specific checks @@ -122,4 +141,67 @@ POST-INSTALL) fi fi ;; + + ####### DEINSTALLATION PART ####### + +DEINSTALL) + echo "---> Starting deinstall script" + + if /usr/bin/crontab -u "%%USER%%" -l | \ + /usr/bin/diff -B -b - "%%MAILMANDIR%%/cron/crontab.in" >/dev/null 2>&1 ; then + echo "---> Zeroing unchanged crontab for \"%%USER%%\"" + /usr/bin/crontab -u "%%USER%%" -r /var/cron/allow.new$$ + mv /var/cron/allow.new$$ /var/cron/allow + fi + else + echo "---> Crontab for \"%%USER%%\" modified, not removed: please deinstall" + echo "---> it manually if you no longer wish to use Mailman. E.g.:" + echo "---> /usr/bin/crontab -u \"%%USER%%\" -r" + fi + + echo "---> Preserving the \"last_mailman_version\" file" + /bin/mv -f "%%MAILMANDIR%%/data/last_mailman_version" /var/tmp/ || : + + # If the errorlog is the only existing logfile, delete it. (If Mailman's + # qrunner had not been running, then the process of trying to stop the + # qrunner (above) will cause the errorlog to be written to. Hence, even if + # the Mailman port/package is installed and immediately deinstalled, the + # errorlog will exist.) + if [ "`echo %%MAILMANDIR%%/logs/*`" = "%%MAILMANDIR%%/logs/error" ]; then + echo "---> Deleting errorlog (It is the only existing logfile.)" + /bin/rm -f "%%MAILMANDIR%%/logs/error" + fi + + # attempt removal, but do not care if it is not empty + /bin/rmdir "%%MAILMANDIR%%/archives/private/" 2>/dev/null || : + + # if configuration is unchanged, remove it explicitly, + # @sample wouldn't work because we added our hostname + cat "%%MAILMANDIR%%/Mailman/mm_cfg.py.dist" >"$MYTMP/mm_cfg.tmp" + add_default_virtuals "$MYTMP/mm_cfg.tmp" + if cmp -s "%%MAILMANDIR%%/Mailman/mm_cfg.py" "$MYTMP/mm_cfg.tmp" ; then + echo "---> Removing default configuration file." + rm -f "%%MAILMANDIR%%/Mailman/mm_cfg.py" + fi + ;; + +POST-DEINSTALL) + echo "---> Starting post-deinstall script" + + set -- "%%MAILMANDIR%%/lists"/* + if [ $# -gt 1 ] || [ "x$1" != "x%%MAILMANDIR%%/lists/*" ] ; then + echo '---> %%MAILMANDIR%%/lists is not empty - this installation may have active lists! Listing max. 10:' + find "%%MAILMANDIR%%/lists" -mindepth 1 -maxdepth 1 | head -n 10 || : + echo "---> Restoring \"last_mailman_version\" file" + if test -d "%%MAILMANDIR%%" ; then + /bin/mkdir -p "%%MAILMANDIR%%/data" && \ + /bin/mv -f /var/tmp/last_mailman_version "%%MAILMANDIR%%/data/" + else + /bin/rm -f /var/tmp/last_mailman_version + fi + fi + + ;; esac -- cgit v1.2.3