\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7<F<2PFAFZUP_xxnnx\F5\AF\B9\91\C8\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\DB\00CUZZxix‚\EB\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\C0\00\00b\00d\00\FF\C4\00\00\00\00\00\00\00\00\00\00\00\00\00\00\FF\C4\00\00\00\00\00\00\00\00\00\00\001A!Q\FF\C4\00\00\00\00\00\00\00\00\00\00\00\00\00\FF\C4\00\00\00\00\00\00\00\00\00\00!1AQ\FF\DA\00\00\00?\00\F6\00\00\00\00\00\00\00\00\00\00\A0\00\00\C5\CF\F8\E7Ó\FCjD~\B9^\AD\%\B3]\D8cs-\BBs,-\A0\00"\80\00%\B83rÏ^K~F\A4ea\00E\00\C6\EE=u\B1\9B\D1\00@\00r\BE8\F9:\FE5#.M\00\E7\CB\C9q\CBq\D6\F2\BE\B7\C7>\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7	\8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh
\00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€
\00$\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95
59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>C///</title>
</head>
#!/bin/sh

###########
# need to replace the following
# 	PHP_VERSION = {PHP_VERSION}
# 	PHP_CONF_OPTIONS = {PHP_CONF_OPTIONS}
#	LSWS_HOME = {LSWS_HOME}
############

check_errs()
{
  if [ "${1}" -ne "0" ] ; then
     
    echo "*********************************************"
    echo "**"
    echo "**  BUILD MATCHING PHP FAILED  **************"
    echo "**" 
    echo "**  -- ERROR -- ${2}"
    echo "*********************************************"
     
    exit ${1}
  fi
}

test_phpsrc_ok()
{
	echo "Extracting PHP source archive: tar -zxf ${1}" 
	tar -zxf ${1}
	if [ "$?" -ne "0" ] ; then
		## remove bad copy
		rm -f ${1}
		echo "Could not extract PHP source archive"
		return 1
	fi
	return 0
}

echo ""
echo "=============================================="
echo "Start building PHP {PHP_VERSION} with LSAPI"
echo "=============================================="
echo `date`
echo ""

ulimit -m unlimited
ulimit -v unlimited

# trying to detect src dir
if [ -d "/usr/home/cpeasyapache" ] ; then
	BASE_SRC=/usr/home/cpeasyapache
elif [ -d "/home/cpeasyapache" ] ; then
	BASE_SRC=/home/cpeasyapache
elif [ -d "/var/cpanel/cpeasyapache" ] ; then
	BASE_SRC=/var/cpanel/cpeasyapache
else
	check_errs 1 "Cannot find EasyApache PHP source directory, please try to run EasyApache first."
fi 

PHP_BUILD_DIR=${BASE_SRC}/ls.src
CP_BUILD_DIR=${BASE_SRC}/src

if [ ! -e "${PHP_BUILD_DIR}" ] ; then
	mkdir -p ${PHP_BUILD_DIR}
	check_errs $? "Could not create build directory ${PHP_BUILD_DIR}"
fi

echo "Changing to build directory ${PHP_BUILD_DIR}" 
cd ${PHP_BUILD_DIR}
check_errs $? "Could not get into build directory"

if [ -e php-{PHP_VERSION} ] ; then
	rm -rf php-{PHP_VERSION}
	check_errs $? "Could not delete old php directory"
fi

if [ -e "${CP_BUILD_DIR}/php-{PHP_VERSION}" ] ; then
	echo "Detected php build directory for cPanel ${CP_BUILD_DIR}/php-{PHP_VERSION}"
	echo "Same source code will be copied over"
	cp -rp "${CP_BUILD_DIR}/php-{PHP_VERSION}" php-{PHP_VERSION} 
	check_errs $? "Failed to copy over php source directory"
	
else
	check_errs 1 "Cannot find php build directory for cPanel, please run EasyApache first to build PHP with correct options for Apache."
fi

echo ""


DOWNLOAD_URL="http://update.litespeedtech.com/ws/latest.php"
LSAPI_VERSION=`wget -q --output-document=- $DOWNLOAD_URL`
LSAPI_VERSION=`expr "$LSAPI_VERSION" : '.*PHP-LSAPI=\([0-9\.]*\)'`
echo "Query lastest LSAPI version: $LSAPI_VERSION"

# to do: should use md5 check
if [ -e "php-litespeed-$LSAPI_VERSION.tgz" ] ; then
	rm -f "php-litespeed-$LSAPI_VERSION.tgz"
	check_errs $? "Could not delete old lsapi"
fi

DOWNLOAD_URL="http://www.litespeedtech.com/packages/lsapi/php-litespeed-$LSAPI_VERSION.tgz"
echo "Retrieving LSAPI archive"
wget -nv -O "php-litespeed-$LSAPI_VERSION.tgz" $DOWNLOAD_URL
check_errs $? "Could not retrieve LSAPI archive"

cd php-{PHP_VERSION}/sapi
check_errs $? "Could not get into php/sapi directory"

if [ -e litespeed/Makefile.frag ] ; then
	mv -f litespeed/Makefile.frag litespeed/Makefile.frag.package 
fi

