# SliTaz package receipt.

PACKAGE="lighttpd"
VERSION="1.4.30"
CATEGORY="network"
SHORT_DESC="Fast and light HTTP Web server."
MAINTAINER="pankso@slitaz.org"
DEPENDS="pcre"
BUILD_DEPENDS="pcre-dev bzip2-dev"
SUGGESTED="lighttpd-modules php perl python"
TARBALL="$PACKAGE-$VERSION.tar.gz"
WEB_SITE="http://www.lighttpd.net/"
WGET_URL="http://download.lighttpd.net/lighttpd/releases-1.4.x/$TARBALL"
CONFIG_FILES="/etc/lighttpd/vhosts.conf /etc/lighttpd/lighttpd.conf \
/var/www/index.html /var/www/style.css"
BASE_MODULES="
access
accesslog
alias
cgi
dirlisting
indexfile
staticfile
rewrite
status
userdir"

# Rules to configure and make the package.
compile_rules()
{
	cd $src
	if [ ! done.fastcgi_detach.patch ]; then
		patch -i $stuff/fastcgi_detach.patch || return 1
		touch done.fastcgi_detach.patch
	fi
	./configure \
		--enable-shared \
		--disable-ipv6 \
		--prefix=/usr \
    	--libdir=/usr/lib/lighttpd \
    	--mandir=/usr/share/man \
    	$CONFIGURE_ARGS &&
	make &&
	make DESTDIR=$PWD/_pkg install
}

# Rules to gen a SliTaz package suitable for Tazpkg.
# On SliTaz Lighttpd runs as user/group : www/www or 80/80.
genpkg_rules()
{
	mkdir -p $fs/usr
	#cp -a $_pkg/usr/bin $fs/usr
	cp -a $_pkg/usr/sbin $fs/usr

	# Modules.
	mkdir -p $fs/usr/lib/lighttpd
	for module in $BASE_MODULES
	do
		cp $_pkg/usr/lib/lighttpd/mod_${module}.so $fs/usr/lib/lighttpd
		echo -n "Copying : mod_${module}.so" && status
	done

	# Server root and config file.
	cp -a $stuff/var $fs
	cp -a $stuff/etc $fs
	chown -R 0.0 $fs/var/www
	chown -R 0.0 $fs/etc

	# Logs directory.
	mkdir -p $fs/var/log/lighttpd
	chown 80.80 $fs/var/log/lighttpd
}

# Pre and post install commands for Tazpkg.
# We stop the server by default in case of upgarde.
pre_install()
{
	echo "Processing pre-install commands..."
	[ -f /etc/init.d/$PACKAGE ] && /etc/init.d/$PACKAGE stop
	# Backup config file.
	if [ -d $1/etc/lighttpd ]; then
		cp -a $1/etc/lighttpd $1/etc/lighttpd.bak
	fi
}
post_install()
{
	echo "Processing post-install commands..."
	# Restore original config.
	if [ -d $1/etc/lighttpd.bak ]; then
		rm -rf $1/etc/lighttpd
		mv $1/etc/lighttpd.bak $1/etc/lighttpd
	fi
	# Just in case.
	chown www.www $1/var/log/$PACKAGE
	if [ -z "$1" ]; then
		for i in apache httpd; do
			[ -f /etc/init.d/$i ] && /etc/init.d/$i stop
		done
		/etc/init.d/$PACKAGE start
	fi
}