pkgsrc/mail/cyrus-imapd21/files/cyrus.sh
jlam 8349293f6a Restructure the flow so that we use pipes to pass information between
processes instead of saving values in shell variables and then iterating
over them.  Using pipes is more scalable and is just as easy to read, so
it's a net win.
2004-07-31 03:29:38 +00:00

77 lines
1.7 KiB
Bash

#!@RCD_SCRIPTS_SHELL@
#
# $NetBSD: cyrus.sh,v 1.3 2004/07/31 03:29:38 jlam Exp $
#
# PROVIDE: cyrus
# REQUIRE: DAEMON
#
# To start cyrus-imapd at startup, copy this script to /etc/rc.d and set
# cyrus=YES in /etc/rc.conf.
if [ -f /etc/rc.subr ]; then
. /etc/rc.subr
fi
rcd_dir=`@DIRNAME@ $0`
name="cyrus"
rcvar=$name
command="@PREFIX@/cyrus/bin/master"
command_args="-d"
pidfile="/var/run/cyrus-master.pid"
required_files="@PKG_SYSCONFDIR@/cyrus.conf @IMAPDCONF@"
extra_commands="mkimap reload"
mkimap_cmd="cyrus_mkimap"
start_precmd="cyrus_prestart"
cyrus_prestart()
{
# Check to see if "configdirectory" is present before we start
# the Cyrus IMAP server. Otherwise, we run mkimap to generate
# the necessary directories.
#
if [ -f @IMAPDCONF@ ]; then
configdir=` \
@AWK@ '/^configdirectory:/ { print $2; exit };' \
@IMAPDCONF@ \
`
if [ -z "$configdir" ]; then
@ECHO@ "@IMAPDCONF@ missing 'configdirectory' setting"
exit 1
fi
if [ ! -d "$configdir" ]; then
$rcd_dir/cyrus mkimap
fi
fi
}
cyrus_mkimap()
{
# Generate the prerequisite directory structure for Cyrus IMAP.
if [ -f @IMAPDCONF@ ]; then
@AWK@ '/^configdirectory:/ { print $2 }; \
/^partition-.*:/ { print $2 }; \
/^sievedir:/ { print $2 }' \
@IMAPDCONF@ | \
while read dir; do
if [ ! -d "$dir" ]; then
@MKDIR@ "$dir"
@CHMOD@ 750 "$dir"
@CHOWN@ @CYRUS_USER@ "$dir"
@CHGRP@ @CYRUS_GROUP@ "$dir"
fi
done
@SU@ -m @CYRUS_USER@ -c "@PREFIX@/cyrus/bin/mkimap"
fi
}
if [ -f /etc/rc.subr -a -f /etc/rc.conf \
-a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ]; then
load_rc_config $name
run_rc_command "$1"
else
@ECHO@ -n " ${name}"
eval ${start_precmd}
${command} ${cyrus_flags} ${command_args}
fi