≡ Menu

Shell Script To Build And Install PHP Security Model Suhosin

#!/bin/bash
# A simple shell to build and install suhosin as module for PHP under
# CentOS, Fedora and RHEL / Redhat Enterprise Linux servers.
# ----------------------------------------------------------------------------
# Written by Vivek Gite 
# (c) 2009 nixCraft under GNU GPL v2.0+
# ----------------------------------------------------------------------------
# Home page: http://www.hardened-php.net
# Last updated: 15/June/2010
# ----------------------------------------------------------------------------
VERSION="-${2:-0.9.31}"
URL="http://download.suhosin.org/suhosin${VERSION}.tgz"
vURL="http://download.suhosin.org/suhosin${VERSION}.tgz.sig"
FILE="${URL##*/}"
vFILE="${vURL##*/}"
DLHOME="/opt"
SOFTWARE="suhosin"
DEST="${FILE%.tgz}"
[[ $(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 && phpize && ./configure && make && read -p "Update/Install $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 "Continue 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
	buildsoftware
	;;
    verify)
	#verifyfile
	buildsoftware
	;;
    *) echo "Usage: $0 {download|verify|build|upgrade} version"
esac
{ 2 comments… add one }
  • Jaysunn July 11, 2010, 2:22 pm

    This is really great use of functions and verifications. Love it.

    jaysunn

  • Vamsi June 23, 2010, 4:50 am

    Nice one :D
    I love the verification process ;)

Security: Are you a robot or human?

Leave a Comment