#!/bin/bash

#----------------------------------------------------------------------------#
#   Qmail The Easy Way v1.3 - distributed under the General Public License   #
#                                README                                      #
#                          September 5, 2001                                 #
#----------------------------------------------------------------------------#


#Declaring global Variables
ans1=y
ans2=Y
ans3=n
ans4=N

#Declaring global variables for app download locations
daemontools_download=http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
ucspi_tcp_download=http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
qmail_download=http://cr.yp.to/software/qmail-1.03.tar.gz
rblsmtpd_download=http://cr.yp.to/software/rblsmtpd-0.70.tar.gz
fastforward_download=http://cr.yp.to/software/fastforward-0.51.tar.gz
djbdns_download=http://cr.yp.to/djbdns/djbdns-1.05.tar.gz
checkpassword_download=http://cr.yp.to/checkpwd/checkpassword-0.90.tar.gz

#Declaring global variables for IMP+HORDE app download locations
imp_download=ftp://ftp.horde.org/pub/imp/tarballs/imp-latest.tar.gz
horde_download=ftp://ftp.horde.org/pub/imp/tarballs/horde-latest.tar.gz
wimap_download=ftp://ftp.cac.washington.edu/imap/imap.tar.Z
mysql_server_download=http://www.mysql.com/Downloads/MySQL-3.23/MySQL-3.23*.i386.rpm
mysql_client_download=http://www.mysql.com/Downloads/MySQL-3.23/MySQL-client*.i386.rpm
mysql_devel_download=http://www.mysql.com/Downloads/MySQL-3.23/MySQL-devel*.i386.rpm
php_download=http://www.php.net/do_download.php?download_file=php-4.0.6.tar.gz&source_site=php4.globe.de
courier_download=http://www.courier-mta.org/beta/imap/courier-imap-1.3.10.20010830.tar.gz

start ( )
 {
  clear
  echo " "
  echo " "
  echo "                 +++++++++++++++++++++++++++++++++++++"
  echo "                      Welcome to Qmail The Easy Way      "
  echo "                 +++++++++++++++++++++++++++++++++++++"
  echo "  "
  echo "  --> This script is distributed under the auspices of the GNU/GPL."
  echo " "
  echo "  --> My prime reason for writing this script is to make it easier"
  echo "      for people to install DJB's tools from Source....."
  echo " "
  echo "  --> This may not be the best DJB installer around, but i guess"
  echo "      with enough of review from you Open Source guys...i'll improve"
  echo "      it as much as i can....'-)"
  echo " "
  echo " "
  echo "  --> Pliss untar the file in the /tmp and run this script from there."
  echo " "
  echo  "                                   Trevor Warren "
  echo  "                               thefreeosguy@yahoo.com    "
  echo "                                www.qmailtheeasyway.com   "
  echo " " 
  echo " "
  sleep 10
 }

stop ( )
 {
  echo " "
  echo " "
  echo "          +++++++++++++++++++++++++++++++++++++++"
  echo "            Thanks for using Qmail The Easy Way     "
  echo "          +++++++++++++++++++++++++++++++++++++++"
  echo " "
  echo " "
 }

check_wget ( )
 {
 
  echo " "
  echo "  --> Testing for a wget installation"
  test_wget=`which wget`
  if [ $test_wget = /usr/bin/wget ]
    then
     echo " "
     echo "  --> Your Wget installation seems perfect. "
     echo " "
    else
    echo " "
    echo "  --> You do not seem to have a Wget Installation on your "
    echo "      machine. Hence, you will not be able to download any"
    echo "      qmail dependencies from the Internet."
    exit
    echo " "
  fi

 }

check_n_nstall_apache ( )
 {
  
#Start of the Apache test and install. Testing and installing for the 
#following on the disk.
#apache-1.3, apacheconf-0.7, apache-devel-1.3

   echo " "
   echo " "
   echo "  --> Checking for the Apache Webserv Installation."
   apache_test=`rpm -qa | grep -i apache-1.3`
   apacheconf_test=`rpm -qa | grep -i apacheconf-0.7` 
   apachedevel_test=`rpm -qa | grep -i apache-devel-1.3`

   if [ -z $apache_test ]
    then
     echo "  --> You do not seem to have the Apache Web-Server Installed."
     echo " " 
     echo "  --> Installing the Apache Web Server on our machine."
     rpm -ivh ./apache-1.3.19-5.i386.rpm
    else
     echo " "
     echo "  --> Apache Web Server Installation perfect. Continuing "
     echo "      with Installation."
     echo " " 
   fi

     echo "  --> Checking for the Apacheconf Installation. "
   if [ -z $apacheconf_test ]
    then
     echo " "
     echo "  --> You do not seem to have Apacheconf Installed."
     echo " "
     echo "  --> Installing Apache Conf on our machine."
     echo " "
     rpm -ivh ./apacheconf-0.7-2.noarch.rpm
    else
     echo " "
     echo "  --> Apache conf Installation perfect. Continuing "
     echo "      with Installation."
     echo " "
   fi

     echo "  --> Checking for the Apache Devel Installation." 
   if [ -z $apachedevel_test ]
    then 
     echo "  --> You do not seem to have Apache Devel package Installed."
     echo " " 
     echo "  --> Installing Apache Devel on our machine." 
     echo " "
     rpm -ivh  ./apache-devel-1.3.19-5.i386.rpm
    else 
     echo " "
     echo "  --> Apache conf Installation perfect. Continuing "
     echo "      with Installation."
     echo " " 
   fi 

 }

check_n_nstall_squid ( )
 {

#Start of the Squid test and install. Testing and installing for the
#following on the disk.
#squid-2.3

   echo " "
   echo " "
   echo "  --> Checking for the Squid Proxy Installation."
   squid_test=`rpm -qa | grep -i squid-2.3`

   if [ -z $squid_test ]
    then
     echo "  --> You do not seem to have Squid proxy Installed."
     echo " "
     echo "  --> Installing Squid proxy on our machine."
     rpm -ivh ./squid-2.3.STABLE4-10.i386.rpm
    else
     echo " "
     echo "  --> Squid Proxy Installation perfect. Continuing "
     echo "      with Installation."
     echo " "
   fi

 }

