#!/bin/bash
#CLOUD MCGIDPATCH INSTALL

currentpath=$(pwd)
cd /tmp

rm -f $patch_name
wget $FTPSERVERSRC/$patch_name
if [ -e "$patch_name" ];then
 CURR_PATH=$(pwd)
 cd /home/cpeasyapache/src
 ls -1d httpd-2* 2>/dev/null| while read dirname;
 do
    echo $dirname
    if [ -d "$dirname" ];then
	cp $CURR_PATH/$patch_name $dirname/$patch_name
	cd "$dirname"
	patch -p0 -f < $patch_name
	if [ $? != 0 ];then
	    echo "Can't apply patch. Call to support-center of CloudLinux..."
	    cd $currentpath
	    exit 1
	else 
	    echo "Patch was correct applied..."
	fi
	cd - 
    fi
 done
 cd $CURR_PATH
else
 echo "Can't find $patch_name. Wget must be installed..."
 cd $currentpath
 exit 1
fi

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 "$PATH_TO_CONFIG/conf.d" ]; then                                                                                                           
    echo "Check for conf.d... Ok"                                                                                           
else                                                                                                                                         
    mkdir "$PATH_TO_CONFIG/conf.d"                                                                                                                 
    echo "Check for conf.d...Created Ok"
fi   

echo "SuexecEnableLVE on" > $PATH_TO_CONFIG/conf.d/sumodcgid.conf                                                        
    
cd $currentpath
                                                       



                          
