# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=lighttpd
pkgver=1.4.79
pkgrel=0
pkgdesc="Secure, fast, compliant and very flexible web-server"
url="https://www.lighttpd.net"
arch="all"
license="BSD-3-Clause"
install="$pkgname.pre-install $pkgname.pre-upgrade"
pkgusers="lighttpd"
pkggroups="lighttpd"
makedepends="
	brotli-dev
	libdbi-dev
	libxml2-dev
	lua5.4-dev
	meson
	openldap-dev
	openssl-dev
	pcre2-dev
	sqlite-dev
	zlib-dev
	zstd-dev
	"
checkdepends="perl"
subpackages="
	$pkgname-dbg
	$pkgname-doc
	$pkgname-openrc
	$pkgname-mod_auth
	$pkgname-mod_webdav
	"
source="https://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-$pkgver.tar.xz
	$pkgname.initd
	$pkgname.confd
	$pkgname.logrotate
	lighttpd.conf
	mod_cgi.conf
	mod_fastcgi.conf
	mod_fastcgi_fpm.conf
	"

# secfixes:
#   1.4.67-r0:
#     - CVE-2022-41556
#   1.4.64-r0:
#     - CVE-2022-22707

build() {
	abuild-meson \
		-Db_lto=true \
		-Dwith_brotli=enabled \
		-Dwith_dbi=enabled \
		-Dwith_ldap=enabled \
		-Dwith_lua=true \
		-Dwith_openssl=true \
		-Dwith_pcre2=true \
		-Dwith_webdav_locks=enabled \
		-Dwith_webdav_props=enabled \
		-Dwith_zstd=enabled \
		. output
	meson compile -C output
}

check() {
	meson test --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output

	# create dirs
	install -d -m2750 -o lighttpd -g wheel \
		"$pkgdir"/var/log/lighttpd/
	install -d -m755 \
		"$pkgdir"/var/www/localhost/htdocs

	# lighttpd
	install -D -m755 "$srcdir"/lighttpd.initd \
		"$pkgdir"/etc/init.d/lighttpd
	install -D -m644 "$srcdir"/lighttpd.confd \
		"$pkgdir"/etc/conf.d/lighttpd
	install -D -m644 "$srcdir"/lighttpd.logrotate \
		"$pkgdir"/etc/logrotate.d/lighttpd

	# config files
	install -Dm644 -t "$pkgdir"/etc/lighttpd/ "$srcdir"/*.conf
}

mod_auth() {
	pkgdesc="Authentication module for lighttpd"
	amove usr/lib/lighttpd/mod_auth.so
}

mod_webdav() {
	pkgdesc="WebDAV module for lighttpd"
	amove usr/lib/lighttpd/mod_webdav.so
}

sha512sums="
e0f1bb2cfca5e81001ea30d13f088425dfc7acbec924ecddf438eb6326ab3158a61c6c4aaee0b68a90666d1cb987ce94b1f6a48afd92485cc995db5b58265f83  lighttpd-1.4.79.tar.xz
a74fb8394fb77fca2a08bdcfc79d4e13de6aca7bc4ed842b7e05f7f3a9cc85dccaa4971ba8fd0edfaa19da8d3870a743b713d9e51f1cbfe5b8e2843bb7fe5346  lighttpd.initd
9d2ab5deb7353ebf290e90936b511941df440859c78589d0bcf130ef69a5e9c79e4d318548b6b118df002083c46f7476230a28954b7a10a9dbd05040e02b1291  lighttpd.confd
0536b4f21d2e8659f7831b45998c13d9f6051ae7ecde13be01f372f837d255bfc4e211de48a7686cc743d53aa9c08ab3f10ec19788896dcf8356b90053ca7a16  lighttpd.logrotate
6c0fdf04dbc57ed657b15254db8b6fc7c1a7f3e6cec9ddcac52d7af200b28670a7bcf186643e478579846b66cac59591cb6313632cb2ddf7db1ea59c2d8c7065  lighttpd.conf
27cc638d8068dcf47bd9db44943d1db6c6f4e8e6abd6b42af7cea004b1c093440068541d98c68f8bea70b956713adaf8ed59a4b642dea826ee8620a05f8cfde5  mod_cgi.conf
1d15b84c03fb648a0e67ab5c5411b85478b4454c44bc2959cc96d1700eeadd7ff429520a5f1550db6527267646622dccd3d47d3fd1258869fccaf5c22d4ad4b2  mod_fastcgi.conf
f9efc4b70d825600f5356c30e57d0b6cac11c01739337f7192c09c2cfd96cb76c8328b11d818ea4c2addc1a6d253975b84700106ae75854d55d0df73e220bd2b  mod_fastcgi_fpm.conf
"
