[Webapps-common-discuss] webapps-common/internal php,NONE,1.1

seanius@haydn.debian.org seanius@haydn.debian.org


Update of /cvsroot/webapps-common/webapps-common/internal
In directory haydn:/org/alioth.debian.org/chroot/home/users/seanius/tmp/cvs-serv996

Added Files:
	php 
Log Message:
php related functionality


--- NEW FILE: php ---
# php-related functions

wc_php_supported="php3 php4 php5"
wc_php_sapi_supported="apache apache2 cgi cli fcgi"

#
# wc_php_installed: test for installed phps
# usage:
#       wc_php_installed [ php3 php4 ... ]
#
# no arguments implies to test for all versions
wc_php_installed(){
	local phps
	if [ "$*" ]; then
		phps=$*
	else
		phps=$wc_php_supported
	fi
	for f in $phps; do
		if test -x /usr/bin/$f; then
			echo $f
		fi
	done
}

#
# wc_php_sapi_installed: test for installed php sapis
# usage:
#       wc_php_sapi_installed {php3|php4|...} [ sapi1 sapi2 ... ]
#
# no arguments implies to test for all sapis
wc_php_sapi_installed(){
	local sapis phpver
	if [ "$1" ]; then
		phpver="$1"
		shift
	else
		echo "i need a php version to check for a sapi..." >&2
	fi

	if [ "$*" ]; then
		sapis=$*
	else
		sapis=$wc_php_sapi_supported
	fi
	for f in $sapis; do
		if test -d /etc/$phpver/$f; then
			echo $f
		fi
	done
}

# wc_php_include:      include a file in the php sapi configuration
# usage:
#       wc_php_include file name [ php3 php4 ... ]
#
# no arguments implies all installed php versions
wc_php_include(){
	local p incfile phps confdir sapi
	if [ ! "$1" ]; then
		echo "i need at least a file!" 2>&1
		return 1
	fi
	incfile="$1"
	shift
	if [ ! "$1" ]; then
		echo "i also need a name!" 2>&1
		return 1
	fi
	name="$1"
	shift
	if [ ! -e "$incfile" ]; then
		echo "include file $incfile does not exist!" 2>&1
		return 1
	fi
	if [ "$*" ]; then
		phps=$*
	else
		phps=`wc_php_installed $wc_php_supported`
	fi
	for p in $phps; do
		for sapi in `wc_php_sapi_installed $p`; do
			confdir="/etc/$p/$sapi/conf.d"
			conflink="$confdir/${name}.conf"
			if [ -d "$confdir" ]; then
				ln -s "$incfile" "$conflink"
			else
				echo "$0: warning: $confdir does not exist, skipping..." >&2
			fi
		done
	done
}

# wc_php_uninclude:      uninclude a file in the php sapi configuration
# usage:
#       wc_php_uninclude file name [ php3 php4 ... ]
#
# no arguments implies all installed php versions
wc_php_uninclude(){
	local p incfile phps confdir sapi
	if [ ! "$1" ]; then
		echo "i need at least a file!" 2>&1
		return 1
	fi
	incfile="$1"
	shift
	if [ ! "$1" ]; then
		echo "i also need a name!" 2>&1
		return 1
	fi
	name="$1"
	shift
	if [ ! -e "$incfile" ]; then
		echo "include file $incfile does not exist!" 2>&1
		return 1
	fi
	if [ "$*" ]; then
		phps=$*
	else
		phps=`wc_php_installed $wc_php_supported`
	fi
	for p in $phps; do
		for sapi in `wc_php_sapi_installed $p`; do
			confdir="/etc/$p/$sapi/conf.d"
			conflink="$confdir/${name}.conf"
			if [ -L "$conflink" ]; then
				rm -f "$conflink"
			elif [ -e "$conflink" ]; then
				echo "warning: $conflink exists but is not a link" >&2
			fi
		done
	done
}