Image

Image

Search This Blog

Tuesday, September 16, 2008

initsetup
Posted by rain on September 18th, 2007

#!/bin/bash

# no comments, thank you

vardt=/etc/initsetup/vardt
log=/etc/initsetup/setup.log

oldexp=`grep expd $vardt | cut -d= -f2`
. $vardt

echo -en “Starting setup: ” > $log
date >> $log
cat $vardt >> $log

dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 1/10″ \
–inputbox “Enter your domain name” 8 60 $fakedom 2>/tmp/input.$$
sel=$?
dom=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo “[ESC] Pressed, exiting” && exit 1;;
esac
rm -f /tmp/input.$$
echo dom=$dom >> $log

dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 2/10″ \
–inputbox “Enter your IP address” 8 60 $fakeip 2>/tmp/input.$$
sel=$?
ipif=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo “[ESC] Pressed, exiting” && exit 1;;
esac
rm -f /tmp/input.$$
echo ipif=$ipif >> $log

dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 3/10″ \
–inputbox “Enter the MailServer IP address” 8 60 $fakemail 2>/tmp/input.$$
sel=$?
ipmail=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo “[ESC] Pressed, exiting” && exit 1;;
esac
rm -f /tmp/input.$$
echo ipmail=$ipmail >> $log

dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 4/10″ \
–inputbox “Enter the Gateway IP address” 8 60 $fakegw 2>/tmp/input.$$
sel=$?
ipgw=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo “[ESC] Pressed, exiting” && exit 1;;
esac
rm -f /tmp/input.$$
echo ipgw=$ipgw >> $log

dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 5/10″ \
–inputbox “Enter the DNS IP address” 8 60 $fakedns 2>/tmp/input.$$
sel=$?
ipdns=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo “[ESC] Pressed, exiting” && exit 1;;
esac
rm -f /tmp/input.$$
echo ipdns=$ipdns >> $log

dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 6/10″ \
–inputbox “Enter the Range of IP address” 8 60 $fakenet 2>/tmp/input.$$
sel=$?
ipnet=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo “[ESC] Pressed, exiting” && exit 1;;
esac
rm -f /tmp/input.$$
echo ipnet=$ipnet >> $log

dialog –nocancel –title “Enter the ExpiryDate” –backtitle “Step 7/10″ \
–calendar data 1 10 2>/tmp/input.$$
sel=$?
expd=`cat /tmp/input.$$`
case $sel in
0) ;;
255) echo “[ESC] Pressed, exiting” && exit 1;;
esac
rm -f /tmp/input.$$

dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 8/10″ \
–passwordbox “Enter the LicenseGenerator Password” 8 60 2>/tmp/input.$$
sel=$?
echo “Decrypting license generator” >> $log
cp /etc/initsetup/shc.tar.bz2.bfe /etc/initsetup/lic.tar.bz2.bfe 2>> $log
bcrypt lic.tar.bz2.bfe < /tmp/input.$$ 2>> $log
tar -jxf lic.tar.bz2 2>> $log
rm -f lic.* 2>> $log
case $sel in
0) ;;
255) echo “[ESC] Pressed, exiting” && exit 1;;
esac
rm -f /tmp/input.$$

/bin/sed -i s/$fakedom/$dom/g /etc/hosts
/bin/sed -i s/$fakedom/$dom/g /etc/squirrelmail/config.php
/bin/sed -i s/$fakedom/$dom/g /etc/postfix/transport
/bin/sed -i s/$fakedom/$dom/g /etc/awstats/awstats.mail.conf
/bin/sed -i s/$fakedom/$dom/g /etc/amavisd/amavisd.conf
/bin/sed -i s/$fakedom/$dom/g /etc/sysconfig/network
/bin/sed -i s/$fakedom/$dom/g /etc/mail/main.cf
/bin/sed -i s/$fakedom/$dom/g /etc/initsetup/process_unix
/bin/sed -i s/$fakeip/$ipif/g /etc/webmin/awstats/config
/bin/sed -i s/$fakeip/$ipif/g /etc/awstats/awstats.model.conf
/bin/sed -i s/$fakeip/$ipif/g /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/sed -i s/$fakeip/$ipif/g /etc/mail/spamassassin/local.cf
/bin/sed -i s/$fakeip/$ipif/g /etc/initsetup/exportuser
/bin/sed -i s/$fakeip/$ipif/g /etc/initsetup/getbackup
/bin/sed -i s/$fakedns/$ipdns/g /etc/resolv.conf
/bin/sed -i s/$fakedns/$ipdns/g /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/sed -i s^$fakenet^$ipnet^g /etc/mail/main.cf
/bin/sed -i s^$fakenet^$ipnet^g /etc/mail/spamassassin/local.cf
/bin/sed -i s/$fakemail/$ipmail/g /etc/postfix/transport
/bin/sed -i s/$fakemail/$ipmail/g /etc/init.d/redir
/bin/sed -i s/$fakegw/$ipgw/g /etc/sysconfig/network
/bin/sed -i s/$fakegw/$ipgw/g /etc/sysconfig/network-scripts/ifcfg-eth0

