ports/56450: [PATCH] port mail/exim: use rc.subr(8) start/stop script, add daily maintainance scripts

Oliver Eikemeier eikemeier at fillmore-labs.com
Thu Sep 4 17:00:37 UTC 2003


>Number:         56450
>Category:       ports
>Synopsis:       [PATCH] port mail/exim: use rc.subr(8) start/stop script, add daily maintainance scripts
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 04 10:00:33 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Oliver Eikemeier
>Release:        FreeBSD 4.8-STABLE i386
>Organization:
Fillmore Labs - http://www.fillmore-labs.com
>Environment:
System: FreeBSD nuuk.fillmore-labs.com 4.8-STABLE

>Description:

- use a rc.subr(8) start/stop script
  * Don't forget to add 'enable_exim="YES' to rc.conf(5) *
- contributed daily scripts 150.exim-tidydb and 460.exim-mail-rejects,
  analogous to 150.clean-hoststat and 460.status-mail-rejects
- replace literal '${PREFIX}' by the real prefix in generated documentation
- generate a default ${PREFIX}/etc/exim/configure
- stop exim when deleting the package
- bump PORTREVISION

one step closer to make exim a real sendmail replacement on FreeBSD:
a patch to sysinstall will be posted seperately

>How-To-Repeat:
>Fix:

--- exim-rc.subr.patch begins here ---
diff -Nur mail/exim/Makefile.orig mail/exim/Makefile
--- mail/exim/Makefile.orig	Thu Sep  4 16:56:00 2003
+++ mail/exim/Makefile	Thu Sep  4 18:50:15 2003
@@ -7,7 +7,7 @@
 
 PORTNAME=	exim
 PORTVERSION=	4.22
-PORTREVISION=	3
+PORTREVISION=	4
 CATEGORIES=	mail
 MASTER_SITES=	${MASTER_SITE_EXIM}
 MASTER_SITE_SUBDIR=	exim4
@@ -29,12 +29,16 @@
 USE_PERL5=	yes
 MAN8=		exim.8
 
+DAILY_SCRIPTS=	150.exim-tidydb 460.exim-mail-rejects
+
 EXISCAN_ACL_VERSION=	${PORTVERSION}-12
 
 PLIST_SUB+=	EXIM_VERSION="${PORTVERSION}"
 
 .if defined(NOPORTDOCS)
 PKGMESSAGE=	${WRKDIR}/POST-INSTALL-NOTES
+.else
+PKGMESSAGE=	${WRKDIR}/pkg-message
 .endif
 
 MAKE_ENV+=	OSTYPE=${OPSYS} ARCHTYPE=${MACHINE_ARCH} LOCALBASE=${LOCALBASE}
@@ -135,6 +139,25 @@
 
 .include <bsd.port.pre.mk>
 
+.if ${OSVERSION} >= 500038
+RC_SUBR?=	${DESTDIR}/etc/rc.subr
+RC_DIR=		${DESTDIR}/etc/rc.d
+RC_SUFX=
+.else
+USE_RC_SUBR=	yes
+RC_DIR=		${PREFIX}/etc/rc.d
+RC_SUFX=	.sh
+.endif
+
+SED_SCRIPT=	-e 's,%%PREFIX%%,${PREFIX},g' \
+		-e 's,%%DOCSDIR%%,${DOCSDIR},g' \
+		-e 's,%%RC_SUBR%%,${RC_SUBR},g' \
+		-e 's,%%RC_DIR%%,${RC_DIR},g' \
+		-e 's,%%RC_SUFX%%,${RC_SUFX},g'
+
+PLIST_SUB+=	RC_DIR=${RC_DIR} \
+		RC_SUFX=${RC_SUFX}
+
 PORTDOC_FILES=	Exim3.upgrade Exim4.upgrade OptionLists.txt README \
 		dbm.discuss.txt filter.txt pcrepattern.txt pcretest.txt \
 		spec.txt
@@ -326,28 +349,39 @@
 	@${ECHO} ''
 .endif
 
