2000-01-24 06:22:22 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
# Created by: stb@FreeBSD.org for the cyrus imap server
|
2000-11-01 12:59:18 +01:00
|
|
|
# Added to the cyrus-sasl port by hetzels@westbend.net
|
2000-01-24 06:22:22 +01:00
|
|
|
|
|
|
|
#set -vx
|
|
|
|
|
2000-09-19 04:59:29 +02:00
|
|
|
PKG_BATCH=${BATCH:=NO}
|
|
|
|
|
|
|
|
PKG_PREFIX=${PKG_PREFIX:=/usr/local}
|
|
|
|
|
2001-12-20 13:18:57 +01:00
|
|
|
SASLDB_NAME=${PKG_PREFIX}/etc/%%SASLDB%%
|
|
|
|
|
2003-01-30 15:04:02 +01:00
|
|
|
CYRUS_USER=${CYRUS_USER:=%%CYRUS_USER%%}
|
|
|
|
CYRUS_GROUP=${CYRUS_GROUP:=%%CYRUS_GROUP%%}
|
|
|
|
|
2000-01-24 06:22:22 +01:00
|
|
|
#
|
|
|
|
# create 'cyrus' user and group before installing
|
|
|
|
#
|
|
|
|
|
2000-09-19 04:59:29 +02:00
|
|
|
create_user() {
|
2003-01-30 15:04:02 +01:00
|
|
|
USER=${CYRUS_USER}
|
|
|
|
GROUP=${CYRUS_GROUP}
|
2004-03-30 17:28:07 +02:00
|
|
|
PW=/usr/sbin/pw
|
2002-05-24 04:01:13 +02:00
|
|
|
|
2004-03-31 18:56:31 +02:00
|
|
|
if [ -x /usr/sbin/nologin ]; then
|
|
|
|
shell=/usr/sbin/nologin
|
|
|
|
elif [ -x /sbin/nologin ]; then
|
2004-03-30 17:28:07 +02:00
|
|
|
shell=/sbin/nologin
|
|
|
|
else
|
|
|
|
shell=/nonexistent
|
|
|
|
fi
|
2002-05-24 04:01:13 +02:00
|
|
|
uhome="/nonexistent"
|
2000-01-24 06:22:22 +01:00
|
|
|
|
2002-05-24 04:01:13 +02:00
|
|
|
if ! ${PW} show group ${GROUP} -q >/dev/null; then
|
2000-01-24 06:22:22 +01:00
|
|
|
gid=60
|
2002-05-24 04:01:13 +02:00
|
|
|
while ${PW} show group -g ${gid} -q >/dev/null; do
|
2000-01-24 06:22:22 +01:00
|
|
|
gid=`expr ${gid} + 1`
|
|
|
|
done
|
2002-05-24 04:01:13 +02:00
|
|
|
if ! ${PW} add group ${GROUP} -g ${gid}; then
|
2000-01-24 06:22:22 +01:00
|
|
|
e=$?
|
2002-05-24 04:01:13 +02:00
|
|
|
echo "*** Failed to add group \`${GROUP}'. Please add it manually."
|
2000-01-24 06:22:22 +01:00
|
|
|
exit ${e}
|
|
|
|
fi
|
2002-05-24 04:01:13 +02:00
|
|
|
echo "*** Added group \`${GROUP}' (id ${gid})"
|
2000-01-24 06:22:22 +01:00
|
|
|
else
|
2002-05-24 04:01:13 +02:00
|
|
|
gid=`${PW} show group ${GROUP} 2>/dev/null | cut -d: -f3`
|
2000-01-24 06:22:22 +01:00
|
|
|
fi
|
|
|
|
|
2002-05-24 04:01:13 +02:00
|
|
|
if ! ${PW} show user ${USER} -q >/dev/null; then
|
2000-01-24 06:22:22 +01:00
|
|
|
uid=60
|
2002-05-24 04:01:13 +02:00
|
|
|
while ${PW} show user -u ${uid} -q >/dev/null; do
|
2000-01-24 06:22:22 +01:00
|
|
|
uid=`expr ${uid} + 1`
|
|
|
|
done
|
2002-05-24 04:01:13 +02:00
|
|
|
if ! ${PW} add user ${USER} -u ${uid} -g ${gid} -d "${uhome}" \
|
|
|
|
-c "the cyrus mail server" -s "${shell}" -p "*" \
|
2000-01-24 06:22:22 +01:00
|
|
|
; then
|
|
|
|
e=$?
|
2002-05-24 04:01:13 +02:00
|
|
|
echo "*** Failed to add user \`${USER}'. Please add it manually."
|
2000-01-24 06:22:22 +01:00
|
|
|
exit ${e}
|
|
|
|
fi
|
2002-05-24 04:01:13 +02:00
|
|
|
echo "*** Added user \`${USER}' (id ${uid})"
|
2000-01-24 06:22:22 +01:00
|
|
|
else
|
2004-03-30 17:33:55 +02:00
|
|
|
if ! ${PW} mod user ${USER} -g ${gid}; then
|
2000-01-24 06:22:22 +01:00
|
|
|
e=$?
|
2002-05-24 04:01:13 +02:00
|
|
|
echo "*** Failed to update user \`${USER}'."
|
2000-01-24 06:22:22 +01:00
|
|
|
exit ${e}
|
|
|
|
fi
|
2002-05-24 04:01:13 +02:00
|
|
|
echo "*** Updated user \`${USER}'."
|
2000-01-24 06:22:22 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2000-09-19 04:59:29 +02:00
|
|
|
create_sasldb() {
|
2001-12-20 13:18:57 +01:00
|
|
|
if [ ! -f ${SASLDB_NAME} ]; then
|
2003-01-30 15:04:02 +01:00
|
|
|
echo "test" | ${PKG_PREFIX}/sbin/saslpasswd2 -p -c ${CYRUS_USER}
|
2002-08-08 16:04:44 +02:00
|
|
|
if [ `${PKG_PREFIX}/sbin/sasldblistusers2 | wc -l` -eq 0 ] ; then
|
2002-05-21 17:08:58 +02:00
|
|
|
echo "WARNING: Failed to create ${PKG_PREFIX}/etc/$SASLDB_NAME}"
|
|
|
|
else
|
2003-01-30 15:04:02 +01:00
|
|
|
${PKG_PREFIX}/sbin/saslpasswd2 -d ${CYRUS_USER}
|
|
|
|
chown ${CYRUS_USER}:mail ${SASLDB_NAME}
|
2002-05-21 17:08:58 +02:00
|
|
|
chmod 640 ${SASLDB_NAME}
|
|
|
|
fi
|
2000-09-19 04:59:29 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2000-01-24 06:22:22 +01:00
|
|
|
case $2 in
|
|
|
|
PRE-INSTALL)
|
2000-09-19 04:59:29 +02:00
|
|
|
create_user
|
|
|
|
;;
|
|
|
|
POST-INSTALL)
|
|
|
|
if [ "${PKG_BATCH}" = "NO" ]; then
|
|
|
|
create_sasldb
|
2004-11-09 08:47:24 +01:00
|
|
|
elif [ ! -f ${SASLDB_NAME} ]; then
|
|
|
|
echo "*** We do not create ${SASLDB_NAME} automatically in"
|
|
|
|
echo "*** BATCH mode. Please create it by yourself. It should be"
|
|
|
|
echo "*** owner: ${CYRUS_USER}, group: mail, mode: 0640."
|
2000-09-19 04:59:29 +02:00
|
|
|
fi
|
2000-01-24 06:22:22 +01:00
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|