echo -en “Files modified, restarting network…”
/sbin/service network restart >> $log
echo -en ” Wait 10sec, network config…”
sleep 10
echo “Changing default route” >> $log
/sbin/route del default
/sbin/route add default gw $ipgw
export HOSTNAME=mail2.$dom

echo “Generating license” >> $log
if [ -f /etc/initsetup/shc-3.8.6/shc ]; then
/etc/initsetup/shc-3.8.6/shc -e $expd -f /etc/initsetup/shc-3.8.6/run
cp -f /etc/initsetup/shc-3.8.6/run.x /etc/init.d/run
rm -rf /etc/initsetup/shc-3.8.6
echo expd=$expd > $vardt
echo “License valid untill $expd” >> $log
else
dialog –beep –nocancel –title “SpamFilter Initial Setup” –backtitle “ERROR” \
–msgbox “THE LICENSE GENERATOR IS NOT FOUND! LICENSE WILL NOT BE REBUILD!
(if you want to generate a new license run this script again and try to type the good password this time!)” 9 45
echo “ERROR - no license found! Not updating to $expd” >> $log
echo expd=$oldexp > $vardt

sel=$?
case $sel in
0) ;;
255) echo “[ESC] Pressed, exiting” && exit 1;;
esac
fi
function isunix() {
dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 9.9/10″ \
–yesno “- To transfer userlist from unix server, copy /etc/initsetup/exportuser somewhere to the unix server (you can do that from the unix server by ftp as ftpuser:xxxx on port 1221 at this machine, get /exportuser /some/path/to/exportuser), then on the unix server do a crontab -e and add the line:
9 * * * * ftp -n /dev/null

Did you configured userlist transfer and want to use this option? ” 15 60
sel=$?
rm -f /etc/initsetup/process_userlist
ln -s /etc/initsetup/process_unix /etc/initsetup/process_userlist
case $sel in
0) grep relay_recipient_maps /etc/mail/main.cf 1>/dev/null || echo “relay_recipient_maps = hash:/etc/postfix/exchange_recipients” >> /etc/mail/main.cf
echo “Using unix server. Transfer userlist” >> $log
;;
1) echo “Using Unix server. No userlist transfer” >> $log;;
255) echo “[ESC] Pressed, exiting” && exit 1;;
esac
}
dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 9/10″ –yes-label Exchange \
–yesno “Is your mail server a Microsoft Exchange machine or NOT (something else… Unix/Linux/Win9x, or not using userlist at all)?” 10 40
sel=$?
case $sel in
0) dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 9.1/10″ \
–inputbox “Enter the Active Directory main server FULL name (FDQN)” 8 60 $fakeadfull 2>/tmp/input.$$
addomfull=`cat /tmp/input.$$`
rm -f /tmp/input.$$
echo addomfull=$addomfull >> $log
addom=`echo $addomfull | cut -d. -f2`
adext=`echo $addomfull | cut -d. -f3`
addom1=`echo $addomfull | cut -d. -f1`
dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 9.2/10″ \
–inputbox “Enter the AD secondary server name (ONLY name)” 8 60 $fakead2 2>/tmp/input.$$
addom2=`cat /tmp/input.$$`
rm -f /tmp/input.$$
echo addom2=$addom2 >> $log
dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 9.3/10″ \
–inputbox “Enter a valid user id for the Active Directory domain
Please do not use ‘user’ as valid user id!” 8 60 $fakeid 2>/tmp/input.$$
adid=`cat /tmp/input.$$`
rm -f /tmp/input.$$
echo adid=$adid >> $log
dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 9.4/10″ \
–inputbox “Enter the password for user ‘$adid’ in the AD” 8 60 $fakepw 2>/tmp/input.$$
adpw=`cat /tmp/input.$$`
rm -f /tmp/input.$$
echo adpw=$adpw >> $log
/bin/sed -i s^$fakeadfull^$addomfull^g /etc/initsetup/getexch.pl
/bin/sed -i s^$fakead1^$addom1^g /etc/initsetup/getexch.pl
/bin/sed -i s^$fakead2^$addom2^g /etc/initsetup/getexch.pl
/bin/sed -i s^$fakeaddom^$addom^g /etc/initsetup/getexch.pl
/bin/sed -i s^$fakeadext^$adext^g /etc/initsetup/getexch.pl
/bin/sed -i s^$fakeid^$adid^g /etc/initsetup/getexch.pl
/bin/sed -i s^$fakepw^$adpw^g /etc/initsetup/getexch.pl
echo fakead1=$addom1 > $vardt
echo fakead2=$addom2 >> $vardt
echo fakeaddom=$addom >> $vardt
echo fakeadext=$adext >> $vardt
echo fakeid=$adid >> $vardt
echo fakepw=$adpw >> $vardt
echo fakeadfull=$addomfull >> $vardt
grep relay_recipient_maps /etc/mail/main.cf 1>/dev/null || echo “relay_recipient_maps = hash:/etc/postfix/exchange_recipients” >> /etc/mail/main.cf
rm -f /etc/initsetup/process_userlist
ln -s /etc/initsetup/process_exchange /etc/initsetup/process_userlist
echo -en “Updated AD getuser script… ”
echo “Using AD userlist transfer” >> $log
;;
1) isunix
echo “Keeping fake AD infos for a future possible change of mail server…” >> $log
echo fakead1=$fakead1 >> $vardt
echo fakead2=$fakead2 >> $vardt
echo fakeaddom=$fakeaddom >> $vardt
echo fakeadext=$fakeadext >> $vardt
echo fakeid=$fakeid >> $vardt
echo fakepw=$fakepw >> $vardt
echo fakeadfull=$fakeadfull >> $vardt
;;
255) echo “[ESC] Pressed, exiting” && exit 1;;
esac