-post-patch:
+do-configure:
+	${MKDIR} ${WRKSRC}/Local
+	${SED} ${SEDLIST} ${WRKSRC}/src/EDITME > ${WRKSRC}/Local/Makefile
+
+post-build:
+.for script in exim ${DAILY_SCRIPTS}
+	@${SED} ${SED_SCRIPT} ${FILESDIR}/${script}.sh > ${WRKDIR}/${script}.sh
+.endfor
 .if !defined(WITHOUT_EXISCAN)
-	@${CAT} ${FILESDIR}/POST-INSTALL-NOTES.exiscan-acl \
+	@${SED} ${SED_SCRIPT} ${FILESDIR}/POST-INSTALL-NOTES.exiscan-acl \
 	    ${FILESDIR}/POST-INSTALL-NOTES > ${WRKDIR}/POST-INSTALL-NOTES
+	@${SED} ${SED_SCRIPT} ${FILESDIR}/POST-INSTALL-NOTES.clamd > ${WRKDIR}/POST-INSTALL-NOTES.clamd
 .else
-	@${CAT} ${FILESDIR}/POST-INSTALL-NOTES > ${WRKDIR}/POST-INSTALL-NOTES
+	@${SED} ${SED_SCRIPT} ${FILESDIR}/POST-INSTALL-NOTES > ${WRKDIR}/POST-INSTALL-NOTES
 .endif
-
-do-configure:
-	${MKDIR} ${WRKSRC}/Local
-	${SED} ${SEDLIST} < ${WRKSRC}/src/EDITME > ${WRKSRC}/Local/Makefile
+	@${SED} ${SED_SCRIPT} ${MASTERDIR}/pkg-message > ${WRKDIR}/pkg-message
 
 pre-install:
 	@PKG_PREFIX="${PREFIX}" ${SH} ${PKGINSTALL} ${PKGNAME} PRE-INSTALL
 
 post-install:
-	${INSTALL_SCRIPT} ${FILESDIR}/exim.sh ${PREFIX}/etc/rc.d
+	@${INSTALL_SCRIPT} ${WRKDIR}/exim.sh ${RC_DIR}/exim${RC_SUFX}
+	@${MKDIR} ${PREFIX}/etc/periodic/daily
+.for script in ${DAILY_SCRIPTS}
+	@${INSTALL_SCRIPT} ${WRKDIR}/${script}.sh ${PREFIX}/etc/periodic/daily/${script}
+.endfor
+	@[ -f ${PREFIX}/etc/exim/configure ] || \
+		${CP} ${PREFIX}/etc/exim/configure.default ${PREFIX}/etc/exim/configure
 .if !defined(NOPORTDOCS)
 	${MKDIR} ${DOCSDIR}
 	${INSTALL_DATA} ${WRKDIR}/POST-INSTALL-NOTES ${DOCSDIR}
 .if !defined(WITHOUT_EXISCAN)
-	${INSTALL_DATA} ${FILESDIR}/POST-INSTALL-NOTES.clamd ${DOCSDIR}
+	${INSTALL_DATA} ${WRKDIR}/POST-INSTALL-NOTES.clamd ${DOCSDIR}
 .endif
 .for docfile in ${PORTDOC_FILES}
 	${INSTALL_DATA} ${WRKSRC}/doc/${docfile} ${DOCSDIR}
