Install Exim MTA

#!/bin/bash
#Install exim script automatically
 
#turn on debugging, -x starts, +x stops
set +x
 
TMPLOG=/tmp/installexim.txt
 
 
rpm -qa | grep exim > /dev/null
EXIMRPM=$?
 
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
 
else
        echo "Undefined state, exiting."
        exit 2
fi
 
 
 
#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 = mailhost.prod.domain.net\' >> /tmp/smarthost.txt
 
sed -f /tmp/smarthost.txt /etc/exim/exim.conf > /etc/exim/exim.conf.new
 
 
 
#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/exim.conf.new > /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:- "
read TESTEMAILADDRESS
 
echo "Install Exim script" > ${TMPLOG}
echo "===================" >> ${TMPLOG}
echo ""
echo "Test email from /root/scripts/installexim.sh  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
 
exit

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