#!/bin/sh
_mail_log="/var/log/mail.log"
_main_cf="/etc/postfix/main.cf"
_main_cf_default="/etc/postfix/main.cf.default"
_master_cf="/etc/postfix/master.cf"
_master_cf_tmp="/etc/postfix/master.cf.tmp"
_master_cf_orig="/etc/postfix/master.cf.orig"
_master_cf_default="/etc/postfix/master.cf.default"
_postfix_data_dir="/var/run/postfix"
_other_plist="/etc/MailServicesOther.plist"
_other_plist_default="/etc/MailServicesOther.plist.default"
_mail_user_settings="/var/db/.mailusersettings.plist"
echo "Configuring Postfix..."
if [ ! -e "$_mail_log" ] ; then
touch "$_mail_log"
fi
if [ -e "$_mail_log" ] ; then
chown root:admin "$_mail_log"
chmod 640 "$_mail_log"
fi
if [ ! -e "$_mail_user_settings" ] ; then
touch "$_mail_user_settings"
fi
chown _postfix:mail $_mail_user_settings
chmod 660 $_mail_user_settings
if [ ! -e "$_main_cf" ] ; then
if [ -e "$_main_cf_default" ] ; then
cp "$_main_cf_default" "$_main_cf"
chmod 644 "$_main_cf"
else
echo "$_main_cf_default does not exist: Could not create $_main_cf"
fi
fi
if [ ! -e "$_master_cf" ] ; then
if [ -e "$_master_cf_default" ] ; then
cp "$_master_cf_default" "$_master_cf"
chmod 644 "$_master_cf"
else
echo "$_master_cf_default does not exist: Could not create $_master_cf"
fi
fi
if [ ! -e "$_other_plist" ] ; then
if [ -e "$_master_cf_default" ] ; then
cp "$_other_plist_default" "$_other_plist_default"
chmod 644 "$_other_plist"
else
echo "$_other_plist_default does not exist: Could not create $_other_plist"
fi
fi
if [ ! -d "$_postfix_data_dir" ] ; then
mkdir "$_postfix_data_dir"
chmod 755 "$_postfix_data_dir"
chown _postfix "$_postfix_data_dir"
else
chmod 755 "$_postfix_data_dir"
chown _postfix "$_postfix_data_dir"
fi
if [ -e "$_master_cf" ] ; then
sed '/^pickup/ a\
\ \ -o content_filter=
' < $_master_cf > $_master_cf_tmp
if [ -e "$_master_cf_tmp" ] ; then
mv $_master_cf $_master_cf_orig
mv $_master_cf_tmp $_master_cf
fi
fi
/usr/sbin/postconf -e mail_owner=_postfix
/usr/sbin/postconf -e setgid_group=_postdrop
/usr/sbin/postconf -e mailbox_size_limit=0
/usr/sbin/postconf -e mydestination='$myhostname, localhost.$mydomain, localhost, $mydomain'
/usr/sbin/postconf -e imap_submit_cred_file=/private/etc/postfix/submit.cred
if [ ! -e /private/etc/postfix/submit.cred ] ; then
hostname=`grep "^myhostname *=" /private/etc/postfix/main.cf | sed 's,.*= *,,'`
if [ ! "$hostname" ] ; then
hostname=`hostname`
fi
if [ -s /private/etc/dovecot/submit.passdb ] ; then
pw=`grep "^submit:" /private/etc/dovecot/submit.passdb | sed -e 's,.*},,' -e 's,:.*,,'`
fi
if [ ! "$pw" ] ; then
pw=`dd if=/dev/urandom bs=256 count=1 | env LANG=C tr -dc a-zA-Z0-9 | cut -b 1-22`
fi
if [ "$pw" -a "$hostname" ]; then
echo "submitcred version 1" > /private/etc/postfix/submit.cred
echo "$hostname|submit|$pw" >> /private/etc/postfix/submit.cred
fi
chmod 600 /private/etc/postfix/submit.cred
fi
/usr/sbin/postfix check > /dev/null 2>&1
POSTFIX_PID=`ps -cxU root | grep master | sed -n -e "s/[^0-9]*\([0-9]*\).*/\1/p"`
if [ "$POSTFIX_PID" = "" ] ; then
/usr/sbin/postfix start > /dev/null 2>&1
/usr/sbin/postfix stop > /dev/null 2>&1
fi
sed 's/^mail\.\*/mail.warn/' < /etc/syslog.conf > /etc/syslog.conf.$$ && mv /etc/syslog.conf.$$ /etc/syslog.conf