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

pathtosrc=$(ls | grep $archname1)
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/$dirname
        cmake -DAPACHE_USER:string=nobody && make && make install)
                                      
if [ $? != 0 ]; then
{
    echo "Linking module error..."
    exit 1
} fi
rm -rf $CMAKE_SRC
rm -f $archname1
                                                                                       
echo "Daemon&module 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

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



                          