echo “Keeping fake IP/Name infos for a future possible change of mail server…” >> $log
echo fakedom=$dom >> $vardt
echo fakeip=$ipif >> $vardt
echo fakemail=$ipmail >> $vardt
echo fakegw=$ipgw >> $vardt
echo fakedns=$ipdns >> $vardt
echo fakenet=$ipnet >> $vardt
echo >> $vardt

echo -en “Last step: Restarting services…”
/etc/init.d/run
/etc/initsetup/process_userlist >> $log
/sbin/service amavisd restart >> $log
/sbin/service clamd restart >> $log
/sbin/service spamd restart >> $log
/sbin/service postfix restart >> $log
dialog –nocancel –title “SpamFilter Initial Setup” –backtitle “Step 10/10″ \
–msgbox “The system config and variables are backed-up daily in /etc/initsetup/backup.tgz. In order to save the backup on the unix machine just use the /etc/initsetup/getbackup ftp commands file.
Copy the file to the unix server (you can do that by ftp: as ftpuser:xxxx at this box on port 1221, get /tmp/getbackup /some/path/to/getbackup) and add the following line to cron:
50 21 * * * ftp -n /dev/null

If the server is Exchange, use the same getbackup script, started daily at 21:50 from getbackup.cmd via Task Scheduler.

THIS IS THE END OF SETUP (see logs in setup.log)” 20 60
sel=$?
case $sel in
0) ;;
255) echo “[ESC] Pressed, exiting” && exit 1;;
esac

echo “Welcome to SpamFilter” > /etc/motd

echo “DONE!”

No comments:

Post a Comment

Blog Archive