File sendmail.systemd of Package sendmail.10026

#!/bin/bash
#
# /etc/mail/system/sm.pre
#
# Author: Werner Fink
# Please send feedback to http://www.suse.de/feedback/
#
# Description:
#
#   Helper script to set up the environment for sendmail
#   Mail Transport Agent (MTA) if started by systemd
#

sysconf=/etc/sysconfig/mail
   port=/var/run/sendmail/port

for cfg in /etc/sendmail.cf /etc/mail/sendmail.cf ; do
    test -s $cfg && break
done
for sed in /bin/sed /usr/bin/sed ; do
    test -x $sed && break
done

#
# Make sure that configuration is uptodate
#
if test -x /usr/bin/make ; then
    /usr/bin/make -C /etc/mail > /dev/null 2>&1
fi

#
# Create /var/run/sendmail if not exit
#
test -d /var/run	    || /bin/mkdir --mode 0755 /var/run
test -d /var/run/sendmail   || /bin/mkdir --mode 1750 /var/run/sendmail

#
# Handle SMTPD_LISTEN_REMOTE from /etc/sysconfig/sendmail
# that is write out environment file to be read by the
# systemd service unit file for sendmail MTA.
#
if test ! -s $port -o $cfg -nt $port -o $sysconf -nt $port ; then
    . $sysconf
    umask 066
    if test "$SMTPD_LISTEN_REMOTE" != "yes" ; then
	PortOpts=$($sed -rn '/^O[[:blank:]]+DaemonPortOptions=.*Name=MTA.*$/I {
			s/[[:blank:]]+//g
			s/^O[^=]+=(.*)/\1/p
		    }' $cfg)
	PortOpts="${PortOpts:+${PortOpts},}Addr=127.0.0.1"
	echo SENDMAIL_PORT_OPTS="\"-O DaemonPortOptions=${PortOpts}\""
    else
	echo SENDMAIL_PORT_OPTS="\"\""
    fi  > $port
    
fi

#
# end of /etc/mail/system/sm.pre