diff -Nur mail/exim/files/150.exim-tidydb.sh.orig mail/exim/files/150.exim-tidydb.sh
--- mail/exim/files/150.exim-tidydb.sh.orig	Thu Jan  1 01:00:00 1970
+++ mail/exim/files/150.exim-tidydb.sh	Thu Sep  4 18:27:05 2003
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+# Exim hints database maintenance
+# 
+#   contributed by: Oliver Eikemeier <eikemeier at fillmore-labs.com>
+#
+
+# If there is a global system configuration file, suck it in.
+#
+if [ -r /etc/defaults/periodic.conf ]; then
+    . /etc/defaults/periodic.conf
+    source_periodic_confs
+fi
+
+exim_tidydb_enable=${exim_tidydb_enable:-"YES"}
+exim_tidydb=${exim_tidydb:-"/usr/local/sbin/exim_tidydb"}
+exim_dbdir=${exim_dbdir:-"/var/spool/exim"}
+
+case "$exim_tidydb_enable" in
+    [Yy][Ee][Ss])
+	echo ""
+	echo "Tidying Exim hints databases:"
+	for db in "$exim_dbdir"/db/*.lockfile; do
+	    echo ""
+	    "$exim_tidydb" "$exim_dbdir" `basename $db .lockfile`
+	done
+	rc=1;;
+
+    *)  rc=0;;
+esac
+
+exit $rc
diff -Nur mail/exim/files/460.exim-mail-rejects.sh.orig mail/exim/files/460.exim-mail-rejects.sh
--- mail/exim/files/460.exim-mail-rejects.sh.orig	Thu Jan  1 01:00:00 1970
+++ mail/exim/files/460.exim-mail-rejects.sh	Thu Sep  4 18:31:39 2003
@@ -0,0 +1,68 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+# Check for rejected mail
+# Log lines that end with ' : IGNORE' will not be reported
+# 
+#   contributed by: Oliver Eikemeier <eikemeier at fillmore-labs.com>
+#
+
+# If there is a global system configuration file, suck it in.
+#
+if [ -r /etc/defaults/periodic.conf ]
+then
+    . /etc/defaults/periodic.conf
+    source_periodic_confs
+fi
+
+exim_status_mail_rejects_enable=${exim_status_mail_rejects_enable:-"YES"}
+exim_status_mail_rejects_logs=${exim_status_mail_rejects_logs:-2}
+exim_rejectlog=${exim_rejectlog:-"/var/log/exim/rejectlog"}
+
+case "$exim_status_mail_rejects_enable" in
+    [Yy][Ee][Ss])
+	if [ ! -d `dirname "$exim_rejectlog"` ]
+	then
+	    echo '$exim_status_mail_rejects_enable is set but' \
+		"`dirname "$exim_rejectlog"` doesn't exist"
+	    rc=2
+	elif [ "$exim_status_mail_rejects_logs" -le 0 ]
+	then
+	    echo '$exim_status_mail_rejects_enable is set but' \
+		'$exim_status_mail_rejects_logs is not greater than zero'
+	    rc=2
+	else
+	    echo
+	    echo Checking for rejected mail:
+
+	    start=`date -v-1d '+%Y-%m-%d'`
+	    n=$(($exim_status_mail_rejects_logs - 2))
+	    rc=$({
+		while [ $n -ge 0 ]
+		do
+		    if [ -f "$exim_rejectlog.$n" ]
+		    then
+			cat "$exim_rejectlog.$n"
+		    elif [ -f "$exim_rejectlog.$n.gz" ]
+		    then
+			zcat -fc "$exim_rejectlog.$n.gz"
+		    elif [ -f "$exim_rejectlog.$n.bz2" ]
+		    then
+			bzcat -fc "$exim_rejectlog.$n.bz2"
+		    fi
+		    n=$(($n - 1))
+		done
+		if [ -f "$exim_rejectlog" ]
+		then
+		    cat "$exim_rejectlog"
+		fi
+	    } |
+		grep -e "^$start" | grep -v ' : IGNORE$' | tee /dev/stderr | wc -l)
+	    [ $rc -gt 0 ] && rc=1
+	fi;;
+
+    *)  rc=0;;
+esac
+
+exit $rc
diff -Nur mail/exim/files/POST-INSTALL-NOTES.orig mail/exim/files/POST-INSTALL-NOTES
--- mail/exim/files/POST-INSTALL-NOTES.orig	Thu Jul 17 21:06:43 2003
+++ mail/exim/files/POST-INSTALL-NOTES	Thu Sep  4 17:18:02 2003
@@ -6,22 +6,22 @@
 In addition, plain text versions of these documents have been installed
 as:
 
-    ${PREFIX}/share/doc/exim/filter.txt
-    ${PREFIX}/share/doc/exim/spec.txt
+    %%DOCSDIR%%/filter.txt
+    %%DOCSDIR%%/spec.txt
 
 Postscript, PDF, HTML and plain text versions of these documents, as well
 as a comprehensive FAQ list, are available at http://www.exim.org/ .
 
 To use Exim instead of sendmail on startup:
 
-*) Create exim/configure from exim/configure.default .
 *) Clear the sendmail queue and stop the sendmail daemon.
 *) Adjust mailer.conf(5) as appropriate.
 *) Set the 'sendmail_enable' rc.conf(5) variable to 'NONE'.
 *) Set the 'daily_status_include_submit_mailq' and
    'daily_clean_hoststat_enable' periodic.conf(5)
    variables to 'NO'.
-*) Start exim with '${PREFIX}/etc/rc.d/exim.sh start'.
+*) Set the 'exim_enable' rc.conf(5) variable to 'YES'.
+*) Start exim with '%%RC_DIR%%/exim%%RC_SUFX%% start'.
 
 You may also want to configure newsyslog(8) to rotate Exim log files:
 
@@ -36,6 +36,6 @@
 Access Control Lists instead of separate options. All this means that
 pre-4.00 configuration files have to be massively converted. If you
 are coming from a 3.xx release, please read the document in the file
-${PREFIX}/share/doc/exim/Exim4.upgrade, and allow some time to complete
+%%DOCSDIR%%/Exim4.upgrade, and allow some time to complete
 the upgrade.
 
diff -Nur mail/exim/files/POST-INSTALL-NOTES.clamd.orig mail/exim/files/POST-INSTALL-NOTES.clamd
--- mail/exim/files/POST-INSTALL-NOTES.clamd.orig	Mon Aug 25 08:57:40 2003
+++ mail/exim/files/POST-INSTALL-NOTES.clamd	Thu Sep  4 17:27:43 2003
@@ -38,7 +38,7 @@
 
 *  Start clamd with /usr/local/etc/rc.d/clamd.sh start .
 
-*  Start Exim with /usr/local/etc/rc.d/exim.sh start .
+*  Start Exim with %%RC_DIR%%/exim%%RC_SUFX%% start .
 
 Sheldon Hearn <sheldonh at FreeBSD.org>
 
diff -Nur mail/exim/files/POST-INSTALL-NOTES.exiscan-acl.orig mail/exim/files/POST-INSTALL-NOTES.exiscan-acl
--- mail/exim/files/POST-INSTALL-NOTES.exiscan-acl.orig	Mon Aug 25 08:57:40 2003
+++ mail/exim/files/POST-INSTALL-NOTES.exiscan-acl	Thu Sep  4 17:14:11 2003
@@ -1,11 +1,11 @@
 This installation of Exim includes Exiscan content scanning support,
 from http://duncanthrax.net/exiscan-acl/, which is documented in
-${PREFIX}/share/doc/exim/exiscan-acl-spec.txt.  The ports tree
+%%DOCSDIR%%/exiscan-acl-spec.txt.  The ports tree
 includes various content scanners that might be useful, e.g.
 mail/p5-Mail-SpamAssassin and security/clamav.
 
 Notes for enabling malware scanning with the excellent clamd scanner
-are in ${PREFIX}/share/doc/exim/POST-INSTALL-NOTES.clamd.
+are in %%DOCSDIR%%/POST-INSTALL-NOTES.clamd.
 
 When Exiscan is actually enabled in the Exim configure file, great
 care should be taken to test upgrades, since Exiscan updates tend
diff -Nur mail/exim/files/exim.sh.orig mail/exim/files/exim.sh
--- mail/exim/files/exim.sh.orig	Mon Jun  2 15:17:43 2003
+++ mail/exim/files/exim.sh	Thu Sep  4 16:50:21 2003
@@ -2,29 +2,63 @@
 #
 # $FreeBSD: ports/mail/exim/files/exim.sh,v 1.5 2003/06/02 13:17:43 sheldonh Exp $
 #
-# Note that 'pidfile' may need to be changed if 'args' is altered; see
-# the description of the 'pid_file_path' Exim configuration option in
-# the Exim Specification.
+
+# PROVIDE: mail
+# REQUIRE: LOGIN
+# KEYWORD: FreeBSD shutdown
+#	we make mail start late, so that things like .forward's are not
+#	processed until the system is fully operational
+
+#
+# Add the following lines to /etc/rc.conf to enable exim:
 #
-args='-bd -q30m'
-pidfile='/var/run/exim.pid'
+#exim_enable="YES"
+#
+# See exim(8) for flags
+#
+
+. %%RC_SUBR%%
+
+name=exim
+rcvar=`set_rcvar`
+
+command=%%PREFIX%%/sbin/exim
+pidfile=/var/run/exim.pid
+required_dirs=/var/log/exim
+required_files=%%PREFIX%%/etc/exim/configure
+
+start_precmd=start_precmd
+stop_postcmd=stop_postcmd
+
+extra_commands="reload"
+
+start_precmd()
+{
+  case $sendmail_enable in
+  [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
+    warn "sendmail_enable should be set to NONE"
+    ;;
+  [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
+    case $sendmail_submit_enable in
+    [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
+      warn "sendmail_submit_enable should be set to NO"
+      ;;
+    esac
+    ;;
+  [Nn][Oo][Nn][Ee])
+    ;;
+  esac
+}
+
+stop_postcmd()
+{
+  rm -f $pidfile
+}
 
-case "$1" in
-start)
-        [ -x /usr/local/sbin/exim ] && /usr/local/sbin/exim ${args} && \
-	    echo -n ' exim'
-        ;;
-stop)
-        kill `cat ${pidfile}` && echo -n ' exim'
-        ;;
-reload)
-        kill -HUP `cat ${pidfile}` && echo -n ' exim'
-        ;;
-*)
-        echo "Usage: `basename $0` {start|stop|reload}" >&2
-        exit 64
-        ;;
-esac
+# set defaults
 
-exit 0
+exim_enable=${exim_enable:-"NO"}
+exim_flags=${exim_flags:-"-bd -q30m"}
 
+load_rc_config $name
+run_rc_command "$1"
diff -Nur mail/exim/pkg-message.orig mail/exim/pkg-message
--- mail/exim/pkg-message.orig	Tue Sep 11 13:06:54 2001
+++ mail/exim/pkg-message	Thu Sep  4 18:47:56 2003
@@ -2,6 +2,8 @@
 IMPORTANT NOTE:
 ===============
 
-Please read ${PREFIX}/share/doc/exim/POST-INSTALL-NOTES for important
+Please read %%DOCSDIR%%/POST-INSTALL-NOTES for important
 information regarding your Exim installation.
+
+Don't forget to add 'exim_enable="YES"' to rc.conf(5)
 
diff -Nur mail/exim/pkg-plist.orig mail/exim/pkg-plist
--- mail/exim/pkg-plist.orig	Mon Aug 25 08:57:39 2003
+++ mail/exim/pkg-plist	Thu Sep  4 18:17:24 2003
@@ -1,5 +1,5 @@
-etc/exim/configure.default
-etc/rc.d/exim.sh
+ at comment $FreeBSD$
+ at unexec [ ! -f /var/run/exim.pid ] || %%RC_DIR%%/exim%%RC_SUFX%% stop || true
 sbin/exim
 sbin/exim-%%EXIM_VERSION%%-1
 sbin/exim_checkaccess
@@ -28,5 +28,14 @@
 %%PORTDOCS%%%%EXISCAN_ACL%%%%DOCSDIR%%/POST-INSTALL-NOTES.clamd
 %%PORTDOCS%%%%EXISCAN_ACL%%%%DOCSDIR%%/exiscan-acl-examples.txt
 %%PORTDOCS%%%%EXISCAN_ACL%%%%DOCSDIR%%/exiscan-acl-spec.txt
- at dirrm etc/exim
 %%PORTDOCS%%@dirrm %%DOCSDIR%%
+etc/periodic/daily/150.exim-tidydb
+etc/periodic/daily/460.exim-mail-rejects
+ at unexec rmdir %D/etc/periodic/daily 2>/dev/null || true
+ at unexec rmdir %D/etc/periodic 2>/dev/null || true
+ at unexec if cmp -s %D/etc/exim/configure %D/etc/exim/configure.default; then rm -f %D/etc/exim/configure; fi
+etc/exim/configure.default
+ at exec [ -f %B/configure ] || cp %B/%f %B/configure
+ at unexec rmdir %B 2>/dev/null || true
+ at cwd %%RC_DIR%%
+exim%%RC_SUFX%%
--- exim-rc.subr.patch ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list