#Maintainer: Thorsten Muehlfelder <thenktor(at)gmx.de>

pkgname=mongoose
pkgver=2.11
pkgrel=1tm
source=("http://mongoose.googlecode.com/files/mongoose-$pkgver.tgz" "rc.mongoose")
dotnew=('etc/mongoose.conf')
url="http://code.google.com/p/mongoose/"
docs=('COPYING')

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"$pkgname (small http server)"
"Easy to use web server for Windows and UNIX. Mongoose provides simple"
"and clean API for embedding it into existing programs. Targeting Web"
"application developers, embedded system developers, and people who"
"need to setup file sharing quickly."
)

build() {
	cd $startdir/src/${pkgname}
	# create basic license file
	echo "mongoose is licensed under the terms of the MIT license." > COPYING

	# make
	make linux || return 1
	make test || return 1

	# create dirs
	mkdir -p $startdir/pkg/etc/rc.d/
	mkdir -p $startdir/pkg/usr/sbin/
	mkdir -p $startdir/pkg/usr/
	mkdir -p $startdir/pkg/usr/man/man1/
	mkdir -p $startdir/pkg/var/www/htdocs/

	# install files
	install -m755 -o root -g root mongoose $startdir/pkg/usr/sbin/
	install -m644 -o root -g root mongoose.1 $startdir/pkg/usr/man/man1/

	# install rc script
	cd $startdir/src/
	install -m755 -o root -g root rc.mongoose $startdir/pkg/etc/rc.d/rc.mongoose.new

	# create a config file
	cat << "EOC" > $startdir/pkg/etc/mongoose.conf
# This is the mongoose http daemon configuration file.
# Try "man mongoose" for more information!

# Location of the WWW root directory. Default: working directory
# from which mongoose has been started.
root /var/www/htdocs

# Comma-separated list of ports to listen on. If the port is SSL, a
# letter 's' must be appeneded, for example, "80,443s" will open
# port 80 and port 443, and connections on port 443 will be SSL-ed.
# Default: 80
ports 80

# Switch to given user after startup. Default: not set.
uid nobody

# Authorization realm. Default: "mydomain.com".
auth_realm "Salix http server"

# Comma-separated list of CGI extensions.  All files having these
# extensions are treated as CGI scripts. Default: "cgi,pl,php"
cgi_ext cgi,pl,php

# Enable/disable directory listing. Default: "1" (enabled).
dir_list yes

# Access log file. Default: not set, no logging is done.
#access_log file

# Error log file. Default: not set, no errors are logged.
#error_log file

# Location of global passwords file. When set, per-directory
# .htpasswd files are ignored, and all accessed must be authorised
# against global passwords file.  Default: not set.
#auth_gpass /var/www/passwd

EOC
}

doinst() {
	if [ -r etc/rc.d/rc.mongoose -a -r etc/rc.d/rc.mongoose.new ]; then
		chmod --reference=etc/rc.d/rc.mongoose etc/rc.d/rc.mongoose.new
	fi
	mv etc/rc.d/rc.mongoose.new etc/rc.d/rc.mongoose
}