# Contributor: Kiyoshi Aman <adelie@aerdan.vulpine.house>
# Maintainer: Kiyoshi Aman <adelie@aerdan.vulpine.house>
pkgname=apache-httpd
_pkgreal=httpd
pkgver=2.4.43
pkgrel=0
pkgdesc="Open-source HTTP server"
url="https://httpd.apache.org"
arch="all"
license="Apache-2.0"
depends=""
install="$pkgname.pre-install $pkgname.pre-upgrade"
makedepends="apr-dev apr-util-dev autoconf automake libxml2-dev nghttp2-dev
	openssl-dev pcre-dev sed zlib-dev cmd:which"
pkgusers="apache"
pkggroups="apache"
subpackages="$pkgname-dev
             $pkgname-doc
	     $pkgname-http2
	     $pkgname-icons::noarch
	     $pkgname-ldap
	     $pkgname-openrc"
provides="apache2 apache2-ssl"
source="https://www-us.apache.org/dist//httpd/httpd-$pkgver.tar.gz
	adelie.layout
	apache-httpd.confd
	apache-httpd.initd
	apache-httpd.logrotate
	conf/httpd.conf
	conf/alias.conf
	conf/http2.conf
	conf/host.conf
	conf/proxy.conf
	conf/ssl.conf
	conf/userdir.conf"
builddir="$srcdir/$_pkgreal-$pkgver"
options="suid !check"

# secfixes: http_server
#   2.4.43-r0:
#     - CVE-2020-1934
#     - CVE-2020-1927
#   2.4.34-r0:
#     - CVE-2017-15710
#     - CVE-2017-15715
#     - CVE-2018-1283
#     - CVE-2018-1301
#     - CVE-2018-1302
#     - CVE-2018-1303
#     - CVE-2018-1312
#     - CVE-2018-1333
#     - CVE-2018-8011
#   2.4.41-r0:
#     - CVE-2019-9517
#     - CVE-2019-10081
#     - CVE-2019-10082
#     - CVE-2019-10092
#     - CVE-2019-10097
#     - CVE-2019-10098

prepare() {
	default_prepare
	cat "$srcdir"/adelie.layout >> "$builddir"/config.layout
	./buildconf \
		--with-apr=apr-1-config
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--enable-layout=Adelie \
		--enable-so \
		--with-mpm=event \
		--enable-mpms-shared="event prefork" \
		--enable-mods-shared=reallyall \
		--enable-ssl \
		--disable-lua \
		--enable-suexec \
		--with-suexec-caller=apache \
		--with-suexec-docroot=/srv/localhost \
		--with-suexec-logfile=/var/log/apache-httpd/suexec.log \
		--with-suexec-bin=/usr/sbin/suexec \
		--with-apr=/usr/bin/apr-1-config \
		--with-apr-util=/usr/bin/apu-1-config \
		--with-pcre=/usr
	make
}

