cd /tmp/

#if [ -f /tmp/atmail6.mailserver.tgz ]
#then
#    echo "atmail package already downloaded ..."
#else
#	wget 'http://atmail.com/downloads/atmail6.mailserver.tgz' -O /tmp/atmail6.mailserver.tgz
#fi

#tar xfvz atmail6.mailserver.tgz -C /usr/local/

echo 'Downloading SVN trunk for current Atmail6 version'

svn --username='UPDATESVN' --password='3e0b908beb199661c8e7bd9c79654000' checkout http://update.atmail.com/svn/atmail6/trunk /usr/local/atmail/

if [ -b /dev/sdb4 ]; then 
	mkdir /usr/local/atmail/users 
	echo "Pro Appliance - Mounting /usr/local/atmail/users" 
	mount /dev/sdb4 /usr/local/atmail/users          
fi

echo 'Changing root password to default'

# Change the root password for system default
echo 'C@l@Code123' | passwd root --stdin 

# Change the hostname
hostname mydomain.com
perl -pi.orig -e "s/^HOSTNAME .*/HOSTNAME=mydomain.com/" /etc/sysconfig/network

/etc/init.d/mysqld start

chkconfig mysqld on
chkconfig iptables off
/etc/init.d/iptables stop

# Turn off sendmail if running on system
service sendmail stop
chkconfig sendmail off

# Change the mysql root pass
mysqladmin -u root password 2c924d88

# Install local named if not already running
cp /usr/share/doc/bind-9.3.6/sample/var/named/named.local /var/named/chroot/var/named/named.local
cp /usr/share/doc/bind-9.3.6/sample/var/named/named.root /var/named/chroot/var/named/named.root
touch /var/named/chroot/etc/named.conf.local
cp /usr/local/atmail/server_source/scripts/appliance/named.conf /var/named/chroot/etc/named.conf

service named start
chkconfig named on

# Next, build Atmail
cd /usr/local/atmail/

### Build the version
date=`date -I`

echo 'Compiling Atmail, standby will take 5-10mins ...'
echo "Beginning installation - Date: $date" > /tmp/atmail-install.log

cd /usr/local/atmail
php server-install.php --install --dbhost=127.0.0.1 --dbuser=root --dbpass=2c924d88 --dbtable=atmail6 --create-db --create-tables --domain=mydomain.com --adminemail=admin@mydomain.com --adminpass=admin --domain=mydomain.com > /tmp/atmail-install.log 2>&1

### End build of version

# Change the document-root
perl -pi.orig -e "s/^DocumentRoot .*/DocumentRoot \"\/usr\/local\/atmail\/webmail\/\"/" /etc/httpd/conf/httpd.conf

chkconfig httpd on
service httpd restart