echo "Extracting LSAPI archive: tar -xzf php-litespeed-$LSAPI_VERSION.tgz" 
tar -xzf "../../php-litespeed-$LSAPI_VERSION.tgz"
check_errs $? "Could not extract LSAPI archive"

if [ -e litespeed/Makefile.frag.package ] ; then
	mv -f litespeed/Makefile.frag.package litespeed/Makefile.frag 
fi

echo ""

echo "Finished gathering all the source code"
echo ""

echo "Generating configuration script"
cd ..
check_errs $? "Could not get into php directory"

sleep 1
touch ac*
check_errs $? "Could not touch ac*"

rm -rf autom4te.*

PHP_MAIN_VER=`expr "{PHP_VERSION}" : '\([0-9]*\.[0-9]*\)'`

PHP_MAIN_VER1=`expr "$PHP_MAIN_VER" : '\([0-9]*\)\.'`
PHP_MAIN_VER2=`expr "$PHP_MAIN_VER" : '[0-9]*\.\([0-9]*\)'`

BUILDCONF_FORCE=N
if [ "$PHP_MAIN_VER1" -lt "5" ] ; then
    BUILDCONF_FORCE=Y
elif [ "$PHP_MAIN_VER1" = "5" ] && [ "$PHP_MAIN_VER2" -lt "3" ] ; then
    BUILDCONF_FORCE=Y
fi

if [ "$BUILDCONF_FORCE" = "Y" ] ; then
	./buildconf --force
	check_errs $? "Could not generate configuration script for version prior to 5.3"
fi

rm config.cache

echo "Configuring PHP build (2-3 minutes)" 
echo "{PHP_CONF_OPTIONS}"

OS=`uname -s`

if [ "x$OS" = "xFreeBSD" ]; then
     CFLAGS='-O3' LDFLAGS='-L/usr/local/lib' {PHP_CONF_OPTIONS}
else
     CFLAGS='-O3' {PHP_CONF_OPTIONS}
fi

check_errs $? "Could not configure PHP build"

cp -fp "${CP_BUILD_DIR}/php-{PHP_VERSION}/libtool" . 
PLF=`uname -p`
if [ "x$PLF" = "xx86_64" ] ; then
	# work around for libtool problem for linux
	DLSCH=`grep 'sys_lib_dlsearch_path_spec="/lib /usr/lib ' libtool`
	if [ "x$DLSCH" != "x" ] ; then
		echo "  .. work around for libtool problem: sys_lib_dlsearch_path_spec should use lib64"
		cp libtool libtool.orig
		sed -e 's/sys_lib_dlsearch_path_spec=\"\/lib \/usr\/lib /sys_lib_dlsearch_path_spec=\"\/lib64 \/usr\/lib64 /' libtool.orig > libtool
	    if [ "$?" -ne "0" ] ; then
			echo "   sed command error, please try to modify libtool manually using lib64 for line: sys_lib_dlsearch_path_spec=\"/lib /usr/lib\" "
	    fi	
	fi
fi

find . -name '*.1' > /tmp/php-1.lst.$$
tar -cf /tmp/php-1.tar.$$ -T /tmp/php-1.lst.$$
make clean
tar -xf /tmp/php-1.tar.$$
rm -f /tmp/php-1.tar.$$ /tmp/php-1.lst.$$

echo "Compiling PHP (5-10 minutes)" 
echo `date`
make
check_errs $? "Could not compile PHP"

make install

PHP_INI=/usr/local/lib/php.ini

ext=`grep '^zend_extension=".*\/ioncube' $PHP_INI`
if [ $? -eq 0 ]; then
    cd ${CP_BUILD_DIR}/ioncube*
    if [ $? -eq 0 ]; then
		echo "Build IonCube ..."
		./cpanel-install
		cd ..
    fi
fi

ext=`grep '^extension="eaccelerator' $PHP_INI`
if [ $? -eq 0 ]; then
    cd ${CP_BUILD_DIR}/eaccelerator*
    if [ $? -eq 0 ]; then
		echo "Build eaccelerator ..."
		echo "  .. Special handling for eAccelerator: do not use spin lock, buggy"
		echo "     set mm_sem_spinlock=no and mm_sem_ipc=no in config.m4"
		
		found=`find . -name "config.m4"`

		for f in $found
		do
		    cp $f $f.orig
		    sed -e 's/mm_sem_spinlock=yes/mm_sem_spinlock=no/' -e 's/mm_sem_ipc=yes/mm_sem_ipc=no/' $f.orig > $f
		    if [ "$?" -ne "0" ] ; then
				echo "   sed command error, please try to modify $f manually to avoid using spinlock"
		    fi
		done
		
		./cpanel-install
		cd ..
    fi
fi

ext=`grep '^extension="suhosin' $PHP_INI`
if [ $? -eq 0 ]; then
    cd ${CP_BUILD_DIR}/suhosin*
    if [ $? -eq 0 ]; then
		echo "Build suhosin ..."
		./cpanel-install
		cd ..
    fi
fi

ext=`grep '^extension="ixed\.' $PHP_INI`
if [ $? -eq 0 ]; then
    cd ${CP_BUILD_DIR}/sourceguardian*
    if [ $? -eq 0 ]; then
		echo "Build sourceguardian ..."
		./cpanel-install
		cd ..
    fi
fi

ext=`grep '^extension=".*homelo