package() {
	make DESTDIR="$pkgdir" -j1 install

	# apache-provided configuration is awful
	rm "$pkgdir"/etc/apache2/*.conf
	rm -r "$pkgdir"/etc/apache2/extra
	rm -r "$pkgdir"/etc/apache2/original
	install -Dm644 "$srcdir"/httpd.conf "$pkgdir"/etc/apache2/httpd.conf
	install -Dm644 "$srcdir"/alias.conf "$pkgdir"/etc/apache2/conf.d/alias.conf
	install -Dm644 "$srcdir"/http2.conf "$pkgdir"/etc/apache2/conf.d/http2.conf
	install -Dm644 "$srcdir"/host.conf "$pkgdir"/etc/apache2/sites.d/localhost.conf
	install -Dm644 "$srcdir"/proxy.conf "$pkgdir"/etc/apache2/conf.d/proxy.conf
	install -Dm644 "$srcdir"/ssl.conf   "$pkgdir"/etc/apache2/conf.d/ssl.conf
	install -Dm644 "$srcdir"/userdir.conf "$pkgdir"/etc/apache2/conf.d/userdir.conf

	# init & logrotate handling
	install -Dm755 "$srcdir"/apache-httpd.initd "$pkgdir"/etc/init.d/apache-httpd
	install -Dm644 "$srcdir"/apache-httpd.confd "$pkgdir"/etc/conf.d/apache-httpd
	install -Dm644 "$srcdir"/apache-httpd.logrotate "$pkgdir"/etc/logrotate.d/apache-httpd

	install -dm2750 -g wheel "$pkgdir"/var/log/apache2
}

dev() {
	default_dev
	depends="$depends perl apr-util-dev"
	install -d "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/apxs "$subpkgdir"/usr/bin
	install -d "$subpkgdir"/usr/share/apache2
	mv "$pkgdir"/usr/share/apache2/build "$subpkgdir"/usr/share/apache2
}

http2() {
	pkgdesc="Highly experimental protocol support for Apache HTTP server"
	local _file
	install -d "$subpkgdir"/etc/apache2/conf.d
	install -d "$subpkgdir"/usr/libexec/apache2

	for _file in etc/apache2/conf.d/http2.conf \
		usr/libexec/apache2/mod_proxy_http2.so \
		usr/libexec/apache2/mod_http2.so; do
		mv "$pkgdir"/$_file "$subpkgdir"/$_file
	done
}

icons() {
	pkgdesc="Public-domain icon pack for Apache HTTP server"
	install -d "$subpkgdir"/usr/share/apache2
	mv "$pkgdir"/usr/share/apache2/icons "$subpkgdir"/usr/share/apache2
}

ldap() {
	pkgdesc="LDAP authentication support for Apache HTTP server"
	install -d "$subpkgdir"/usr/libexec/apache2
	mv "$pkgdir"/usr/libexec/apache2/*_ldap.so \
		"$subpkgdir"/usr/libexec/apache2
}

sha512sums="d9879b8f8ef7d94dee1024e9c25b56d963a3b072520878a88a044629ad577c109a5456791b39016bf4f6672c04bf4a0e5cfd32381211e9acdc81d4a50b359e5e  httpd-2.4.43.tar.gz
c8bc2bb06ae51b0956e0ee673e80c444551c9b33dfcbb845106477c46d9e52786a8896022e1f00102264fecdf66e35e47fc6cf0abe9836fa536735cff4e6adf4  adelie.layout
336e81fa0d08f8fbe6243d52bd59b12cf2e925deb49b29d7a22953c5d40a951b6b753f51e5a396752cb0bbaf1cf25b1358902f375fb65639d00e62db7ae55ff2  apache-httpd.confd
5762d53f39ce7ecd730e05ddf6c063ede65cd75b9e7d67217784c80366646491ef9474306e8eb119c8fb5b4358407b07636a4e9cd82325d8df4e3e00dabc3459  apache-httpd.initd
18e8859c7d99c4483792a5fd20127873aad8fa396cafbdb6f2c4253451ffe7a1093a3859ce719375e0769739c93704c88897bd087c63e1ef585e26dcc1f5dd9b  apache-httpd.logrotate
927fd409221a6a632db6786f112e6e804f0e45adc2d4bc4754c84af9a2f8374b53816a9f493d9c870ecd6c5aeb365ee248d254aea1f7c2730efadd212a508d18  httpd.conf
83d57c57b809340bb07291c340ded5903ae55c0bba7c48e4eb0d27529ce4ecb6e235378ad770c69c8be2762b5346fa5bec94b6c585510719c37fe6addb33f998  alias.conf
7def0982bda42d5fe3a1812128be455fe0a47161f7fd0facd9ff85056f043a19f520bdb1c01b9f3fb25ddd66aa6224fb4b183f107bccd56719e0c7a88ad70bd9  http2.conf
9745ec511331b2ec399bf7895bc935f9c8526fd81d47cb17e42c1f5c010bbbea0b5ef2f2f4b12984dc8c77f410132010c3e73347a49ebe5feb0c1a763fe73a82  host.conf
905212b9107d71e4d64b338b1c1cf222f7a78979b928e7fa89b06620fbc010df00204a20aa22e69ed49682412d95ecc4e6abaafbb4cb043b31610d5b7a36ac00  proxy.conf
44f97ac0bab5122d409767af388046dfce5cad42ff18d79394f258546d3e578db334da4722cce4dc2ac03f9508a8b97587370cdede5e7678f02b9abc5dda88ee  ssl.conf
dd3c8fa9bc32a92c35df8728f6750fab8dd39be9e90e448a44a77efabc3e5516772607548856af520d4d5e8f2aff11f0b56d29db642e69ab72b1683e6aba5aed  userdir.conf"