### this file is sourced not run
PKGVER=2.4.35
PKGBUILD=1
PKGARCH=x86_64

# source: post BLFS 8.3 2018-10-14
TARBALL=httpd-$PKGVER.tar.bz2
MD5SUM=30c1cde80ffe814a8d16b4fdffda330a
SRC_URL=http://archive.apache.org/dist/httpd/$TARBALL
BUNDLE=

SLACKREQ='libapr-util libpcre'
SLACKDESC="apache-httpd: apache-httpd $PKGVER (Apache Web Server)  
apache-httpd:  
apache-httpd: The Apache HTTPD package contains an open-source HTTP server. It 
apache-httpd: is useful for creating local intranet web sites or running huge 
apache-httpd: web serving operations.  
apache-httpd: 
apache-httpd: 
apache-httpd: 
apache-httpd: 
apache-httpd: 
apache-httpd:
"
SLACKINSTALL='
! grep -q webuser ./etc/passwd && echo "webuser:x:504:504:Webserver User,,,:/root/Web-Server:/bin/sh" >> ./etc/passwd
! grep -q webgroup ./etc/group  && echo "webgroup:x:504:" >> ./etc/group
'

### default pkg_download
### default pkg_prepare
### default pkg_package
### build
pkg_build() {
	cd /tmp/httpd* &&

	# create users - must be the same as the ones specified in SLACKINSTALL
	{	echo "cd /"
		echo "$SLACKINSTALL"
	} > /tmp/create-user &&
	sh /tmp/create-user
	
	# the patch needs to be patched
	sed -i -e "s|/lib|/$LIBDIR|" /tmp/pkg/httpd-$PKGVER-blfs_layout-1.patch &&
	patch -Np1 -i /tmp/pkg/httpd-$PKGVER-blfs_layout-1.patch &&
	
	# BLFS: Forces the apxs utility to use absolute pathnames for modules, when instructed to do so. 
	sed '/dir.*CFG_PREFIX/s@^@#@' -i support/apxs.in &&
	./configure \
		--enable-rewrite                                \
		--enable-authnz-fcgi                            \
		--enable-layout=BLFS                            \
		--enable-mods-shared="all cgi"                  \
		--enable-mpms-shared=all                        \
		--enable-suexec=shared                          \
		--with-apr=/usr/bin/apr-1-config                \
		--with-apr-util=/usr/bin/apu-1-config           \
		--with-suexec-bin=/usr/$LIBDIR/httpd/suexec     \
		--with-suexec-caller=webuser                    \
		--with-suexec-docroot=/srv/www                  \
		--with-suexec-logfile=/var/log/httpd/suexec.log \
		--with-suexec-uidmin=100                        \
		--with-suexec-userdir=public_html               &&
	make $MAKEFLAGS && 

	# BLFS install
	make install &&
	mv -v /usr/sbin/suexec /usr/$LIBDIR/httpd/suexec &&
	chgrp webgroup         /usr/$LIBDIR/httpd/suexec &&
	chmod 4754             /usr/$LIBDIR/httpd/suexec &&
	chown -v -R webuser:webgroup /srv/www &&

	# Fatdog configuration and startup script
	install -m644 /tmp/pkg/99-httpd /etc/init.d &&
	sed -i -e 's|^User .*|User webuser|' \
		-e 's|^Group .*|Group webgroup|' /etc/httpd/httpd.conf &&
		
	pkg_build_slackdesc &&
	rm -f /etc/passwd /etc/group &&
	
	# multilib
	mv -v /usr/bin/apxs{,-64} &&
	ln -sfv /usr/bin/multiarch_wrapper /usr/bin/apxs
}