check_n_nstall_webmin ( )
 {

#Start of the Webmin test and install. Testing and installing for the
#following on the disk.
#webmin-0.88

   echo " "
   echo " "
   echo "  --> Checking for the Webmin Installation."
   webmin_test=`rpm -qa | grep -i webmin-0.88`

   if [ -z $webmin_test ]
    then
     echo "  --> You do not seem to have Webmin Installed."
     echo " "
    echo "  --> Installing Webmin on our machine."
    rpm -ivh ../apps/webmin-0.88.rpm
     temp_path=`pwd`
     cd /usr/libexec/webmin
     ./install-module.pl  $temp_path/qmailwebmin.wbm
     cd $temp_path
    else
     echo " "

    if [ -d /usr/libexec/webmin/qmailwebmin ]
     then
      echo "  --> Webmin + Qmail Webmin Aldready Installed "
     else
      temp_path=`pwd`
      cd /usr/libexec/webmin
      ./install-module.pl  $temp_path/qmailwebmin.wbm
      cd $temp_path
    fi

     echo "  --> Webmin Installation perfect. Continuing "
     echo "      with Installation."
     echo " "
   fi

 }


check_daemontools ( )
 {

#Starting to check for Daemontools

echo "  --> Checking for the daemontools tarball"
daemontools_there=`ls | grep -i daemontools*.gz`
if [ -z $daemontools_there ]
 then
  echo " "
  echo "  --> Couldn't locate the daemontools Tarball"
  echo " "
  echo "  --> Would you like to download the daemontools Tarball."
  echo "      Enter either  y or n."
  read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0  $daemontools_download
      d_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the daemontools tarball,"
      echo "      this will cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      d_there=n
    fi
 else
  echo " "
  echo "  --> Located the daemontools Tarball as $daemontools_there"
  echo " "
  echo " "
  d_there=y
fi

# End of Daemontools test

}

