Shell Script To Build And Install PHP Xcache Opcode Cache Extension

in Categories Software Build Scripts last updated May 19, 2012
#!/bin/bash
# A simple shell to build and install xcache Opcode Cache as module for 
# PHP under # CentOS, Fedora and RHEL / Redhat Enterprise Linux servers.
# ----------------------------------------------------------------------------
# Written by Vivek Gite <http://www.cyberciti.biz/>
# (c) 2008 nixCraft under GNU GPL v2.0+
# ----------------------------------------------------------------------------
# Home page: http://www.hardened-php.net
# Last updated: 15/June/2010
# ----------------------------------------------------------------------------
# Home page: http://xcache.lighttpd.net
VERSION="${2:-1.3.0}"
URL="http://xcache.lighttpd.net/pub/Releases/${VERSION}/xcache-${VERSION}.tar.gz"
vURL="http://xcache.lighttpd.net/pub/Releases/${VERSION}/xcache-${VERSION}.tar.gz.md5.txt"
FILE="${URL##*/}"
vFILE="${vURL##*/}"
DLHOME="/opt"
SOFTWARE="xcache"
DEST="${FILE%.tar.gz}"
 
[[ $(id -u) -ne 0 ]] && { echo "$0: You must be root user to run this script. Run it as 'sudo $0'"; exit 1; }
 
getsoftware(){
	wget $URL -O "${DLHOME}/$FILE"
        wget $vURL -O "${DLHOME}/$vFILE"
}
 
buildsoftware(){
        [[ ! -f "${DLHOME}/$FILE" ]] &&  getsoftware
        cd "${DLHOME}"
        tar -zxvf $FILE
        cd "$DEST"
	phpize --clean && ./configure --enable-xcache && make && read -p "Update in $SOFTWARE [Y/n] ? " answer
	shopt -s nocasematch
	[[ $answer =~ y|es  ]] &&  make install
	shopt -u nocasematch
}
 
verifyfile(){
        cd "${DLHOME}"
	[ ! -f ${DLHOME}/$vFILE ] && getsoftware
	md5sum -c $vFILE
	read -p "Contine to build [Y/n] ? " answer
	shopt -s nocasematch
	case "$answer" in
		y|yes) buildsoftware;;
		*) echo "";
	esac
	shopt -u nocasematch
}
 
case "$1" in
    download) 
	getsoftware 
        ;;
    build) 
	verifyfile
	;;
    verify)
	verifyfile
	;;	
    *) echo "Usage: $0 {download|verify|build|upgrade} version"
esac

Share this on:

1 comment

    Have a question? Post it on our forum!