#!/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"
echo "Upgrading Postfix..."
if [ ! -e "$_mail_log" ] ; then
touch "$_mail_log"
fi
if [ ! -e "$_main_cf" ] ; then
if [ -e "$_main_cf_default" ] ; then
cp "$_main_cf_default" "$_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"
else
echo "$_master_cf_default does not exist: Could not create $_master_cf"
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
SA_ENABLED=`serveradmin settings mail:postfix:spam_scan_enabled | sed 's/^.*=//' | sed -e 's/^ *//'`
if [ $SA_ENABLED = "yes" ] ; then
serveradmin settings mail:postfix:smtp_uce_controlls = 1
fi
/usr/sbin/postconf -e mail_owner=_postfix
/usr/sbin/postconf -e setgid_group=_postdrop
/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 '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 upgrade-configuration > /dev/null 2>&1
/usr/sbin/postfix check > /dev/null 2>&1
/usr/sbin/postfix set-permissions > /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
sleep 2
/usr/sbin/postfix stop
fi