check_ucspi_tcp ( )
{

#Start of ucspi-tcp check

echo "  --> Checking for the ucspi-tcp tarball"
ucspi_tcp_there=`ls | grep -i ucspi-tcp*.gz`
if [ -z $ucspi_tcp_there ]
 then
  echo " "
  echo "  --> Couldn't locate the ucspi-tcp Tarball"
  echo " "
  echo "  --> Would you like to download the ucspi-tcp Tarball. "
  echo "      Enter either y or n."
  read answer6
    if [ $answer6 = $ans1 -o $answer6 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 $ucspi_tcp_download
      u_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the ucspi-tcp tarball,"
      echo "      this  will cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      u_there=n
    fi
 else
  echo " "
  echo "  --> Located the ucspi-tcp Tarball as $ucspi_tcp_there"
  echo " "
  echo " "
  u_there=y

fi

#End of uscpi-tcp check

 }

check_qmail ( )
 {
#Starting Check for qmail tarball

echo "  --> Checking for the qmail tarball"
qmail_there=`ls | grep -i qmail-1*.gz`
if [ -z $qmail_there ]
 then
  echo " "
  echo "  --> Couldn't locate the qmail Tarball"
  echo " "
  echo "  --> Would you like to download the qmail Tarball. "
  echo "      Enter either y or n."
   read answer1
    if [ $answer1 = $ans1 -o $answer1 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 $qmail_download
      q_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the qmail tarball,"
      echo "      this will cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      q_there=n
     fi
else
  echo " "
  echo "  --> Located the qmail Tarball as $qmail_there"
  echo " "
  echo " "
  q_there=y  

fi
#Ending check of qmail tarball

 }

check_rblsmtpd ( )
 {

#Starting rblsmtpd check

echo "  --> Checking for the rblsmtpd tarball"
rblsmtpd_there=`ls | grep -i rblsmtpd*.gz`
if [ -z $rblsmtpd_there ]
 then
  echo " "
  echo "  --> Couldn't locate the rblsmtpd Tarball"
  echo " "
  echo "  --> Would you like to download the rblsmtpd Tarball."
  echo "      Enter either y or n."
  read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 $rblsmtpd_download
      r_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the rblsmtpd tarball,"
      echo "      this will cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      r_there=n
     fi
 else
  echo " "
  echo "  --> Located the rblsmtpd Tarball as $rblsmtpd_there"
  echo " "
  echo " "
  r_there=y

fi 

#Ending rblsmtpd check
 }

check_fastforward ( )
 {

# Start fastforward check
echo "  --> Checking for the fastforward tarball"
fastforward_there=`ls | grep -i fastforward*.gz`
if [ -z $fastforward_there ]
 then
  echo " "
  echo "  --> Couldn't locate the fastforward Tarball"
  echo " "
  echo "  --> Would you like to download the fastforward Tarball."
  echo "      Enter either yor n."
read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 $fastforward_download
      f_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the fastforward tarball,"
      echo "      this will cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      f_there=n
    fi
 else
  echo " "
  echo "  --> Located the fastforward Tarball as $fastforward_there"
  echo " "
  echo " "
  f_there=y
fi

#End of fastforward check
 }

check_djbdns ( )
 {

#Start of djb dns check

echo " "
echo " "
echo "  --> Checking for the djbdns tarball"
djbdns_there=`ls | grep -i djbdns-1`
if [ -z $djbdns_there ]
 then
  echo " "
  echo "  --> Couldn't locate the djbdns Tarball"
  echo " "
  echo "  --> Would you like to download the djbdns Tarball."
  echo "      Enter either y or n."
  read answer2
    if [ $answer2 = $ans1 -o $answer2 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 $djbdns_download
      j_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the djbdns tarball,"
      echo "      this will cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
     echo " "
     j_there=n
    fi
 else
  echo " "
  echo "  --> Located the djbdns Tarball as $djbdns_there"
  echo " "
  echo " "
  j_there=y
fi

#End of djb dns check

 }

check_checkpassword ( )
 {

#Start of checkpassword check

echo "  --> Checking for the Checkpassword tarball"
checkpassword_there=`ls | grep -i checkpassword*.gz`
if [ -z $checkpassword_there ]
 then
  echo " "
  echo "  --> Couldn't locate the Checkpassword Tarball"
  echo " "
  echo "  --> Would you like to download the Checkpassword Tarball."
  echo "      Enter either y or n."
  read answerCP
   if [ $answerCP = $ans1 -o $answerCP = $ans2 ]
     then
      echo " "
      wget -c -v -t0 $checkpassword_download
      c_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the Checkpassword"
      echo "      tarball, this will cause an incomplete installation"
      echo "      of qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      c_there=n
    fi
 else
  echo " "
  echo "  --> Located the Checkpassword Tarball as $checkpassword_there"
  echo " "
  echo " "
  c_there=y
fi

#End of checkpassword check

}


daemontools_install ( )
 {

if [ $d_there=y ]
 then
#Starting compilation and Installation from source
  echo "  --> Untarring the daemontools Source"
  sleep 5
  tar -xvzf `ls | grep -i daemontools*.gz`
  mkdir /usr/libexec/daemontools
  mv admin /usr/libexec/daemontools
  temp_path=`pwd`
  cd /usr/libexec/daemontools/admin
  cd `ls | grep daemon`

 # Starting Compilation of daemontools
  ./package/install
  cd $temp_path
  #rm -fr ./admin

fi


}

ucspi_tcp_install ( )
 {

if [ $u_there=y ]
 then
#Starting compilation and Installation from source
  echo "  --> Untarring the ucspi_tcp Source"
  sleep 5
  tar -xvzf `ls | grep -i ucspi-tcp*.gz`
  cd `ls | grep -i ucspi*.gz | cut -d . -f1,2` 

 # Starting Compilation of daemontools
  make
  make setup check
  cd ..
  rm -fr ./`ls | grep -i ucspi*.gz | cut -d . -f1,2`

 fi

}



qmail_install ( )
 { 

if [ $q_there=y ]
 then

#Starting compilation and Installation from source  

#Creating the home directory for qmail
  mkdir /var/qmail
#Creating non system user accounts for qmail daemons
    groupadd nofiles
    useradd alias -g nofiles -d /var/qmail/alias -s /bin/false
    useradd qmaild -g nofiles -d /var/qmail -s /bin/false
    useradd qmaill -g nofiles -d /var/qmail -s /bin/false
    useradd qmailp -g nofiles -d /var/qmail -s /bin/false
    groupadd qmail
    useradd qmailq -g qmail -d /var/qmail -s /bin/false
    useradd qmailr -g qmail -d /var/qmail -s /bin/false
    useradd qmails -g qmail -d /var/qmail -s /bin/false

  echo "  --> Untarring the qmail Source"
  sleep 5
  tar -xvzf `ls | grep -i qmail-1*.gz`
  cd ./`ls | grep -i qmail-1*.gz | cut -d . -f1,2`
  
 # Starting Compilation of qmail
  make 
  make setup check
  echo " "
#  echo "  --> Enter your hostname+domain name eg geeky.freeos.com."
#  read d_name
#  ./config-fast $d_name

  ./config-fast $1

  cd ..
  rm -fr ./`ls | grep -i qmail-1*.gz | cut -d . -f1,2`

 # Starting with configuration of qmail

  if [ -d /etc/rc.d/init.d ]
    then
     echo "  --> /etc/rc.d/init.d found, continuing installation normally. " 
    else 
     echo "  --> /etc/rc.d/init.d not found, symlinking init.d to /etc/rc.d."
     ln -s /etc/rc.d /etc/rc.d/init.d     
  fi    

  cp ./qmail_needed/rc /var/qmail
  chmod 755 /var/qmail/rc
 
  cp ./qmail_needed/.qmail /etc/skel
  echo ./Maildir/ >/var/qmail/control/defaultdelivery
  /var/qmail/bin/maildirmake /etc/skel/Maildir 
  
  cp ./qmail_needed/qmailctl /var/qmail/bin 
  chmod 755 /var/qmail/bin/qmailctl
  ln -s /var/qmail/bin/qmailctl /usr/bin
  ln -s /var/qmail/bin/qmailctl /etc/rc.d/init.d/qmail
  
  if [ -d /etc/rc.d/init.d/rc0.d ]
   then
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/init.d/rc0.d/K30qmail
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/init.d/rc1.d/S80qmail
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/init.d/rc2.d/S80qmail
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/init.d/rc3.d/S80qmail
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/init.d/rc4.d/S80qmail
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/init.d/rc5.d/S80qmail
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/init.d/rc6.d/K30qmail
   else 
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/rc0.d/K30qmail
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/rc1.d/S80qmail
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/rc2.d/S80qmail
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/rc3.d/S80qmail
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/rc4.d/S80qmail
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/rc5.d/S80qmail
  ln -s /etc/rc.d/init.d/qmail  /etc/rc.d/rc6.d/K30qmail
   fi
 
  mkdir -p /service/qmail-send
  mkdir -p /service/qmail-send/log
  mkdir -p /service/qmail-smtpd
  mkdir -p /service/qmail-smtpd/log
  
  chmod +t /service/qmail-send
  chmod +t /service/qmail-send/log
  chmod +t /service/qmail-smtpd
  chmod +t /service/qmail-smtpd/log

  cp ./qmail_needed/qsend_run  /service/qmail-send/run
  chmod 755 /service/qmail-send/run
  cp ./qmail_needed/qsendlog_run  /service/qmail-send/log/run
  chmod 755 /service/qmail-send/log/run
  
  cp ./qmail_needed/qsmtpd_run  /service/qmail-smtpd/run
  chmod 755 /service/qmail-smtpd/run
  cp ./qmail_needed/qsmtpdlog_run  /service/qmail-smtpd/log/run
  chmod 755 /service/qmail-smtpd/log/run

  mkdir /var/qmail/log
  mkdir /var/qmail/log/smtpd
  chown qmaill /var/qmail/log
  chown qmaill /var/qmail/log/smtpd

  echo 20 > /var/qmail/control/concurrencyincoming
  chmod 644 /var/qmail/control/concurrencyincoming
  
  echo '127.:allow,RELAYCLIENT=""' >>/etc/tcp.smtp
  echo '$part1.$part2.:allow,RELAYCLIENT=""' >>/etc/tcp.smtp
  qmailctl cdb

  mv /usr/lib/sendmail /usr/lib/sendmail.old                  # ignore errors
  mv /usr/sbin/sendmail /usr/sbin/sendmail.old                # ignore errors
# chmod 0 /usr/lib/sendmail.old /usr/sbin/sendmail.old        # ignore errors
  ln -s /var/qmail/bin/sendmail /usr/lib
  ln -s /var/qmail/bin/sendmail /usr/sbin
 
#  echo "  --> Enter the login id of the person who'll recieve mail for root."
#  read root_alias
#  echo $root_alias > /var/qmail/alias/.qmail-root
#  echo $root_alias > /var/qmail/alias/.qmail-postmaster
#  echo $root_alias > /var/qmail/alias/.qmail-mailer-daemon

  echo $2 > /var/qmail/alias/.qmail-root
  echo $2 > /var/qmail/alias/.qmail-postmaster
  echo $2 > /var/qmail/alias/.qmail-mailer-daemon
  chmod 644 /var/qmail/alias/.qmail-root
  chmod 644 /var/qmail/alias/.qmail-postmaster
  chmod 644 /var/qmail/alias/.qmail-mailer-daemon

# Adding the qmail-pop3d daemon
   mkdir  /service/qmail-pop3d
   mkdir  /service/qmail-pop3d/log
   chmod +t /service/qmail-pop3d/
   chmod +t /service/qmail-pop3d/log/  

   cp ./qmail_needed/qpop3d_run /service/qmail-pop3d/run
   chmod 755 /service/qmail-pop3d/run
   cp ./qmail_needed/qpop3dlog_run  /service/qmail-pop3d/log/run 
   mkdir /var/qmail/log/pop3d
   chown qmaill /var/qmail/log/pop3d/

fi

}

rblsmtpd_install ( )
 {
 
if [ $r_there=y ]
 then
#Starting compilation and Installation from source
  echo "  --> Untarring the rblsmtpd Source"
  sleep 5
  tar -xvzf `ls | grep -i rblsmtpd*.gz`
  cd `ls | grep -i rblsmtpd*.gz | cut -d . -f1,2`

 # Starting Compilation of rblsmtpd
  make
  make setup check
  cd ..
  rm -fr ./`ls | grep -i rblsmtpd*.gz | cut -d . -f1,2`

fi

 }

fastforward_install ( )
 {

if [ $f_there=y ]
 then
#Starting compilation and Installation from source
  echo "  --> Untarring the fastforward Source"
  sleep 5
  tar -xvzf `ls | grep -i fastforward*.gz`
  cd `ls | grep -i fastforward*.gz | cut -d . -f1,2`

 # Starting Compilation of rblsmtpd
  make
  make setup check
  cd ..
  rm -fr ./`ls | grep -i fastforward*.gz | cut -d . -f1,2`

fi

 }


djbdns_install ( )
 {

if [ $j_there=y ]
 then
#Starting compilation and Installation from source

  echo "  --> Untarring the djbdns Source"
  sleep 5
  tar -xvzf `ls | grep -i djbdns-1`
  cd ./`ls | grep -i djbdns-1 | cut -d . -f1,2`

 # Starting Compilation of djb dns
  make
  make setup check
  cd ..
  rm -fr ./`ls | grep -i djbdns-1 | cut -d . -f1,2`


dns_configure ( )
 {

  groupadd dns
# useradd tinydns -g dns -d /etc/tinydns -s /bin/false
# useradd dnslog -g dns -d /etc/tinydns -s /bin/false
 useradd tinydns -g dns -M -s /bin/false
 useradd dnslog -g dns -M -s /bin/false

  echo " "
  echo " "
  echo "  --> Enter the IP address of your machine."
  read answer3
  tinydns-conf tinydns dnslog /etc/tinydns $answer3
  export answer3
  if [ -d /service ]
   then
   echo " "
   echo "  --> /service exists."
   ln -s /etc/tinydns tinydns
   mv tinydns /service
   echo " "
  else
    echo "  --> /service doesn't exist."
    echo " "
    echo "  --> creating /service."
    echo " "
    mkdir /service
    ln -s /etc/tinydns tinydns
    mv tinydns /service
  fi

 }

dns_postconfigure ( )
 {

  echo " "
  echo "  --> Enter the hostname+domain name(bom.freeos.com) of your machine."
  read answer5

#Separating the 32 bit IP address into 4 8 bit parts
  part1=`echo $answer3 | cut -d . -f1`
  part2=`echo $answer3 | cut -d . -f2`
  part3=`echo $answer3 | cut -d . -f3`
  part4=`echo $answer3 | cut -d . -f4`

  temp_dir=`pwd`
  cd /etc/tinydns/root
  ./add-ns $answer5 $answer3
  ./add-ns $part3.$part2.$part1.in-addr.arpa $answer3
  ./add-host $answer5 $answer3
  make
  echo " "
  echo " "
  cd $temp_dir
 
# Exporting IP address for use in qmail installation
  export part1
  export part2
  export part3
  export part4

# Moving existing /etc/resolv.conf to /etc/resolv/conf.bak
mv /etc/resolv.conf /etc/resolv.conf.bak
touch /etc/resolv.conf
echo "nameserver $answer3" > /etc/resolv.conf
cat /etc/resolv.conf.bak >> /etc/resolv.conf

}

dns_configure
dns_postconfigure

fi

}

checkpassword_install ( )
 {

if [ $c_there=y ]
 then
#Starting compilation and Installation from source
  echo "  --> Untarring the Checkpassword Source"
  sleep 5
  tar -xvzf `ls | grep -i checkpassword*.gz`
  cd `ls | grep -i checkpassword*.gz | cut -d . -f1,2`

 # Starting Compilation of daemontools
  make
  make setup check
  cd ..
  rm -fr ./`ls | grep -i checkpassword*.gz | cut -d . -f1,2`

fi

}

# Starting Web Based Mail installation.

check_tcl ( )
 {

#Starting to check for TCL

echo "  --> Checking for the TCL tarball"
tcl_there=`ls | grep -i tcl*.gz`
if [ -z $tcl_there ]
 then
  echo " "
  echo "  --> Couldn't locate the TCL Tarball"
  echo " "
  echo "  --> Would you like to download the TCL Tarball. Enter either
 y or n."
  read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 http://prdownloads.sourceforge.net/tcl/tcl8.4a3.tar.gz
      tl_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the TCL tarball, this will cause an incomplete installation of qmail Web Mail."
      echo "  --> Another option for you is to download the source tarball from
the designated site and place it in this directory and run this script again."
      echo " "
      tl_there=n
    fi
 else
  echo " "
  echo "  --> Located the TCL Tarball as $tcl_there"
  echo " "
  echo " "
  tl_there=y
fi

# End of TCL test


 }
 
check_expect ( )
  {

#Starting to check for Expect
echo "  --> Checking for the Expect tarball"
expect_there=`ls | grep -i expect*.gz`
if [ -z $expect_there ]
 then
  echo " "
  echo "  --> Couldn't locate the Expect Tarball"
  echo " "
  echo "  --> Would you like to download the Expect Tarball. Enter either
 y or n."
  read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 http://expect.nist.gov/expect.tar.gz
      ex_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the Expect tarball, this will cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball from
the designated site and place it in this directory and run this script again."
      echo " "
      ex_there=n
    fi
 else
  echo " "
  echo "  --> Located the Expect Tarball as $expect_there"
  echo " "
  echo " "
  ex_there=y
fi

# End of Expect test

  }


check_cimap ( )
 {

#Starting to check for Courier Imap

echo "  --> Checking for the Courier Imap tarball"
cimap_there=`ls | grep -i courier*.gz`
if [ -z $cimap_there ]
 then
  echo " "
  echo "  --> Couldn't locate the Courier Imap Tarball"
  echo " "
  echo "  --> Would you like to download the Courier Imap Tarball."
  echo "      Enter either y or n."
  read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0  $courier_download
      ci_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the Courier Imap tarball,"
      echo "      this will cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      ci_there=n
    fi
 else
  echo " "
  echo "  --> Located the Courier Tarball as $cimap_there"
  echo " "
  echo " "
  ci_there=y
fi

# End of Courier Imap test

 }

 check_sqwebmail ( )
 {

#Starting to check for Sqwebmail

echo "  --> Checking for the Sqwebmail tarball"
sqb_there=`ls | grep -i sqwebmail*.gz`
if [ -z $sqb_there ]
 then
  echo " "
  echo "  --> Couldn't locate the Sqwebmail Tarball"
  echo " "
  echo "  --> Would you like to download the Sqwebmail Tarball. Enter either
 y or n."
  read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 http://www.courier-mta.org/beta/sqwebmail/sqwebmail-3.0.0.20010827.tar.gz
      sq_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the Sqwebmail tarball, thiswill cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball from
the designated site and place it in this directory and run this script again."
      echo " "
      sq_there=n
    fi
 else
  echo " "
  echo "  --> Located the Sqwebmail Tarball as $sqb_there"
  echo " "
  echo " "
  sq_there=y
fi

# End of Sqwebmail test

 }

tcl_install ( )
 {

if [ $tl_there=y ]
 then
#Starting compilation and Installation from source
  echo "  --> Untarring the TCL Source"
  sleep 5
  tar -xvzf `ls | grep -i tcl*.gz`
  cd `ls | grep -i tcl*.gz | cut -d . -f1,2`
  cd unix
 
 # Starting Compilation of TCL
  ./configure
  make
  make install
  cd ../..

# Deleting the TCL source directory after installation of Expect
# rm -fr ./`ls | grep -i tcl*.gz | cut -d . -f1,2`

fi

 }

expect_install ( )
 {

if [ $ex_there=y ]
 then
#Starting compilation and Installation from source
  tcl_location=`ls | grep -i tcl*.gz | cut -d . -f1,2`
  echo "  --> Untarring the Expect Source"
  sleep 5
  tar -xvzf `ls | grep -i expect*.gz`
  cd expect-*

 # Starting Compilation of expect
  ./configure --with-tcl=../$tcl_location/unix
  make
  make install
  cd ..

  rm -fr ./`ls | grep -i fastforward*.gz | cut -d . -f1,2`
  rm -fr ./`ls | grep -i tcl*.gz | cut -d . -f1,2`

fi

 }

courier_install ( )
 {

if [ $ci_there=y ]
 then
#Starting compilation and Installation from source
  echo "  --> Untarring the Courier Imap Source"
  sleep 5
  tar -xvzf `ls | grep -i courier*.gz`
  cd courier-imap*

# Starting Compilation of Courier Imap
  echo " "
  echo " --> The installation of Courier Imap requires either "
  echo "     GDBM/DB - either the GDBM or the Berkeley DB library"
  echo "     is required."
  echo " --> If the configure script screams and aborts abruptly,"
  echo "     pliss install either the gd library or gdbm and re-run"
  echo "     this script."
  echo " "
  echo " --> Courier Imap cannot be built as ROOT, pliss supply a "
  echo "     normal user id on this machine to continue."
  echo "     If you have downloaded the scripts to say "
  echo "     e.g. /home/geekybabe or /home/geekybabe/xyz/ , then give"
  echo "     the username as geekybabe. If you are running this script"
  echo "     from /tmp then any username will do."
  echo " "
  echo " --> Courier Imap cannot be built as ROOT, pliss supply a"
  echo "     normal user id on this machine to continue."
#  read username
#  su $username -c ./configure;make
  su $1 -c ./configure;make
  make install     
  make install-configure 
  cd ..
  cp courier-imap*.gz /tmp
  rm -fr ./courier-imap*
  mv /tmp/courier-imap*.gz .
  mv /usr/lib/courier-imap/libexec/authlib/authdaemond.ldap  /usr/lib/courier-imap/libexec/authlib/authdaemond.ldap.bak
if [ -f /etc/rc.d/boot.local ]
  then

     modify_cimap=`grep -i cimap_mod /etc/rc.d/boot.local`
     if [ -z $modify_cimap ]
      then
      echo "#Please don't remove these lines. Added by QMAILTHEASYWAY installer( cimap_mod )." >>  /etc/rc.d/boot.local     
      echo "/usr/lib/courier-imap/libexec/imapd.rc start" >> /etc/rc.d/boot.local
     fi

  else 

     modify_cimap=`grep -i cimap_mod /etc/rc.d/rc.local`
     if [ -z $modify_cimap ]
      then
      echo "#Please don't remove these lines. Added by QMAILTHEASYWAY installer( cimap_mod )." >> /etc/rc.d/rc.local
      echo "/usr/lib/courier-imap/libexec/imapd.rc start" >> /etc/rc.d/rc.local
     fi

fi

fi

}


sqwebmail_install ( )
 {

if [ $sq_there=y ]
 then
#Starting compilation and Installation from source
  echo "  --> Untarring the Sqwebmail Source"
  sleep 5
  tar -xvzf `ls | grep -i sqwebmail*.gz`
  cd sqwebmail-*

 # Starting Compilation of Sqwebmail
 if [ -d /var/www ]
  then
  ./configure --with-cachedir=/var/cache/sqwebmail --enable-imagedir=/var/www/html/webmail --enable-cgibindir=/var/www/html/webmail --with-module=authpam
  else
    ./configure --with-cachedir=/var/cache/sqwebmail --enable-imagedir=/usr/local/httpd/htdocs/webmail --enable-cgibindir=/usr/local/httpd/htdocs/webmail --with-module=authpam
 fi
  make
  make install
  make install-configure
  cd ..
  cp sqwebmail-*.gz /tmp
  rm -fr ./sqwebmail-*
  mv /tmp/sqwebmail-*.gz .

 if [ -f /etc/rc.d/boot.local ]
  then
   echo "/usr/local/share/sqwebmail/libexec/authlib/authdaemond start
" >> /etc/rc.d/boot.local
   mv /usr/local/share/sqwebmail/libexec/authlib/authdaemond.ldap  /usr/local/share/sqwebmail/libexec/authlib/authdaemond.ldap_bak
  else
   echo "/usr/local/share/sqwebmail/libexec/authlib/authdaemond start
" >> /etc/rc.d/rc.local
   mv /usr/local/share/sqwebmail/libexec/authlib/authdaemond.ldap  /usr/local/share/sqwebmail/libexec/authlib/authdaemond.ldap_bak
fi

if [ -f /etc/httpd/httpd.conf ]
 then
  mkdir /usr/local/httpd/htdocs/webmail_cgi
  cp  /usr/local/httpd/htdocs/webmail/sqwebmail /usr/local/httpd/htdocs/webmail_cgi
  echo " " >> /etc/httpd/httpd.conf
  echo " " >> /etc/httpd/httpd.conf
  echo "<Directory "/usr/local/httpd/htdocs/webmail_cgi">" >> /etc/httpd/httpd.conf
  echo "AllowOverride None" >> /etc/httpd/httpd.conf
  echo "Options None" >> /etc/httpd/httpd.conf
  echo "Order allow,deny" >> /etc/httpd/httpd.conf
  echo "Allow from all" >> /etc/httpd/httpd.conf
  echo "Options +ExecCGI -Includes" >> /etc/httpd/httpd.conf
  echo "SetHandler cgi-script" >> /etc/httpd/httpd.conf
  echo "</Directory>" >> /etc/httpd/httpd.conf
  /etc/rc.d/init.d/apache restart
 else
  echo " " >> /etc/httpd/conf/httpd.conf
  echo " " >> /etc/httpd/conf/httpd.conf
  mkdir /var/www/html/webmail_cgi
  cp  /var/www/html/webmail/sqwebmail /var/www/html/webmail_cgi
    echo "<Directory "/var/www/html/webmail_cgi">" >> /etc/httpd/conf/httpd.conf
  echo "AllowOverride None" >> /etc/httpd/conf/httpd.conf
  echo "Options None" >> /etc/httpd/conf/httpd.conf
  echo "Order allow,deny" >> /etc/httpd/conf/httpd.conf
  echo "Allow from all" >> /etc/httpd/conf/httpd.conf
  echo "Options +ExecCGI -Includes" >> /etc/httpd/conf/httpd.conf
  echo "SetHandler cgi-script" >> /etc/httpd/conf/httpd.conf
  echo "</Directory>" >> /etc/httpd/conf/httpd.conf
  /etc/rc.d/init.d/httpd restart

fi

echo " "
echo " "
echo "  --> To Use Web Mail just connect to http://localhost/webmail_cgi/sqwebmail " 
echo " "
echo " " 


fi

}

big_warn ( )
 {

echo " "
echo " "
echo "                         PLEASE NOTE  "
echo "  --> Continuing with this installation will require you to "
echo "      have the following tools in the current directory on your"
echo "      disk else it will prompt for downloading them from the net."
echo " "
echo "  --> Courier-imap  1.14MB"
echo "  --> Expect         494KB"
echo "  --> Sqwebmail     1.19MB"
echo "  --> tcl Source     2.7MB"
echo " "
echo "  --> You can manually download these tools from the links provided"
echo "      in the README file and prevent the script from downloading"
echo "      the sources from the Internet."
echo "  --> !!! Else are u ready for a Bandwidth resource hogger. "
echo "      If no press CTRL+C to ABORT !!!! "          
sleep 15
echo " "
echo " " 

}


#Starting Installation of IMP+HORDE

big_warn_imp ( )
 {
clear
echo " "
echo " "
echo "                         PLEASE NOTE  "
echo "  --> Continuing with this installation will require you to"
echo "      have the following tools in the current directory on your"
echo "      disk else it will prompt for downloading them from the net."
echo " "
echo "  --> Also ensure that you have Apache with APXS(The Apache-devel"
echo "      RPM on RH) Installed."
echo " "
echo "  -->  MySQL Server  4.15MB  -->  MySQL Client   116KB"
echo "  -->  MySQL Devel    443KB  -->  IMP           363KB"
echo "  -->  HORDE          143KB  -->  Courier Imap  1.14MB" 
echo "  -->  W Imap         1.9MB  -->  PHP           3.15MB"
echo " "
echo "  --> You can manually download these tools from the links "
echo "      provided in the README file and prevent the script from"
echo "      downloading the sources from the Internet."
echo "  --> !!! Else are u ready for a Bandwidth resource hogger."
echo "      If no press CTRL+C to ABORT !!!! "
sleep 15
echo " "
echo " "

 }


check_imp ( )
 {
#Starting to check for IMP

echo "  --> Checking for the IMP tarball"
imp_there=`ls | grep -i imp*.gz`
if [ -z $imp_there ]
 then
  echo " "
  echo "  --> Couldn't locate the IMP Tarball"
  echo " "
  echo "  --> Would you like to download the IMP Tarball."
  echo "      Enter either y or n".
  read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 $imp_download
      impgz_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the IMP tarball,"
      echo "      this will cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      impgz_there=n
    fi
 else
  echo " "
  echo "  --> Located the IMP Tarball as $imp_there"
  echo " "
  echo " "
  impgz_there=y
fi

# End of IMP test


 }

check_horde ( )
 {
#Starting to check for HORDE

echo "  --> Checking for the HORDE tarball"
horde_there=`ls | grep -i horde*.gz`
if [ -z $horde_there ]
 then
  echo " "
  echo "  --> Couldn't locate the HORDE Tarball"
  echo " "
  echo "  --> Would you like to download the HORDE Tarball."
  echo "      Enter either y or n."
  read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0  $horde_download
      hor_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the HORDE tarball,"
      echo "      this will cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      hor_there=n
    fi
 else
  echo " "
  echo "  --> Located the HORDE Tarball as $horde_there"
  echo " "
  echo " "
  hor_there=y
fi

# End of HORDE test

 }

check_w_imap ( )
 {

#Starting to check for W Imap

echo "  --> Checking for the W Imap tarball"
wimap_there=`ls | grep -i imap.tar.Z`
if [ -z $wimap_there ]
 then
  echo " "
  echo "  --> Couldn't locate the Imap Tarball"
  echo " "
  echo "  --> Would you like to download the Imap Tarball."
  echo "      Enter either y or n."
  read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 $wimap_download
      wim_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the IMAP tarball,"
      echo "      this will cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      wim_there=n
    fi
 else
  echo " "
  echo "  --> Located the W IMAP Tarball as $wimap_there"
  echo " "
  echo " "
  wim_there=y
fi

# End of W IMAP test

 }

check_mysql ( )
 {

#Starting to check for MySQL

echo "  --> Checking for the MySQL RPM"
mysql_there1=`ls | grep -i MySQL-devel*.rpm`
mysql_there2=`ls | grep -i MySQL-client*.rpm`
mysql_there3=`ls | grep -i MySQL-3*.rpm`


#Start of MySQL Server Test

if [ -z $mysql_there3 ]
 then
  echo "  --> Couldn't locate the MySQL Server RPM."
  echo " "
  echo "  --> Would you like to download the MySQL Server RPM."
  echo "      Enter either y or n."
  read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 $mysql_server_download
      my3_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the MySQL Server,"
      echo "      this will cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      my3_there=n
    fi
else
  echo " "
  echo "  --> Located the MySQL Server RPM as $mysql_there1"
  echo " "
  echo " "
  my3_there=y
fi

#End of MySQL Server test

#Start MySQL client test
if [ -z $mysql_there2 ]
 then 
 echo "  --> Couldn't locate the MySQL Client RPM."
  echo " "
  echo "  --> Would you like to download the MySQL Client RPM."
  echo "      Enter either y or n."
  read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 $mysql_client_download
      my2_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the MySQL Client,"
      echo "      this will cause an incomplete installation of Qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      my2_there=n
    fi
 else
  echo " "
  echo "  --> Located the MySQL Client RPM as $mysql_there2"
  echo " "
  echo " "
  my2_there=y
fi

#End of MySQL client test


#Start of MySQL Devel test
if [ -z $mysql_there1 ]
 then
  echo "  --> Couldn't locate the MySQL Devel RPM."
  echo " "
  echo "  --> Would you like to download the MySQL Devel RPM."
  echo "      Enter either y or n."
  read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 $mysql_devel_download
      my1_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the MySQL Devel,"
      echo "      this will cause an incomplete installation of Qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      my1_there=n
    fi
 else
  echo " "
  echo "  --> Located the MySQL Devel RPM as $mysql_there1"
  echo " "
  echo " "
  my1_there=y
fi

#End of MySQL Devel test

 
#End of MySQL Test
 
 }

check_php ( )
 {

#Starting to check for PHP

echo "  --> Checking for the PHP tarball"
php_there=`ls php-4*.gz`
if [ -z $php_there ]
 then
  echo " "
  echo "  --> Couldn't locate the PHP Tarball"
  echo " "
  echo "  --> Would you like to download the PHP Tarball."
  echo "      Enter either y or n"
  read answer4
    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
     then
      echo " "
      wget -c -v -t0 $php_download
      ph_there=y
     else
      echo " "
      echo "  --> You have choosen not to download the PHP tarball,"
      echo "      this will cause an incomplete installation of qmail."
      echo "  --> Another option for you is to download the source tarball"
      echo "      from the designated site and place it in this directory"
      echo "      and run this script again."
      echo " "
      ph_there=n
    fi
 else
  echo " "
  echo "  --> Located the PHP Tarball as $php_there"
  echo "  --> Also make sure that you have installed APXSi else "
  echo "      things won't work, on RedHat you need to install"
  echo "      the apache-devel RPM."
  echo " "
  echo " "
  ph_there=y
fi

# End of PHP test

 }


imp_install ( )
 {

if [ $impgz_there=y ]
 then 
 echo " "
 echo " "
 tar -xvzf imp-latest.tar.gz

#Finding location of the Document root of Apache.
  if [ -d /var/www/html ]
   then
    mv imp-2.*  /var/www/html/horde/imp
    temp_path=`pwd`
    cd /var/www/html/horde/
    ./install.sh
    cd $temp_path
    cp ./qmail_needed/local.inc /var/www/html/horde/phplib/
 
    echo " "
    echo " "
    echo "                     V.V. IMP"
    echo "  --> Your blank configuration files have been created,"
    echo "      please open up a browser and go to the configuration"
    echo "      utility at:  http://localhost/horde/setup.php3 "
    echo "      to customise your Configuration."
    echo " "
    echo "  --> Accept all the Defaults, but when prompted for a "
    echo "      Database say 'True' and Select 'MySQL' as the Database." 
    echo " "
    echo "  --> After Completing the above customisation enter y to continue."
#   read answer4
#    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
#     then
    /etc/rc.d/init.d/httpd restart 
    ./WARNING
        /etc/rc.d/init.d/mysql stop
        /etc/rc.d/init.d/mysql start
        echo " "
        echo "  --> Enter the Password for MySQL Database Access."
        echo "      If you have just installed MySQL then just " 
        echo "      press Enter to continue."
#       read mysql_password 
#        mysql -u root -p $mysql_password < /var/www/html/horde/scripts/database/mysql_create.sql
         mysql -u root -password=$1 < /var/www/html/horde/scripts/database/mysql_create.sql
        temp_path1=`pwd`
        cd /var/www/html/horde/
        ./secure.sh
        cd $temp_path1
#     fi

   else
    mv horde-1.*  /usr/local/httpd/htdocs/horde
    temp_path=`pwd`
    cd /usr/local/httpd/htdocs/horde/
    ./install.sh
    cd $temp_path
    cp ./qmail_needed/local.inc /usr/local/httpd/htdocs/horde/phplib/
  
    echo " "
    echo " "
    echo "                     V.V. IMP"
    echo "  --> Your blank configuration files have been created,"
    echo "      please open up a browser and go to the configuration"
    echo "      utility at:  http://ur_machine_name/horde/setup.php3"
    echo "      to customise your Configuration."
    echo " "
    echo "  --> Accept all the Defaults, but when prompted for a Database"
    echo "      say 'True' and Select 'MySQL' as the Database."
    echo " "
    echo "  --> After Completing the above customisation enter y to continue."
# read answer4
#    if [ $answer4 = $ans1 -o $answer4 = $ans2 ]
#     then
     /etc/rc.d/init.d/apache restart 
     ./WARNING
        /etc/rc.d/init.d/mysql stop
        /etc/rc.d/init.d/mysql start
        echo " "
        echo "  --> Enter the Password for MySQL Database Access."
        echo "      If you have just installed MySQL then just press"
        echo "      Enter to continue."
#        read mysql_password
#       mysql -u root -p $mysql_password < /usr/local/httpd/htdocs/horde/scripts/database/mysql_create.sql
        mysql -u root -password=$1 < /usr/local/httpd/htdocs/horde/scripts/database/mysql_create.sql
        temp_path1=`pwd`
        cd /usr/local/httpd/htdocs/horde/
        ./secure.sh
        cd $temp_path1
#   fi
  fi
fi
 
 }

horde_install ( )
 {

 if [ $hor_there=y ]
  then
   tar -xvzf horde-latest.tar.gz 

#Finding location of the Document root of Apache.
  if [ -d /var/www/html ]
   then
    mv horde-1.*  /var/www/html/horde
    cp  /var/www/html/horde/config/horde.php3.dist /var/www/html/horde/config/horde.php3

   else
    mv horde-1.*  /usr/local/httpd/htdocs/horde      
    cp /usr/local/httpd/htdocs/horde/config/horde.php3.dist /usr/local/httpd/htdocs/horde/config/horde.php3

  fi
   
 fi

 } 

w_imap_install ( )
 {

if [ $wim_there=y ]
 then
 echo " "
 echo " "
#These libraries r needed in addition to the Courier Imap installation for purpose of PHP compilation only.
 echo " --> Starting with the Imap(Washington Univ) Compilation." 
 echo " "
 echo " --> Untarring the Imap(Washington Univ) Tarball."
 sleep 5
 tar -xvzf imap.tar.Z 
 cd imap-*
 make lnp
 cd ..
fi 

 }


php_install ( )
 {
if [ $ph_there=y ]
 then
 echo " "
 echo " "
 echo " --> Starting PHP installation."
 echo " "
 echo " --> Untarring the PHP Tarball."
 sleep 5
 tar -xvzf php*.gz 
 cd php-4.0.6
 ./configure --with-mysql --with-apxs --with-imap=../imap-*
 make 
 make install

if [ -f /etc/httpd/httpd.conf ]
 then

#  Testing for existing entries in the HTTPD.CONF file.
   php_addtype=`grep -i qtew_php_mod /etc/httpd/httpd.conf`
    if [ -z $php_addtype ]
     then

  echo " " >> /etc/httpd/httpd.conf
  echo " " >> /etc/httpd/httpd.conf
  echo "# Please don't remove, these are the PHP Includes( qtew_php_mod )." >> /etc/httpd/httpd.conf
  echo " AddType application/x-httpd-php .php" >> /etc/httpd/httpd.conf
  echo " AddType application/x-httpd-php .php4" >> /etc/httpd/httpd.conf
  echo " AddType application/x-httpd-php .php3" >> /etc/httpd/httpd.conf
  echo " AddType application/x-httpd-php-source .phps" >> /etc/httpd/httpd.conf
  echo " " >> /etc/httpd/httpd.conf
  echo " " >> /etc/httpd/httpd.conf
  echo "<Directory /usr/local/httpd/htdocs/horde>" >> /etc/httpd/httpd.conf
  echo "Options Indexes FollowSymLinks" >> /etc/httpd/httpd.conf
  echo "AllowOverride None" >> /etc/httpd/httpd.conf
  echo "Order allow,deny" >> /etc/httpd/httpd.conf
  echo "Allow from all" >> /etc/httpd/httpd.conf
  echo "php_value include_path '/usr/local/httpd/htdocs/horde/phplib:.'" >> /etc/httpd/httpd.conf
  echo "php_value auto_prepend_file /usr/local/httpd/htdocs/horde/phplib/prepend.php3" >> /etc/httpd/httpd.conf
 echo "php_flag register_globals On" >> /etc/httpd/httpd.conf
 echo "php_flag magic_quotes_gpc Off" >> /etc/httpd/httpd.conf
 echo "php_flag track_vars On" >> /etc/httpd/httpd.conf
 echo "</Directory>" >> /etc/httpd/httpd.conf
 echo " "
 echo "  --> Restarting APACHE"
 /etc/rc.d/init.d/apache restart
 
     fi
#End of test for includes in /etc/httpd/httpd.conf

  else  
#  Testing for existing entries in the HTTPD.CONF file.
   php_addtype=`grep -i qtew_php_mod  /etc/httpd/conf/httpd.conf`
    if [ -z $php_addtype ]
     then

  echo " " >> /etc/httpd/conf/httpd.conf
  echo " " >> /etc/httpd/conf/httpd.conf
  echo "# Please don't remove, these are the PHP Includes( qtew_php_mod )." >>  /etc/httpd/conf/httpd.conf
  echo " AddType application/x-httpd-php .php" >> /etc/httpd/conf/httpd.conf
  echo " AddType application/x-httpd-php .php4" >> /etc/httpd/conf/httpd.conf
  echo " AddType application/x-httpd-php .php3" >> /etc/httpd/conf/httpd.conf
  echo " AddType application/x-httpd-php-source .phps" >> /etc/httpd/conf/httpd.conf
  echo " " >> /etc/httpd/conf/httpd.conf
  echo " " >>  /etc/httpd/conf/httpd.conf
  echo "<Directory /var/www/html/horde>" >> /etc/httpd/conf/httpd.conf
  echo "Options Indexes FollowSymLinks" >> /etc/httpd/conf/httpd.conf
  echo "AllowOverride None" >> /etc/httpd/conf/httpd.conf
  echo "Order allow,deny" >> /etc/httpd/conf/httpd.conf
  echo "Allow from all" >> /etc/httpd/conf/httpd.conf
  echo "php_value include_path '/var/www/html/horde/phplib:.'" >> /etc/httpd/conf/httpd.conf
  echo "php_value auto_prepend_file /var/www/html/horde/phplib/prepend.php3" >> /etc/httpd/conf/httpd.conf
 echo "php_flag register_globals On" >> /etc/httpd/conf/httpd.conf
 echo "php_flag magic_quotes_gpc Off" >> /etc/httpd/conf/httpd.conf
 echo "php_flag track_vars On" >> /etc/httpd/conf/httpd.conf
 echo "</Directory>" >> /etc/httpd/conf/httpd.conf
 echo "  --> Restarting APACHE"
 /etc/rc.d/init.d/httpd restart


     fi
#End of test for includes in /etc/httpd/conf/httpd.conf


 fi

 cd ..
 cp php*.gz /tmp
 rm -fr ./php-*
 rm -fr ./imap-*
 mv /tmp/php*.gz .
fi

 }

mysql_install ( )
 {

if [ $my3_there=y ]
 then
  echo " "
  echo "  --> Installing the MySQL Server"
  rpm -ivh MySQL-3.2*
  echo " " 
fi

if [ $my2_there=y ]
 then
  echo " "
  echo "  --> Installing the MySQL Client"
  rpm -ivh MySQL-client*
  echo " "
fi

if [ $my1_there=y ]
 then
  echo " "
  echo "  --> Installing the MySQL Devel"
  rpm -ivh MySQL-devel*
  echo " "
fi

echo " "
echo "  --> Starting the MySQL Daemon "
/etc/rc.d/init.d/mysql start
echo " "
echo " "

 if [ -L /tmp/mysql.sock ]
  then 
   echo " "
  else
   ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock 
 fi

 }

#calling the installation greeting message
start

#testing for a wget installation
check_wget

#testing for and installing Apache 
#check_n_nstall_apache

#testing for and installing Squid
#check_n_nstall_squid

#calling the daemontools installation
check_daemontools
daemontools_install

#installing djb dns
#check_djbdns
#djbdns_install

#calling ucspi-tcp installation
check_ucspi_tcp
ucspi_tcp_install

#calling the rblsmtpd installation
check_rblsmtpd
rblsmtpd_install

#calling the fastforward installation
check_fastforward
fastforward_install

#calling the checkpassword installation
check_checkpassword
checkpassword_install

#Calling the qmail installation
check_qmail
qmail_install $1 $2
init q

#Starting the IMP+HORDE installationn
#big_warn_imp

#Calling the Courier Imap Installer function
#check_cimap
#courier_install $2

#Calling the Imap(Washington Univ) installer function
#check_w_imap
#w_imap_install

#Caling the PHP installation
#check_php
#php_install

#Calling the MySQL Installation
#check_mysql
#mysql_install

#Calling the Horde Instllation
#check_horde
#horde_install

#Calling the IMP Installation
#check_imp
#imp_install $3

#Calling the Webmin installlation
#check_n_nstall_webmin

#calling the installation termination message
stop
