#!/bin/bash
#Copyright 2010 (c) syslint.com
RED='\033[01;31m'
GREEN='\033[01;32m'
RESET='\033[0m'
clear
echo -e "$GREEN*************************************************************$RESET"
echo -e "     Directadmin Apache 2.2 + PHP5.2 + Suphp + Suexec Autobuild script"
echo -e "          Copyright (c) 2008-2011  http://syslint.com/ "
echo -e "         Your  Directadmin Server Management Partner  "
echo -e "$GREEN*************************************************************$RESET"
echo " "
echo " "

echo "The installation will start within  10 seconds "
sleep 10
cd /usr/local/directadmin/custombuild

./build clean
echo -ne "Cleaning  for custome build   .."
echo -e "[ $GREEN done $RESET ]"
./build update
echo -ne "updating custome build .."
echo -e "[ $GREEN done $RESET ]"


mkdir -pv custom/ap2
mkdir -pv custom/suphp

echo -ne " Creating custom folder /usr/local/directadmin/custombuild/custom " 
echo -e "[ $GREEN done $RESET ]"

rm -rf custom/ap2/*
rm -rf custom/suphp/*

echo -ne " Cleaning Custom Folder .. "
echo -e "[ $GREEN done $RESET ]"

echo -ne " Downloading configure template ... "
wget -c http://files.syslint.com/da/conf/suphp/configure.apache.conf
mv -vf  configure.apache.conf  custom/ap2/configure.apache
wget -c http://files.syslint.com/da/conf/suphp/configure.php5.conf
mv -vf  configure.php5.conf  custom/ap2/configure.php5
cp -vf  custom/ap2/configure.php5 custom/suphp/
wget -c http://files.syslint.com/da/conf/suphp/configure.suphp.conf
mv -vf configure.suphp.conf custom/suphp/configure.suphp
chmod 755 custom/ap2/*
chmod 755 custom/suphp/*
echo -e "[ $GREEN done $RESET ]"

echo -ne "Changing php5-cli to php5-cgi ..."
sed -i 's/php5_cgi=.*/php5_cgi=yes/g'   /usr/local/directadmin/custombuild/options.conf
sed -i 's/php5_cli=.*/php5_cli=no/g'  /usr/local/directadmin/custombuild/options.conf
echo -e "[ $GREEN done $RESET ]"

echo -ne "Starting apache Build"
./build apache
echo -ne "Starting php build"
./build php 5

echo -ne " Creating /usr/local/lib/php.d .."
mkdir -p /usr/local/lib/php.d
echo -e "[ $GREEN done $RESET ]"
echo -ne "Creating Soft links ...."
ln -sf  /usr/local/bin/php-cgi /usr/local/bin/php
ln -sf /usr/local/bin/php /usr/bin/php
echo -e "[ $GREEN done $RESET ]"
echo -ne "Editing /usr/local/suphp/etc/suphp.conf ..."
sed -i 's/x-httpd-php5=.*/x-httpd-php5=\"php:\/usr\/local\/bin\/php-cgi\"/g' /usr/local/suphp/etc/suphp.conf
echo -e "[ $GREEN done $RESET ]"
echo -ne "Setting php.ini path .."
sed -i 's/suPHP_ConfigPath.*/suPHP_ConfigPath\  \/usr\/local\/lib\//g' /etc/httpd/conf/extra/httpd-suphp.conf
echo -e "[ $GREEN done $RESET ]"
/etc/init.d/httpd restart

echo -e "--------------------------------------------------------------------------------------------------------------"
echo -e "                               Installation Completed"
echo -e " Get Support for your Directadmin Server from $GREEN http://syslint.com/DirectAdmin-Server-Management$RESET"
echo -e "--------------------------------------------------------------------------------------------------------------"

