nvidia-driver.eclass: Use next gen version of readme.gentoo eclass
[gentoo.git] / eclass / apache-2.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: apache-2.eclass
6 # @MAINTAINER:
7 # polynomial-c@gentoo.org
8 # @BLURB: Provides a common set of functions for apache-2.x ebuilds
9 # @DESCRIPTION:
10 # This eclass handles apache-2.x ebuild functions such as LoadModule generation
11 # and inter-module dependency checking.
12
13 inherit autotools eutils flag-o-matic multilib ssl-cert user toolchain-funcs versionator
14
15 [[ ${CATEGORY}/${PN} != www-servers/apache ]] \
16         && die "Do not use this eclass with anything else than www-servers/apache ebuilds!"
17
18 case ${EAPI:-0} in
19         0|1|2|3|4)
20                 die "This eclass requires >=EAPI-5"
21         ;;
22 esac
23
24 # settings which are version specific go in here:
25 case $(get_version_component_range 1-2) in
26         2.4)
27                 DEFAULT_MPM_THREADED="event" #509922
28                 RDEPEND=">=dev-libs/apr-1.5.1
29                         !www-apache/mod_macro" #492578 #477702
30         ;;
31         *)
32                 DEFAULT_MPM_THREADED="worker"
33                 RDEPEND=">=dev-libs/apr-1.4.5" #368651
34         ;;
35 esac
36
37 # ==============================================================================
38 # INTERNAL VARIABLES
39 # ==============================================================================
40
41 # @ECLASS-VARIABLE: GENTOO_PATCHNAME
42 # @DESCRIPTION:
43 # This internal variable contains the prefix for the patch tarball.
44 # Defaults to the full name and version (including revision) of the package.
45 # If you want to override this in an ebuild, use:
46 # ORIG_PR="(revision of Gentoo stuff you want)"
47 # GENTOO_PATCHNAME="gentoo-${PN}-${PV}${ORIG_PR:+-${ORIG_PR}}"
48 [[ -n "$GENTOO_PATCHNAME" ]] || GENTOO_PATCHNAME="gentoo-${PF}"
49
50 # @ECLASS-VARIABLE: GENTOO_PATCHDIR
51 # @DESCRIPTION:
52 # This internal variable contains the working directory where patches and config
53 # files are located.
54 # Defaults to the patchset name appended to the working directory.
55 [[ -n "$GENTOO_PATCHDIR" ]] || GENTOO_PATCHDIR="${WORKDIR}/${GENTOO_PATCHNAME}"
56
57 # @VARIABLE: GENTOO_DEVELOPER
58 # @DESCRIPTION:
59 # This variable needs to be set in the ebuild and contains the name of the
60 # gentoo developer who created the patch tarball
61
62 # @VARIABLE: GENTOO_PATCHSTAMP
63 # @DESCRIPTION:
64 # This variable needs to be set in the ebuild and contains the date the patch
65 # tarball was created at in YYYYMMDD format
66
67 # @VARIABLE: GENTOO_PATCH_A
68 # @DESCRIPTION:
69 # This variable should contain the entire filename of patch tarball.
70 # Defaults to the name of the patchset, with a datestamp.
71 [[ -n "$GENTOO_PATCH_A" ]] || GENTOO_PATCH_A="${GENTOO_PATCHNAME}-${GENTOO_PATCHSTAMP}.tar.bz2"
72
73 SRC_URI="mirror://apache/httpd/httpd-${PV}.tar.bz2
74         https://dev.gentoo.org/~${GENTOO_DEVELOPER}/dist/apache/${GENTOO_PATCH_A}"
75
76 # @VARIABLE: IUSE_MPMS_FORK
77 # @DESCRIPTION:
78 # This variable needs to be set in the ebuild and contains a list of forking
79 # (i.e.  non-threaded) MPMs
80
81 # @VARIABLE: IUSE_MPMS_THREAD
82 # @DESCRIPTION:
83 # This variable needs to be set in the ebuild and contains a list of threaded
84 # MPMs
85
86 # @VARIABLE: IUSE_MODULES
87 # @DESCRIPTION:
88 # This variable needs to be set in the ebuild and contains a list of available
89 # built-in modules
90
91 IUSE_MPMS="${IUSE_MPMS_FORK} ${IUSE_MPMS_THREAD}"
92 IUSE="${IUSE} debug doc ldap libressl selinux ssl static suexec threads"
93
94 for module in ${IUSE_MODULES} ; do
95         IUSE="${IUSE} apache2_modules_${module}"
96 done
97
98 for mpm in ${IUSE_MPMS} ; do
99         IUSE="${IUSE} apache2_mpms_${mpm}"
100 done
101
102 DEPEND="dev-lang/perl
103         =dev-libs/apr-1*
104         =dev-libs/apr-util-1*[ldap?]
105         dev-libs/libpcre
106         apache2_modules_deflate? ( sys-libs/zlib )
107         apache2_modules_mime? ( app-misc/mime-types )
108         ldap? ( =net-nds/openldap-2* )
109         ssl? (
110                 !libressl? ( >=dev-libs/openssl-1.0.2:0= )
111                 libressl? ( dev-libs/libressl:= )
112         )
113         !=www-servers/apache-1*"
114 RDEPEND+=" ${DEPEND}
115         selinux? ( sec-policy/selinux-apache )"
116 PDEPEND="~app-admin/apache-tools-${PV}"
117
118 S="${WORKDIR}/httpd-${PV}"
119
120 # ==============================================================================
121 # INTERNAL FUNCTIONS
122 # ==============================================================================
123
124 # @ECLASS-VARIABLE: MY_MPM
125 # @DESCRIPTION:
126 # This internal variable contains the selected MPM after a call to setup_mpm()
127
128 # @FUNCTION: setup_mpm
129 # @DESCRIPTION:
130 # This internal function makes sure that only one of APACHE2_MPMS was selected
131 # or a default based on USE=threads is selected if APACHE2_MPMS is empty
132 setup_mpm() {
133         MY_MPM=""
134         for x in ${IUSE_MPMS} ; do
135                 if use apache2_mpms_${x} ; then
136                         if [[ -z "${MY_MPM}" ]] ; then
137                                 MY_MPM=${x}
138                                 elog
139                                 elog "Selected MPM: ${MY_MPM}"
140                                 elog
141                         else
142                                 eerror "You have selected more then one mpm USE-flag."
143                                 eerror "Only one MPM is supported."
144                                 die "more then one mpm was specified"
145                         fi
146                 fi
147         done
148
149         if [[ -z "${MY_MPM}" ]] ; then
150                 if use threads ; then
151                         MY_MPM=${DEFAULT_MPM_THREADED}
152                         elog
153                         elog "Selected default threaded MPM: ${MY_MPM}"
154                         elog
155                 else
156                         MY_MPM=prefork
157                         elog
158                         elog "Selected default MPM: ${MY_MPM}"
159                         elog
160                 fi
161         fi
162
163         if has ${MY_MPM} ${IUSE_MPMS_THREAD} && ! use threads ; then
164                 eerror "You have selected a threaded MPM but USE=threads is disabled"
165                 die "invalid use flag combination"
166         fi
167
168         if has ${MY_MPM} ${IUSE_MPMS_FORK} && use threads ; then
169                 eerror "You have selected a non-threaded MPM but USE=threads is enabled"
170                 die "invalid use flag combination"
171         fi
172 }
173
174 # @VARIABLE: MODULE_CRITICAL
175 # @DESCRIPTION:
176 # This variable needs to be set in the ebuild and contains a space-separated
177 # list of modules critical for the default apache. A user may still
178 # disable these modules for custom minimal installation at their own risk.
179
180 # @FUNCTION: check_module_critical
181 # @DESCRIPTION:
182 # This internal function warns the user about modules critical for the default
183 # apache configuration.
184 check_module_critical() {
185         local unsupported=0
186
187         for m in ${MODULE_CRITICAL} ; do
188                 if ! has ${m} ${MY_MODS[@]} ; then
189                         ewarn "Module '${m}' is required in the default apache configuration."
190                         unsupported=1
191                 fi
192         done
193
194         if [[ ${unsupported} -ne 0 ]] ; then
195                 ewarn
196                 ewarn "You have disabled one or more required modules"
197                 ewarn "for the default apache configuration."
198                 ewarn "Although this is not an error, please be"
199                 ewarn "aware that this setup is UNSUPPORTED."
200                 ewarn
201         fi
202 }
203
204 # @VARIABLE: MODULE_DEPENDS
205 # @DESCRIPTION:
206 # This variable needs to be set in the ebuild and contains a space-separated
207 # list of dependency tokens each with a module and the module it depends on
208 # separated by a colon
209
210 # @FUNCTION: check_module_depends
211 # @DESCRIPTION:
212 # This internal function makes sure that all inter-module dependencies are
213 # satisfied with the current module selection
214 check_module_depends() {
215         local err=0
216
217         for m in ${MY_MODS[@]} ; do
218                 for dep in ${MODULE_DEPENDS} ; do
219                         if [[ "${m}" == "${dep%:*}" ]] ; then
220                                 if ! use apache2_modules_${dep#*:} ; then
221                                         eerror "Module '${m}' depends on '${dep#*:}'"
222                                         err=1
223                                 fi
224                         fi
225                 done
226         done
227
228         if [[ ${err} -ne 0 ]] ; then
229                 die "invalid use flag combination"
230         fi
231 }
232
233 # @ECLASS-VARIABLE: MY_CONF
234 # @DESCRIPTION:
235 # This internal variable contains the econf options for the current module
236 # selection after a call to setup_modules()
237
238 # @ECLASS-VARIABLE: MY_MODS
239 # @DESCRIPTION:
240 # This internal variable contains a sorted, space separated list of currently
241 # selected modules after a call to setup_modules()
242
243 # @FUNCTION: setup_modules
244 # @DESCRIPTION:
245 # This internal function selects all built-in modules based on USE flags and
246 # APACHE2_MODULES USE_EXPAND flags
247 setup_modules() {
248         local mod_type=
249
250         if use static ; then
251                 mod_type="static"
252         else
253                 mod_type="shared"
254         fi
255
256         MY_CONF=( --enable-so=static )
257         MY_MODS=()
258
259         if use ldap ; then
260                 MY_CONF+=( --enable-authnz_ldap=${mod_type} --enable-ldap=${mod_type} )
261                 MY_MODS+=( ldap authnz_ldap )
262         else
263                 MY_CONF+=( --disable-authnz_ldap --disable-ldap )
264         fi
265
266         if use ssl ; then
267                 MY_CONF+=( --with-ssl="${EPREFIX}"/usr --enable-ssl=${mod_type} )
268                 MY_MODS+=( ssl )
269         else
270                 MY_CONF+=( --without-ssl --disable-ssl )
271         fi
272
273         if use suexec ; then
274                 elog "You can manipulate several configure options of suexec"
275                 elog "through the following environment variables:"
276                 elog
277                 elog " SUEXEC_SAFEPATH: Default PATH for suexec (default: '${EPREFIX}/usr/local/bin:${EPREFIX}/usr/bin:${EPREFIX}/bin')"
278                 elog "  SUEXEC_LOGFILE: Path to the suexec logfile (default: '${EPREFIX}/var/log/apache2/suexec_log')"
279                 elog "   SUEXEC_CALLER: Name of the user Apache is running as (default: apache)"
280                 elog "  SUEXEC_DOCROOT: Directory in which suexec will run scripts (default: '${EPREFIX}/var/www')"
281                 elog "   SUEXEC_MINUID: Minimum UID, which is allowed to run scripts via suexec (default: 1000)"
282                 elog "   SUEXEC_MINGID: Minimum GID, which is allowed to run scripts via suexec (default: 100)"
283                 elog "  SUEXEC_USERDIR: User subdirectories (like /home/user/html) (default: public_html)"
284                 elog "    SUEXEC_UMASK: Umask for the suexec process (default: 077)"
285                 elog
286
287                 MY_CONF+=( --with-suexec-safepath="${SUEXEC_SAFEPATH:-${EPREFIX}/usr/local/bin:${EPREFIX}/usr/bin:${EPREFIX}/bin}" )
288                 MY_CONF+=( --with-suexec-logfile="${SUEXEC_LOGFILE:-${EPREFIX}/var/log/apache2/suexec_log}" )
289                 MY_CONF+=( --with-suexec-bin="${EPREFIX}/usr/sbin/suexec" )
290                 MY_CONF+=( --with-suexec-userdir=${SUEXEC_USERDIR:-public_html} )
291                 MY_CONF+=( --with-suexec-caller=${SUEXEC_CALLER:-apache} )
292                 MY_CONF+=( --with-suexec-docroot="${SUEXEC_DOCROOT:-${EPREFIX}/var/www}" )
293                 MY_CONF+=( --with-suexec-uidmin=${SUEXEC_MINUID:-1000} )
294                 MY_CONF+=( --with-suexec-gidmin=${SUEXEC_MINGID:-100} )
295                 MY_CONF+=( --with-suexec-umask=${SUEXEC_UMASK:-077} )
296                 MY_CONF+=( --enable-suexec=${mod_type} )
297                 MY_MODS+=( suexec )
298         else
299                 MY_CONF+=( --disable-suexec )
300         fi
301
302         for x in ${IUSE_MODULES} ; do
303                 if use apache2_modules_${x} ; then
304                         MY_CONF+=( --enable-${x}=${mod_type} )
305                         MY_MODS+=( ${x} )
306                 else
307                         MY_CONF+=( --disable-${x} )
308                 fi
309         done
310
311         # sort and uniquify MY_MODS
312         MY_MODS=( $(echo ${MY_MODS[@]} | tr ' ' '\n' | sort -u) )
313         check_module_depends
314         check_module_critical
315 }
316
317 # @VARIABLE: MODULE_DEFINES
318 # @DESCRIPTION:
319 # This variable needs to be set in the ebuild and contains a space-separated
320 # list of tokens each mapping a module to a runtime define which can be
321 # specified in APACHE2_OPTS in /etc/conf.d/apache2 to enable this particular
322 # module.
323
324 # @FUNCTION: generate_load_module
325 # @DESCRIPTION:
326 # This internal function generates the LoadModule lines for httpd.conf based on
327 # the current module selection and MODULE_DEFINES
328 generate_load_module() {
329         local endit=0 mod_lines= mod_dir="${ED}/usr/$(get_libdir)/apache2/modules"
330
331         if use static; then
332                 sed -i -e "/%%LOAD_MODULE%%/d" \
333                         "${GENTOO_PATCHDIR}"/conf/httpd.conf
334                 return
335         fi
336
337         for m in ${MY_MODS[@]} ; do
338                 if [[ -e "${mod_dir}/mod_${m}.so" ]] ; then
339                         for def in ${MODULE_DEFINES} ; do
340                                 if [[ "${m}" == "${def%:*}" ]] ; then
341                                         mod_lines="${mod_lines}\n<IfDefine ${def#*:}>"
342                                         endit=1
343                                 fi
344                         done
345
346                         mod_lines="${mod_lines}\nLoadModule ${m}_module modules/mod_${m}.so"
347
348                         if [[ ${endit} -ne 0 ]] ; then
349                                 mod_lines="${mod_lines}\n</IfDefine>"
350                                 endit=0
351                         fi
352                 fi
353         done
354
355         sed -i -e "s:%%LOAD_MODULE%%:${mod_lines}:" \
356                 "${GENTOO_PATCHDIR}"/conf/httpd.conf
357 }
358
359 # @FUNCTION: check_upgrade
360 # @DESCRIPTION:
361 # This internal function checks if the previous configuration file for built-in
362 # modules exists in ROOT and prevents upgrade in this case. Users are supposed
363 # to convert this file to the new APACHE2_MODULES USE_EXPAND variable and remove
364 # it afterwards.
365 check_upgrade() {
366         if [[ -e "${EROOT}"etc/apache2/apache2-builtin-mods ]]; then
367                 eerror "The previous configuration file for built-in modules"
368                 eerror "(${EROOT}etc/apache2/apache2-builtin-mods) exists on your"
369                 eerror "system."
370                 eerror
371                 eerror "Please read https://wiki.gentoo.org/wiki/Project:Apache/Upgrading"
372                 eerror "for detailed information how to convert this file to the new"
373                 eerror "APACHE2_MODULES USE_EXPAND variable."
374                 eerror
375                 die "upgrade not possible with existing ${ROOT}etc/apache2/apache2-builtin-mods"
376         fi
377 }
378
379 # ==============================================================================
380 # EXPORTED FUNCTIONS
381 # ==============================================================================
382
383 # @FUNCTION: apache-2_pkg_setup
384 # @DESCRIPTION:
385 # This function selects built-in modules, the MPM and other configure options,
386 # creates the apache user and group and informs about CONFIG_SYSVIPC being
387 # needed (we don't depend on kernel sources and therefore cannot check).
388 apache-2_pkg_setup() {
389         check_upgrade
390
391         # setup apache user and group
392         enewgroup apache 81
393         enewuser apache 81 -1 /var/www apache
394
395         setup_mpm
396         setup_modules
397
398         if use debug; then
399                 MY_CONF+=( --enable-maintainer-mode --enable-exception-hook )
400         fi
401
402         elog "Please note that you need SysV IPC support in your kernel."
403         elog "Make sure CONFIG_SYSVIPC=y is set."
404         elog
405
406         if use userland_BSD; then
407                 elog "On BSD systems you need to add the following line to /boot/loader.conf:"
408                 elog "  accf_http_load=\"YES\""
409                 elog
410         fi
411 }
412
413 # @FUNCTION: apache-2_src_prepare
414 # @DESCRIPTION:
415 # This function applies patches, configures a custom file-system layout and
416 # rebuilds the configure scripts.
417 apache-2_src_prepare() {
418         #fix prefix in conf files etc (bug #433736)
419         use !prefix || sed -e "s@/\(usr\|var\|etc\|run\)/@${EPREFIX}&@g" \
420                 -i "${GENTOO_PATCHDIR}"/conf/httpd.conf "${GENTOO_PATCHDIR}"/scripts/* \
421                 "${GENTOO_PATCHDIR}"/docs/*.example "${GENTOO_PATCHDIR}"/patches/*.layout \
422                 "${GENTOO_PATCHDIR}"/init/* "${GENTOO_PATCHDIR}"/conf/vhosts.d/* \
423                 "${GENTOO_PATCHDIR}"/conf/modules.d/* || die
424
425         # 03_all_gentoo-apache-tools.patch injects -Wl,-z,now, which is not a good
426         # idea for everyone
427         case ${CHOST} in
428                 *-linux-gnu|*-solaris*|*-freebsd*)
429                         # do nothing, these use GNU binutils
430                         :
431                 ;;
432                 *-darwin*)
433                         sed -i -e 's/-Wl,-z,now/-Wl,-bind_at_load/g' \
434                                 "${GENTOO_PATCHDIR}"/patches/03_all_gentoo_apache-tools.patch
435                 ;;
436                 *)
437                         # patch it out to be like upstream
438                         sed -i -e 's/-Wl,-z,now//g' \
439                                 "${GENTOO_PATCHDIR}"/patches/03_all_gentoo_apache-tools.patch
440                 ;;
441         esac
442
443         # Use correct multilib libdir in gentoo patches
444         sed -i -e "s:/usr/lib:/usr/$(get_libdir):g" \
445                 "${GENTOO_PATCHDIR}"/{conf/httpd.conf,init/*,patches/config.layout} \
446                 || die "libdir sed failed"
447
448         epatch "${GENTOO_PATCHDIR}"/patches/*.patch
449
450         # setup the filesystem layout config
451         cat "${GENTOO_PATCHDIR}"/patches/config.layout >> "${S}"/config.layout || \
452                 die "Failed preparing config.layout!"
453         sed -i -e "s:version:${PF}:g" "${S}"/config.layout
454
455         # apache2.8 instead of httpd.8 (bug #194828)
456         mv docs/man/{httpd,apache2}.8
457         sed -i -e 's/httpd\.8/apache2.8/g' Makefile.in
458
459         # patched-in MPMs need the build environment rebuilt
460         sed -i -e '/sinclude/d' configure.in
461         AT_M4DIR=build eautoreconf
462
463         # ${T} must be not group-writable, else grsec TPE will block it
464         chmod g-w "${T}"
465
466         # This package really should upgrade to using pcre's .pc file.
467         cat <<-\EOF >"${T}"/pcre-config
468         #!/bin/sh
469         [ "${flag}" = "--version" ] && set -- --modversion
470         exec ${PKG_CONFIG} libpcre "$@"
471         EOF
472         chmod a+x "${T}"/pcre-config
473 }
474
475 # @FUNCTION: apache-2_src_configure
476 # @DESCRIPTION:
477 # This function adds compiler flags and runs econf and emake based on MY_MPM and
478 # MY_CONF
479 apache-2_src_configure() {
480         tc-export PKG_CONFIG
481
482         # Sanity check in case people have bad mounts/TPE settings. #500928
483         if ! "${T}"/pcre-config --help >/dev/null ; then
484                 eerror "Could not execute ${T}/pcre-config; do you have bad mount"
485                 eerror "permissions in ${T} or have TPE turned on in your kernel?"
486                 die "check your runtime settings #500928"
487         fi
488
489         # Instead of filtering --as-needed (bug #128505), append --no-as-needed
490         # Thanks to Harald van Dijk
491         append-ldflags $(no-as-needed)
492
493         # peruser MPM debugging with -X is nearly impossible
494         if has peruser ${IUSE_MPMS} && use apache2_mpms_peruser ; then
495                 use debug && append-flags -DMPM_PERUSER_DEBUG
496         fi
497
498         # econf overwrites the stuff from config.layout, so we have to put them into
499         # our myconf line too
500         ac_cv_path_PKGCONFIG=${PKG_CONFIG} \
501         econf \
502                 --includedir="${EPREFIX}"/usr/include/apache2 \
503                 --libexecdir="${EPREFIX}"/usr/$(get_libdir)/apache2/modules \
504                 --datadir="${EPREFIX}"/var/www/localhost \
505                 --sysconfdir="${EPREFIX}"/etc/apache2 \
506                 --localstatedir="${EPREFIX}"/var \
507                 --with-mpm=${MY_MPM} \
508                 --with-apr="${SYSROOT}${EPREFIX}"/usr \
509                 --with-apr-util="${SYSROOT}${EPREFIX}"/usr \
510                 --with-pcre="${T}"/pcre-config \
511                 --with-z="${EPREFIX}"/usr \
512                 --with-port=80 \
513                 --with-program-name=apache2 \
514                 --enable-layout=Gentoo \
515                 "${MY_CONF[@]}"
516
517         sed -i -e 's:apache2\.conf:httpd.conf:' include/ap_config_auto.h
518 }
519
520 # @FUNCTION: apache-2_src_install
521 # @DESCRIPTION:
522 # This function runs `emake install' and generates, installs and adapts the gentoo
523 # specific configuration files found in the tarball
524 apache-2_src_install() {
525         emake DESTDIR="${D}" MKINSTALLDIRS="mkdir -p" install
526
527         # install our configuration files
528         keepdir /etc/apache2/vhosts.d
529         keepdir /etc/apache2/modules.d
530
531         generate_load_module
532         insinto /etc/apache2
533         doins -r "${GENTOO_PATCHDIR}"/conf/*
534         use apache2_modules_mime_magic && doins docs/conf/magic
535
536         insinto /etc/logrotate.d
537         newins "${GENTOO_PATCHDIR}"/scripts/apache2-logrotate apache2
538
539         # generate a sane default APACHE2_OPTS
540         APACHE2_OPTS="-D DEFAULT_VHOST -D INFO"
541         use doc && APACHE2_OPTS="${APACHE2_OPTS} -D MANUAL"
542         use ssl && APACHE2_OPTS="${APACHE2_OPTS} -D SSL -D SSL_DEFAULT_VHOST"
543         use suexec && APACHE2_OPTS="${APACHE2_OPTS} -D SUEXEC"
544         if has negotiation ${APACHE2_MODULES} && use apache2_modules_negotiation; then
545                 APACHE2_OPTS="${APACHE2_OPTS} -D LANGUAGE"
546         fi
547
548         sed -i -e "s:APACHE2_OPTS=\".*\":APACHE2_OPTS=\"${APACHE2_OPTS}\":" \
549                 "${GENTOO_PATCHDIR}"/init/apache2.confd || die "sed failed"
550
551         newconfd "${GENTOO_PATCHDIR}"/init/apache2.confd apache2
552         newinitd "${GENTOO_PATCHDIR}"/init/apache2.initd apache2
553
554         # install apache2ctl wrapper for our init script if available
555         if test -e "${GENTOO_PATCHDIR}"/scripts/apache2ctl; then
556                 exeinto /usr/sbin
557                 doexe "${GENTOO_PATCHDIR}"/scripts/apache2ctl
558         else
559                 dosym /etc/init.d/apache2 /usr/sbin/apache2ctl
560         fi
561
562         # provide legacy symlink for apxs, bug 177697
563         dosym apxs /usr/sbin/apxs2
564
565         # install some documentation
566         dodoc ABOUT_APACHE CHANGES LAYOUT README README.platforms VERSIONING
567         dodoc "${GENTOO_PATCHDIR}"/docs/*
568
569         # drop in a convenient link to the manual
570         if use doc ; then
571                 sed -i -e "s:VERSION:${PVR}:" "${ED}/etc/apache2/modules.d/00_apache_manual.conf"
572                 docompress -x /usr/share/doc/${PF}/manual # 503640
573         else
574                 rm -f "${ED}/etc/apache2/modules.d/00_apache_manual.conf"
575                 rm -Rf "${ED}/usr/share/doc/${PF}/manual"
576         fi
577
578         # the default icons and error pages get stored in
579         # /usr/share/apache2/{error,icons}
580         dodir /usr/share/apache2
581         mv -f "${ED}/var/www/localhost/error" "${ED}/usr/share/apache2/error"
582         mv -f "${ED}/var/www/localhost/icons" "${ED}/usr/share/apache2/icons"
583         rm -rf "${ED}/var/www/localhost/"
584         eend $?
585
586         # set some sane permissions for suexec
587         if use suexec ; then
588                 fowners 0:${SUEXEC_CALLER:-apache} /usr/sbin/suexec
589                 fperms 4710 /usr/sbin/suexec
590                 # provide legacy symlink for suexec, bug 177697
591                 dosym /usr/sbin/suexec /usr/sbin/suexec2
592         fi
593
594         # empty dirs
595         for i in /var/lib/dav /var/log/apache2 /var/cache/apache2 ; do
596                 keepdir ${i}
597                 fowners apache:apache ${i}
598                 fperms 0750 ${i}
599         done
600 }
601
602 # @FUNCTION: apache-2_pkg_postinst
603 # @DESCRIPTION:
604 # This function creates test certificates if SSL is enabled and installs the
605 # default index.html to /var/www/localhost if it does not exist. We do this here
606 # because the default webroot is a copy of the files that exist elsewhere and we
607 # don't want them to be managed/removed by portage when apache is upgraded.
608 apache-2_pkg_postinst() {
609         if use ssl && [[ ! -e "${EROOT}/etc/ssl/apache2/server.pem" ]]; then
610                 SSL_ORGANIZATION="${SSL_ORGANIZATION:-Apache HTTP Server}"
611                 install_cert /etc/ssl/apache2/server
612                 ewarn
613                 ewarn "The location of SSL certificates has changed. If you are"
614                 ewarn "upgrading from ${CATEGORY}/${PN}-2.2.13 or earlier (or remerged"
615                 ewarn "*any* apache version), you might want to move your old"
616                 ewarn "certificates from /etc/apache2/ssl/ to /etc/ssl/apache2/ and"
617                 ewarn "update your config files."
618                 ewarn
619         fi
620
621         if [[ ! -e "${EROOT}/var/www/localhost" ]] ; then
622                 mkdir -p "${EROOT}/var/www/localhost/htdocs"
623                 echo "<html><body><h1>It works!</h1></body></html>" > "${EROOT}/var/www/localhost/htdocs/index.html"
624         fi
625
626         echo
627         elog "Attention: cgi and cgid modules are now handled via APACHE2_MODULES flags"
628         elog "in make.conf. Make sure to enable those in order to compile them."
629         elog "In general, you should use 'cgid' with threaded MPMs and 'cgi' otherwise."
630         echo
631
632 }
633
634 EXPORT_FUNCTIONS pkg_setup src_prepare src_configure src_install pkg_postinst