Install Exim MTA

#Install exim script automatically
#turn on debugging, -x starts, +x stops
set +x
rpm -qa | grep exim > /dev/null
if [ "${EXIMRPM}" -eq 0 ]; then
        echo "Exims rpm installed, path is `which exim`."
elif [ "${EXIMRPM}" -eq 1 ]; then
        echo "Exim not installed, cannot continue, exiting."
        exit 1
        echo "Undefined state, exiting."
        exit 2
#Start install
#modify config file
echo '/begin routers/a\' > /tmp/smarthost.txt
echo '\' >> /tmp/smarthost.txt
echo 'smarthost:\' >> /tmp/smarthost.txt
echo '  driver = manualroute\' >> /tmp/smarthost.txt
echo '  domains = *\' >> /tmp/smarthost.txt
echo '  transport = remote_smtp\' >> /tmp/smarthost.txt
echo '  route_data =\' >> /tmp/smarthost.txt
sed -f /tmp/smarthost.txt /etc/exim/exim.conf > /etc/exim/
#delete old symlinks for sendmail with unaliased rm and recreate new links
echo "Moving symlinks...."
'rm' /usr/lib/sendmail /usr/sbin/sendmail
ln -s /usr/sbin/exim /usr/lib/sendmail
ln -s /usr/sbin/exim /usr/sbin/sendmail
#Set up system startup settings.
chkconfig --add exim
chkconfig --del sendmail
chkconfig exim on
chkconfig sendmail off
#Start TLS config
echo "Starting TLS setup"
echo "------------------"
echo ""
echo "Please use the following settings for the ssl certificate:- "
echo "Country Name=GG, State or Province Name=Guernsey, Locality Name=St Peter Port,"
echo "Organization Name=XYZ Ltd, Organizational Unit Name - Leave Blank, Common Name=`hostname -s`"
echo ""
openssl req -x509 -newkey rsa:1024 -keyout /etc/exim/exim.key -out /etc/exim/exim.crt -days 9999 -nodes
echo ""
echo '/timeout_frozen_after = 7d/a\' > /tmp/tlsconfig.txt
echo '\' >> /tmp/tlsconfig.txt
echo 'tls_advertise_hosts = *\' >> /tmp/tlsconfig.txt
echo 'tls_certificate = /etc/exim/exim.crt\' >> /tmp/tlsconfig.txt
sed -f /tmp/tlsconfig.txt /etc/exim/ > /etc/exim/exim.conf.newer
#make backup copy
mv -v /etc/exim/exim.conf /etc/exim/exim.conf.original
cp -v /etc/exim/exim.conf.newer /etc/exim/exim.conf
ls -l  /etc/exim/exim*
#stop sendmail and start exim
service sendmail stop
service exim restart
#send a test mail
echo -n "Please enter an email address to send a test to:- "
echo "Install Exim script" > ${TMPLOG}
echo "===================" >> ${TMPLOG}
echo ""
echo "Test email from /root/scripts/  on `hostname`" >> ${TMPLOG}
/bin/mailx -s "Test Mail from new Exim install." ${TESTEMAILADDRESS} < ${TMPLOG}
rm ${TMPLOG}
#allow log to get written
sleep 10
#Have a look at the logs to see all is ok
echo "Exim log extract from /var/log/exim/main.log:-"
echo "----------------------------------------------"
echo ""
tail /var/log/exim/main.log
echo ""
echo ""
#clean up
rm /tmp/smarthost.txt
rm /tmp/tlsconfig.txt

rb/installexim.txt · Last modified: 15/08/2018 23:48 by andrew