# Contributor: z3bra <willy at mailoo dot org>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=thttpd
pkgver=2.29
pkgrel=5
pkgdesc="Simple, small, portable, fast, and secure HTTP server"
url="http://www.acme.com/software/thttpd"
arch="all"
license="custom:BSD"
# No test/check available
options="!check"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-openrc"
source="http://www.acme.com/software/$pkgname/$pkgname-$pkgver.tar.gz
	thttpd.initd
	thttpd.confd
	thttpd.conf
	thttpd.logrotated
	thttpd-webgroup.patch
	forwarded-for.patch
	remove_transfer_encoding.patch
	thttpd-makeweb-notsuid.patch
	install-user.patch
	CVE-2012-5640.patch
	dont-expose-server-identity.patch
	config-cgi_path.patch
	allow-to-disable-debug-log.patch
	"
# secfixes:
#   2.29-r5:
#     - CVE-2012-5640

prepare() {
	default_prepare
	echo 'mkv       video/x-matroska' >> mime_types.txt
}

build() {
	CFLAGS="$CFLAGS -fpermissive" ./configure \
		--prefix=/usr \
		--mandir=/usr/share/man
	sed -e 's/^CFLAGS =/CFLAGS +=/' \
	    -e '/^STATICFLAG =/c STATICFLAG =' \
	    -i Makefile */Makefile
	make
}

package() {
	mkdir -p $pkgdir/usr/share/man/man1

	make \
		BINDIR="$pkgdir"/usr/sbin \
		WEBDIR="$pkgdir"/var/www/http \
		MANDIR="$pkgdir"/usr/share/man \
		WEBGROUP=www-data install

	rm -rf "$pkgdir"/var/www/http/*

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.conf \
		"$pkgdir"/etc/thttpd.conf
	install -m644 -D "$srcdir"/$pkgname.logrotated \
		"$pkgdir"/etc/logrotate.d/thttpd

	install -d "$pkgdir"/var/log/thttpd
	install -d "$pkgdir"/usr/share/licenses/"$pkgname"
	head -n 26 thttpd.c > "$pkgdir"/usr/share/licenses/"$pkgname"/LICENSE

	mkdir -p "$pkgdir/usr/share/doc/$pkgname"
	cat > $pkgdir/usr/share/doc/$pkgname/README.alpine <<-EOF
	To use makeweb, please set suid to makeweb binary with:
	-------------------------------------------------------
	chmod 2755 /usr/sbin/makeweb
	EOF
}

sha512sums="
e02ed5b889eb3c875d56503093777c542316165a8df2d83e539337fb0759b6d9728fd484123dd903af57b06c97fe339055b816cca64778b7369b94020bd61ab6  thttpd-2.29.tar.gz
d9c6b74f02b9b09106d355e40be605d2d8bae47a346cdb7cf22961f584f821041c26b1143832cd670650cd63982327414b731b8126b94bf8333673398ee5fd49  thttpd.initd
1e80d6702a17b6175ba16e44a2dc5086f2078c9cf18b598e2758b6b38ee40326bdea8d5b79f657afb3d7b92bc293375aa944757caa041cd8ea7a550873e3ebed  thttpd.confd
0e5fd090a83af1e7c452f257c3cd5d0870f8f5d33bbdddc9f98595c591b585eda29ebf1665cedeeaabdd987f5d4be53a3c10b12d3bf0287287dd3c44dafc7445  thttpd.conf
5b2800825583e93cf4be76e71d2840b9894c1779a810d562a0b6145cae0c7504dadfdc1e844f1611a48cca3b4518d41b47e41a68f33043d58ffde85f1e56e3f3  thttpd.logrotated
349721da9e670ca666891f98ca338ae0041c09b353fc42bdd87015803f0b668478be8e48f36d5b56b5e172d3a7b262bf4a71c9619607a068e41c2bc292bde2be  thttpd-webgroup.patch
02c079ca104f2358cd20756082657dca96f7a88cbeb611de81504f1581c5e085a7a2765ec55b6e0ae1948803afced85e8a45fc6deb2fef1ec5ba1ba96ce68b4b  forwarded-for.patch
6536ae6c25dbf79aec43e3d0596ad135ab3ab6e7cd3a5e3c895a289114c08c03c20357ffb4542decfc4d508039a5045db71fb36002c8ba94dbd6356cad32bae4  remove_transfer_encoding.patch
1138a827049f73b43ce142c914fad0670bcd4577de16485ade024314c616056ab6789897663d8b6592331354d44065eae7aa712e20f5c930a80513448416fa17  thttpd-makeweb-notsuid.patch
9b674b108961289d8869c31978a4c1822de54377d7a35907ae29d47ab2f5003d760f2970dec3bc11780f116d8f3c532f6726b76e0ebf1d0a89c85ce3eb0963ba  install-user.patch
fab46474c0e82df147de6c6d4366661fe2df18f3ca0a8bb874f27c14f522349505647c935461f4f9181c6fd6842e368be5d2894646709c337d72096ab5d67ef1  CVE-2012-5640.patch
06eb282426a6c5e71486a307da69dc1773cf6b81719d30e0217eec5d1aa3ca75a9e5821e7bd03d96416b2d549e67f627f99e47d93727cd604ec6a5c1dbe2c091  dont-expose-server-identity.patch
63c5765082c29b340c585f44e7bc92dba067f628f6b6763abe535805f13e37b18f63631127be12a108f4f1e27526f3c139dadfb30d837f497b0a5c09cecdd939  config-cgi_path.patch
a704b4dd559fe32ce5a7c9529212b1dd5601cbe2fbdf93f20b72e071000c6eba23fcb08cd4de1df3f3cde7ecb81490a2ab6ea4c1d739277b21957ce300aaf956  allow-to-disable-debug-log.patch
"
