#!/bin/bash
#CLOUD HOOKLIMIT INSTALL
currentpath=$(pwd)
cd /tmp
echo -n "Getting mod_hostinglimits..."
wget "$FTPSERVERSRC/$MODLIMSRC"
if [ $? != 0 ]; then
{
    echo $FAILED
    exit 1
} 
fi
echo $OK

pathtosrc=$(ls | grep "$archname2.tar.gz")
if [ -z "$pathtosrc" ]; then 
    echo $FAILED
    echo "Can't find module's sources"
    exit 1    
fi
          
CMAKE_SRC=tmpcmakesrc
mkdir -p $CMAKE_SRC
tar -zxvf $pathtosrc -C $CMAKE_SRC
(cd $CMAKE_SRC/$archname2
        cmake . && make && make install)
                                      
if [ $? != 0 ]; then
{
    echo "Linking mod_hostinglimits error..."
    exit 1
} fi
rm -rf $CMAKE_SRC
rm -f "$archname2.tar.gz"
                                                                                       
echo "mod_hostinglimits comlete well..."

#modify cpanel's apache config file
pathtoconfig1="/var/cpanel/templates/apache2"

if [ -e "$pathtoconfig1/main.default" ]; then
 sed 's/Include "\/usr\/local\/apache\/conf\/conf\.d\/\*"/ /g' "$pathtoconfig1/main.default" > main2.default
 sed 's/<Location \/whm-server-status>/Include "\/usr\/local\/apache\/conf\/conf\.d\/\*"\n<Location \/whm-server-status>/g' main2.default > main.default     
 cp main.default $pathtoconfig1
 rm main.default
 rm main2.default
 echo "Conf modified ok..."
            
else 
          
 echo "Cann't find template file"
                           
fi

if [ -e "$pathtoconfig3/main.default" ]; then
 sed 's/Include "\/usr\/local\/apache\/conf\/conf\.d\/\*"/ /g' "$pathtoconfig3/main.default" > main2.default
 sed 's/<Location \/whm-server-status>/Include "\/usr\/local\/apache\/conf\/conf\.d\/\*"\n<Location \/whm-server-status>/g' main2.default > main.default     
 cp main.default $pathtoconfig3
 rm main.default
 rm main2.default
 echo "Conf modified ok..."
            
else 
          
 echo "Cann't find template file"
                           
fi

rebuildscript="/scripts/rebuildhttpdconf"
if [ -e "$rebuildscript" ]; then
 "$rebuildscript"
 echo "Rebuilding conf ok..."
else
 echo "Rubuilding faild..."
fi
                                            
cd $currentpath
                                                       



                          