# SliTaz package receipt.

PACKAGE="php-apache"
VERSION="5.2.17"
CATEGORY="development"
SHORT_DESC="PHP module for apache."
MAINTAINER="pascal.bellard@slitaz.org"
DEPENDS="php-common apache libxml2 zlib"
WEB_SITE="http://www.php.net/"
WANTED="php"
PROVIDE="php:apache"

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr/share
	cp -a $_pkg/usr/share/apache $fs/usr/share
}

# Post and pre install commans to stop
# and restart Web server if needed.
pre_install()
{
	if [ -z "$1" -a -f "/var/run/apache/httpd.pid" ]; then
		/etc/init.d/apache stop
	fi
}

post_install()
{
	grep -q php5_module $1/etc/apache/httpd.conf || {
	    sed -e 's|mod_rewrite.so|mod_rewrite.so\nLoadModule php5_module share/apache/modules/libphp5.so|' \
	    	-e 's|DirectoryIndex index.html|DirectoryIndex index.html index.php|' \
		-e 's|mime.types|mime.types\n    AddType application/x-httpd-php .php .php3 .php4 .php5\n    AddType application/x-httpd-php-source .phps|' \
	        -i $1/etc/apache/httpd.conf
	}
	[ -f $1/etc/apache/conf.d/phpinfo ] || \
		cat > $1/etc/apache/conf.d/phpinfo <<EOT
<IfModule mod_alias.c>
    Alias /phpinfo /usr/share/phpinfo
</IfModule>
<DirectoryMatch /usr/share/phpinfo/>
    DirectoryIndex index.php
    Options +FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</DirectoryMatch>
EOT
	# Restart Web server.
	if [ -z "$1" -a -f "/var/run/apache/httpd.pid" ]; then
		/etc/init.d/apache stop
		sleep 2
	fi
	if [ -z "$1" ]; then
		/etc/init.d/apache start
	fi
}