openbsd-ports/mail/postfix/pkg/INSTALL
1999-06-13 16:15:57 +00:00

155 lines
4.2 KiB
Plaintext

#!/bin/sh
# $OpenBSD: INSTALL,v 1.4 1999/06/13 16:15:57 dugsong Exp $
#
# Pre/post-installation setup of postfix
PATH=/bin:/usr/bin:/sbin:/usr/sbin
PREFIX=${PKG_PREFIX:-/usr/local}
CONFIG_DIR=/etc/postfix
SPOOL_DIR=/var/spool/postfix
POSTFIXUID=6
POSTFIXGID=6
MAILDROPGID=12
# Function: set up postfix user/group accounts.
#
do_accts()
{
# Create postfix user and group.
line=`egrep '^postfix:' /etc/group`
if [ "$line" != "" ]; then
POSTFIXGID=`echo $line | cut -f3 -d:`
else
echo "-> Creating postfix group, gid $POSTFIXGID"
echo "postfix:*:${POSTFIXGID}:" >> /etc/group
echo ""
fi
line=`egrep '^postfix:' /etc/passwd`
if [ "$line" != "" ]; then
POSTFIXUID=`echo $line | cut -f3 -d:`
else
echo "-> Creating postfix user, uid $POSTFIXUID"
chpass -a "postfix:*:${POSTFIXUID}:${POSTFIXGID}::::Disgruntled Postal Worker:/nonexistent:/sbin/nologin"
echo ""
fi
echo "-> Using account 'postfix' for postfix, uid $POSTFIXUID, gid $POSTFIXGID"
echo ""
# Create Postfix maildrop group.
line=`egrep '^maildrop:' /etc/group`
if [ "$line" != "" ]; then
MAILDROPGID=`echo $line | cut -f3 -d:`
else
echo "-> Creating maildrop group, gid $MAILDROPGID"
echo "maildrop:*:${MAILDROPGID}:" >> /etc/group
echo ""
fi
echo "-> Using group 'maildrop' for postdrop, gid $MAILDROPGID"
}
# Function: set up the postfix spool dir / chroot area
#
do_spooldir()
{
[ -d $SPOOL_DIR ] || mkdir -p -m 755 $SPOOL_DIR
[ -d ${SPOOL_DIR}/etc ] || mkdir -p -m 755 ${SPOOL_DIR}/etc
for file in localtime services resolv.conf ; do
install -c -m 755 /etc/$file ${SPOOL_DIR}/etc
done
echo
echo "+---------------"
echo "| Postfix spool directory and chroot area created"
echo "| under $SPOOL_DIR"
echo "+---------------"
}
# Function: replace sendmail binaries with postfix
#
do_sendmail()
{
echo
echo "+---------------"
echo "| Postfix can be set up to replace sendmail entirely."
echo "| Please read the documentation at http://www.postfix.org/"
echo "| carefully before you decide to do this!"
echo "+---------------"
echo
printf "Do you want to replace sendmail with postfix? [Y/n] "
read ans
case $ans in n*|N*) return ;; esac
echo
echo "-> Disabling sendmail"
set -x
mv /usr/sbin/sendmail /usr/sbin/sendmail-orig
mv /usr/bin/mailq /usr/bin/mailq-orig
mv /usr/bin/newaliases /usr/bin/newaliases-orig
chmod 555 /usr/sbin/sendmail-orig /usr/bin/mailq-orig /usr/bin/newaliases-orig
set +x
echo
echo "-> Enabling postfix replacements"
set -x
ln -s ${PREFIX}/sbin/sendmail /usr/sbin/sendmail
ln -s /usr/sbin/sendmail /usr/bin/mailq
ln -s /usr/sbin/sendmail /usr/bin/newaliases
set +x
}
# Function: install the postfix configuration files from the samples
#
do_configs()
{
if [ -d $CONFIG_DIR ]; then
echo
echo "+---------------"
echo "| The existing $1 configuration files in ${CONFIG_DIR},"
echo "| have NOT been changed. You may want to compare them to the"
echo "| current sample files, ${PREFIX}/lib/postfix,"
echo "| and update your configuration as needed."
echo "+---------------"
else
# Install config files.
mkdir -p -m 755 $CONFIG_DIR
install -m 644 -c ${PREFIX}/lib/postfix/* $CONFIG_DIR
sed "s@y0y0y0@${PREFIX}@g" ${CONFIG_DIR}/main.cf > ${CONFIG_DIR}/main.cf.$$
install -m 644 ${CONFIG_DIR}/main.cf.$$ ${CONFIG_DIR}/main.cf
# Configure setgid maildrop.
chgrp maildrop ${PREFIX}/sbin/postdrop
chmod 2755 ${PREFIX}/sbin/postdrop
install -m 755 -c ${CONFIG_DIR}/postfix-script-sgid ${CONFIG_DIR}/postfix-script
echo
echo "+---------------"
echo "| The $1 configuration files in ${CONFIG_DIR},"
echo "| have been installed. Please view these files and change"
echo "| the configuration to meet your needs"
echo "+---------------"
fi
}
# verify proper execution
#
if [ $# -ne 2 ]; then
echo "usage: $0 distname { PRE-INSTALL | POST-INSTALL }" >&2
exit 1
fi
# Verify/process the command
#
case $2 in
PRE-INSTALL)
do_accts
;;
POST-INSTALL)
do_spooldir
do_configs $1
do_sendmail
;;
*)
echo "Usage: `basename $0` distname <PRE-INSTALL|POST-INSTALL>" >&2
exit 1
;;
esac
exit 0