Gentoo Archives: gentoo-commits

From: "Benedikt Boehm (hollow)" <hollow@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in eclass: apache-2.eclass
Date: Wed, 28 Nov 2007 13:11:27
Message-Id: E1IxMaL-0007Y0-7S@stork.gentoo.org
1 hollow 07/11/28 13:04:13
2
3 Added: apache-2.eclass
4 Log:
5 Add apache-2 eclass
6
7 Revision Changes Path
8 1.1 eclass/apache-2.eclass
9
10 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/apache-2.eclass?rev=1.1&view=markup
11 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/apache-2.eclass?rev=1.1&content-type=text/plain
12
13 Index: apache-2.eclass
14 ===================================================================
15 # Copyright 1999-2007 Gentoo Foundation
16 # Distributed under the terms of the GNU General Public License v2
17 # $Header: /var/cvsroot/gentoo-x86/eclass/apache-2.eclass,v 1.1 2007/11/28 13:04:12 hollow Exp $
18
19 # @ECLASS: apache-2
20 # @MAINTAINER: apache-devs@g.o
21 # @BLURB: Provides a common set of functions for >=apache-2.2* ebuilds
22 # @DESCRIPTION:
23 # This eclass handles common apache ebuild functions in a sane way and providing
24 # information about where certain interfaces are located such as LoadModule
25 # generation and inter-module dependency checking.
26
27 inherit depend.apache eutils flag-o-matic multilib autotools
28
29 # ==============================================================================
30 # INTERNAL VARIABLES
31 # ==============================================================================
32
33 # @ECLASS-VARIABLE: GENTOO_PATCHNAME
34 # @DESCRIPTION:
35 # This internal variable contains the prefix for the patch tarball
36 GENTOO_PATCHNAME="gentoo-${PF}"
37
38 # @ECLASS-VARIABLE: GENTOO_PATCHDIR
39 # @DESCRIPTION:
40 # This internal variable contains the working directory where patches and config
41 # files are located
42 GENTOO_PATCHDIR="${WORKDIR}/${GENTOO_PATCHNAME}"
43
44 # @ECLASS-VARIABLE: GENTOO_DEVELOPER
45 # @DESCRIPTION:
46 # This variable needs to be set in the ebuild and contains the name of the
47 # gentoo developer who created the patch tarball
48
49 # @ECLASS-VARIABLE: GENTOO_PATCHSTAMP
50 # @DESCRIPTION:
51 # This variable needs to be set in the ebuild and contains the date the patch
52 # tarball was created at in YYMMDD format
53
54 SRC_URI="mirror://apache/httpd/httpd-${PV}.tar.bz2
55 http://dev.gentoo.org/~${GENTOO_DEVELOPER}/dist/apache/${GENTOO_PATCHNAME}-${GENTOO_PATCHSTAMP}.tar.bz2"
56
57 # @ECLASS-VARIABLE: IUSE_MPMS_FORK
58 # @DESCRIPTION:
59 # This variable needs to be set in the ebuild and contains a list of forking
60 # (i.e. non-threaded) MPMS
61
62 # @ECLASS-VARIABLE: IUSE_MPMS_THREAD
63 # @DESCRIPTION:
64 # This variable needs to be set in the ebuild and contains a list of threaded
65 # MPMS
66
67 # @ECLASS-VARIABLE: IUSE_MODULES
68 # @DESCRIPTION:
69 # This variable needs to be set in the ebuild and contains a list of available
70 # built-in modules
71
72 IUSE_MPMS="${IUSE_MPMS_FORK} ${IUSE_MPMS_THREAD}"
73 IUSE="debug doc ldap selinux ssl static suexec threads"
74
75 for module in ${IUSE_MODULES} ; do
76 IUSE="${IUSE} apache2_modules_${module}"
77 done
78
79 for mpm in ${IUSE_MPMS} ; do
80 IUSE="${IUSE} apache2_mpms_${mpm}"
81 done
82
83 DEPEND="dev-lang/perl
84 =dev-libs/apr-1*
85 =dev-libs/apr-util-1*
86 dev-libs/libpcre
87 ldap? ( =net-nds/openldap-2* )
88 selinux? ( sec-policy/selinux-apache )
89 ssl? ( dev-libs/openssl )
90 !=www-servers/apache-1*"
91 RDEPEND="${DEPEND}"
92 PDEPEND="~app-admin/apache-tools-${PV}"
93
94 S="${WORKDIR}/httpd-${PV}"
95
96 # ==============================================================================
97 # INTERNAL FUNCTIONS
98 # ==============================================================================
99
100 # @ECLASS-VARIABLE: MY_MPM
101 # DESCRIPTION:
102 # This internal variable contains the selected MPM after a call to setup_mpm()
103
104 # @FUNCTION: setup_mpm
105 # @DESCRIPTION:
106 # This internal function makes sure that only one of APACHE2_MPMS was selected
107 # or a default based on USE=threads is selected if APACHE2_MPMS is empty
108 setup_mpm() {
109 for x in ${IUSE_MPMS} ; do
110 if use apache2_mpms_${x} ; then
111 if [[ -z "${MY_MPM}" ]] ; then
112 MY_MPM=${x}
113 elog
114 elog "Selected MPM: ${MY_MPM}"
115 elog
116 else
117 eerror "You have selected more then one mpm USE-flag."
118 eerror "Only one MPM is supported."
119 die "more then one mpm was specified"
120 fi
121 fi
122 done
123
124 if [[ -z "${MY_MPM}" ]] ; then
125 if use threads ; then
126 MY_MPM=worker
127 elog
128 elog "Selected default threaded MPM: ${MY_MPM}"
129 elog
130 else
131 MY_MPM=prefork
132 elog
133 elog "Selected default MPM: ${MY_MPM}"
134 elog
135 fi
136 fi
137
138 if has ${MY_MPM} ${IUSE_MPMS_THREAD} && ! use threads ; then
139 eerror "You have selected a threaded MPM but USE=threads is disabled"
140 die "invalid use flag combination"
141 fi
142
143 if has ${MY_MPM} ${IUSE_MPMS_FORK} && use threads ; then
144 eerror "You have selected a non-threaded MPM but USE=threads is enabled"
145 die "invalid use flag combination"
146 fi
147 }
148
149 # @ECLASS-VARIABLE: MODULE_DEPENDS
150 # @DESCRIPTION:
151 # This variable needs to be set in the ebuild and contains a space-separated
152 # list of dependency tokens each with a module and the module it depends on
153 # separated by a colon
154
155 # @FUNCTION: check_module_depends
156 # @DESCRIPTION:
157 # This internal function makes sure that all inter-module dependencies are
158 # satisfied with the current module selection
159 check_module_depends() {
160 local err=0
161
162 for m in ${MY_MODS} ; do
163 for dep in ${MODULE_DEPENDS} ; do
164 if [[ "${m}" == "${dep%:*}" ]]; then
165 if ! use apache2_modules_${dep#*:} ; then
166 eerror "Module '${m}' depends on '${dep#*:}'"
167 err=1
168 fi
169 fi
170 done
171 done
172
173 if [[ ${err} -ne 0 ]] ; then
174 die "invalid use flag combination"
175 fi
176 }
177
178 # @ECLASS-VARIABLE: MY_CONF
179 # DESCRIPTION:
180 # This internal variable contains the econf options for the current module
181 # selection after a call to setup_modules()
182
183 # @ECLASS-VARIABLE: MY_MODS
184 # DESCRIPTION:
185 # This internal variable contains a sorted, space separated list of currently
186 # selected modules after a call to setup_modules()
187
188 # @FUNCTION: setup_modules
189 # @DESCRIPTION:
190 # This internal function selects all built-in modules based on USE flags and
191 # APACHE2_MODULES USE_EXPAND flags
192 setup_modules() {
193 local mod_type=
194
195 if use static ; then
196 mod_type="static"
197 else
198 mod_type="shared"
199 fi
200
201 MY_CONF="--enable-so=static"
202
203 if use ldap ; then
204 if ! built_with_use 'dev-libs/apr-util' ldap ; then
205 eerror "dev-libs/apr-util is missing LDAP support. For apache to have"
206 eerror "ldap support, apr-util must be built with the ldap USE-flag"
207 eerror "enabled."
208 die "ldap USE-flag enabled while not supported in apr-util"
209 fi
210 MY_CONF="${MY_CONF} --enable-authnz_ldap=${mod_type} --enable-ldap=${mod_type}"
211 MY_MODS="${MY_MODS} ldap authnz_ldap"
212 else
213 MY_CONF="${MY_CONF} --disable-authnz_ldap --disable-ldap"
214 fi
215
216 if use ssl ; then
217 MY_CONF="${MY_CONF} --with-ssl=/usr --enable-ssl=${mod_type}"
218 MY_MODS="${MY_MODS} ssl"
219 else
220 MY_CONF="${MY_CONF} --without-ssl --disable-ssl"
221 fi
222
223 if use threads || has ${MY_MPM} ${IUSE_MPMS_THREAD} ; then
224 MY_CONF="${MY_CONF} --enable-cgid=${mod_type}"
225 MY_MODS="${MY_MODS} cgid"
226 else
227 MY_CONF="${MY_CONF} --enable-cgi=${mod_type}"
228 MY_MODS="${MY_MODS} cgi"
229 fi
230
231 if use suexec ; then
232 elog "You can manipulate several configure options of suexec"
233 elog "through the following environment variables:"
234 elog
235 elog " SUEXEC_SAFEPATH: Default PATH for suexec (default: /usr/local/bin:/usr/bin:/bin)"
236 elog " SUEXEC_LOGFILE: Path to the suexec logfile (default: /var/log/apache2/suexec_log)"
237 elog " SUEXEC_CALLER: Name of the user Apache is running as (default: apache)"
238 elog " SUEXEC_DOCROOT: Directory in which suexec will run scripts (default: /var/www)"
239 elog " SUEXEC_MINUID: Minimum UID, which is allowed to run scripts via suexec (default: 1000)"
240 elog " SUEXEC_MINGID: Minimum GID, which is allowed to run scripts via suexec (default: 100)"
241 elog " SUEXEC_USERDIR: User subdirectories (like /home/user/html) (default: public_html)"
242 elog " SUEXEC_UMASK: Umask for the suexec process (default: 077)"
243 elog
244
245 MY_CONF="${MY_CONF} --with-suexec-safepath=${SUEXEC_SAFEPATH:-/usr/local/bin:/usr/bin:/bin}"
246 MY_CONF="${MY_CONF} --with-suexec-logfile=${SUEXEC_LOGFILE:-/var/log/apache2/suexec_log}"
247 MY_CONF="${MY_CONF} --with-suexec-bin=/usr/sbin/suexec"
248 MY_CONF="${MY_CONF} --with-suexec-userdir=${SUEXEC_USERDIR:-public_html}"
249 MY_CONF="${MY_CONF} --with-suexec-caller=${SUEXEC_CALLER:-apache}"
250 MY_CONF="${MY_CONF} --with-suexec-docroot=${SUEXEC_DOCROOT:-/var/www}"
251 MY_CONF="${MY_CONF} --with-suexec-uidmin=${SUEXEC_MINUID:-1000}"
252 MY_CONF="${MY_CONF} --with-suexec-gidmin=${SUEXEC_MINGID:-100}"
253 MY_CONF="${MY_CONF} --with-suexec-umask=${SUEXEC_UMASK:-077}"
254 MY_CONF="${MY_CONF} --enable-suexec=${mod_type}"
255 MY_MODS="${MY_MODS} suexec"
256 else
257 MY_CONF="${MY_CONF} --disable-suexec"
258 fi
259
260 for x in ${IUSE_MODULES} ; do
261 if use apache2_modules_${x} ; then
262 MY_CONF="${MY_CONF} --enable-${x}=${mod_type}"
263 MY_MODS="${MY_MODS} ${x}"
264 else
265 MY_CONF="${MY_CONF} --disable-${x}"
266 fi
267 done
268
269 # sort and uniquify MY_MODS
270 MY_MODS=$(echo ${MY_MODS} | tr ' ' '\n' | sort -u)
271 check_module_depends
272 }
273
274 # @ECLASS-VARIABLE: MODULE_DEFINES
275 # @DESCRIPTION:
276 # This variable needs to be set in the ebuild and contains a space-separated
277 # list of tokens each mapping a module to a runtime define which can be
278 # specified in APACHE2_OPTS in /etc/conf.d/apache2 to enable this particular
279 # module.
280
281 # @FUNCTION: generate_load_module
282 # @DESCRIPTION:
283 # This internal function generates the LoadModule lines for httpd.conf based on
284 # the current module selection and MODULE_DEFINES
285 generate_load_module() {
286 local endit=0 mod_lines= mod_dir="${D}${APACHE2_MODULESDIR}"
287
288 if use static; then
289 sed -i -e "/%%LOAD_MODULE%%/d" \
290 "${GENTOO_PATCHDIR}"/conf/httpd.conf
291 return
292 fi
293
294 for m in ${MY_MODS} ; do
295 if [[ -e "${mod_dir}/mod_${m}.so" ]] ; then
296 for def in ${MODULE_DEFINES} ; do
297 if [[ "${m}" == "${def%:*}" ]] ; then
298 mod_lines="${mod_lines}\n<IfDefine ${def#*:}>"
299 endit=1
300 fi
301 done
302
303 mod_lines="${mod_lines}\nLoadModule ${m}_module modules/mod_${m}.so"
304
305 if [[ ${endit} -ne 0 ]] ; then
306 mod_lines="${mod_lines}\n</IfDefine>"
307 endit=0
308 fi
309 fi
310 done
311
312 sed -i -e "s:%%LOAD_MODULE%%:${mod_lines}:" \
313 "${GENTOO_PATCHDIR}"/conf/httpd.conf
314 }
315
316 # @FUNCTION: check_upgrade
317 # @DESCRIPTION:
318 # This internal function checks if the previous configuration file for built-in
319 # modules exists in ROOT and prevents upgrade in this case. Users are supposed
320 # to convert this file to the new APACHE2_MODULES USE_EXPAND variable and remove
321 # it afterwards.
322 check_upgrade() {
323 if [[ -e "${ROOT}"etc/apache2/apache2-builtin-mods ]]; then
324 eerror "The previous configuration file for built-in modules"
325 eerror "(${ROOT}etc/apache2/apache2-builtin-mods) exists on your"
326 eerror "system."
327 eerror
328 eerror "Please read http://www.gentoo.org/proj/en/apache/upgrade.xml"
329 eerror "for detailed information how to convert this file to the new"
330 eerror "APACHE2_MODULES USE_EXPAND variable."
331 eerror
332 die "upgrade not possible with existing ${ROOT}etc/apache2/apache2-builtin-mods"
333 fi
334 }
335
336 # ==============================================================================
337 # EXPORTED FUNCTIONS
338 # ==============================================================================
339
340 # @FUNCTION: apache-2_pkg_setup
341 # @DESCRIPTION:
342 # This function selects built-in modules, the MPM and other configure options,
343 # creates the apache user and group and informs about CONFIG_SYSVIPC being
344 # needed (we don't depend on kernel sources and therefore cannot check).
345 apache-2_pkg_setup() {
346 check_upgrade
347
348 setup_mpm
349 setup_modules
350
351 if use debug; then
352 MY_CONF="${MY_CONF} --enable-maintainer-mode --enable-exception-hook"
353 fi
354
355 # setup apache user and group
356 enewgroup apache 81
357 enewuser apache 81 -1 /var/www apache
358
359 elog "Please note that you need SysV IPC support in your kernel."
360 elog "Make sure CONFIG_SYSVIPC=y is set."
361 elog
362 }
363
364 # @FUNCTION: apache-2_src_unpack
365 # @DESCRIPTION:
366 # This function applies patches, configures a custom file-system layout and
367 # rebuilds the configure scripts. The patch names are organized as follows:
368 #
369 # 00-19 Gentoo specific (00_all_some-title.patch)
370 # 20-39 Additional MPMs (20_all_${MPM}_some-title.patch)
371 # 40-59 USE-flag based (40_all_${USE}_some-title.patch)
372 # 60-79 Version specific (60_all_${PV}_some-title.patch)
373 # 80-99 Security patches (80_all_${PV}_cve-####-####.patch)
374 apache-2_src_unpack() {
375 unpack ${A}
376 cd "${S}"
377
378 # Use correct multilib libdir in gentoo patches
379 sed -i -e "s:/usr/lib:/usr/$(get_libdir):g" \
380 "${GENTOO_PATCHDIR}"/{conf/httpd.conf,init/*,patches/config.layout} \
381 || die "libdir sed failed"
382
383 epatch "${GENTOO_PATCHDIR}"/patches/*.patch
384
385 # setup the filesystem layout config
386 cat "${GENTOO_PATCHDIR}"/patches/config.layout >> "${S}"/config.layout || \
387 die "Failed preparing config.layout!"
388 sed -i -e "s:version:${PF}:g" "${S}"/config.layout
389
390 # patched-in MPMs need the build environment rebuilt
391 sed -i -e '/sinclude/d' configure.in
392 AT_GNUCONF_UPDATE=yes AT_M4DIR=build eautoreconf
393
394 # apache2.8 instead of httpd.8 (bug #194828)
395 mv docs/man/{httpd,apache2}.8
396 }
397
398 # @FUNCTION: apache-2_src_compile
399 # @DESCRIPTION:
400 # This function adds compiler flags and runs econf and emake based on MY_MPM and
401 # MY_CONF
402 apache-2_src_compile() {
403 # Instead of filtering --as-needed (bug #128505), append --no-as-needed
404 # Thanks to Harald van Dijk
405 append-ldflags -Wl,--no-as-needed
406
407 # peruser MPM debugging with -X is nearly impossible
408 if has peruser ${IUSE_MPMS} && use apache2_mpms_peruser ; then
409 use debug && append-flags -DMPM_PERUSER_DEBUG
410 fi
411
412 # econf overwrites the stuff from config.layout, so we have to put them into
413 # our myconf line too
414 econf \
415 --includedir=/usr/include/apache2 \
416 --libexecdir=/usr/$(get_libdir)/apache2/modules \
417 --datadir=/var/www/localhost \
418 --sysconfdir=/etc/apache2 \
419 --localstatedir=/var \
420 --with-mpm=${MY_MPM} \
421 --with-perl=/usr/bin/perl \
422 --with-apr=/usr \
423 --with-apr-util=/usr \
424 --with-pcre=/usr \
425 --with-z=/usr \
426 --with-port=80 \
427 --with-program-name=apache2 \
428 --enable-layout=Gentoo \
429 ${MY_CONF} || die "econf failed!"
430
431 sed -i -e 's:apache2\.conf:httpd.conf:' include/ap_config_auto.h
432
433 emake || die "emake failed"
434 }
435
436 # @FUNCTION: apache-2_src_install
437 # @DESCRIPTION:
438 # This function runs emake install and generates, install and adapts the gentoo
439 # specific configuration files found in the tarball
440 apache-2_src_install() {
441 emake DESTDIR="${D}" install || die "emake install failed"
442
443 # install our configuration files
444 keepdir /etc/apache2/vhosts.d
445 keepdir /etc/apache2/modules.d
446
447 generate_load_module
448 insinto /etc/apache2
449 doins -r "${GENTOO_PATCHDIR}"/conf/*
450 doins docs/conf/magic
451
452 insinto /etc/logrotate.d
453 newins "${GENTOO_PATCHDIR}"/scripts/apache2-logrotate apache2
454
455 # generate a sane default APACHE2_OPTS
456 APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D LANGUAGE"
457 use doc && APACHE2_OPTS="${APACHE2_OPTS} -D MANUAL"
458 use ssl && APACHE2_OPTS="${APACHE2_OPTS} -D SSL -D SSL_DEFAULT_VHOST"
459 use suexec && APACHE2_OPTS="${APACHE2_OPTS} -D SUEXEC"
460
461 sed -i -e "s:APACHE2_OPTS=\".*\":APACHE2_OPTS=\"${APACHE2_OPTS}\":" \
462 "${GENTOO_PATCHDIR}"/init/apache2.confd || die "sed failed"
463
464 newconfd "${GENTOO_PATCHDIR}"/init/apache2.confd apache2
465 newinitd "${GENTOO_PATCHDIR}"/init/apache2.initd apache2
466
467 # link apache2ctl to the init script
468 dosym /etc/init.d/apache2 /usr/sbin/apache2ctl
469
470 # provide symlinks for all the stuff we no longer rename, bug 177697
471 for i in suexec apxs; do
472 dosym /usr/sbin/${i} /usr/sbin/${i}2
473 done
474
475 # install some thirdparty scripts
476 exeinto /usr/sbin
477 use ssl && doexe "${GENTOO_PATCHDIR}"/scripts/gentestcrt.sh
478
479 # install some documentation
480 dodoc ABOUT_APACHE CHANGES LAYOUT README README.platforms VERSIONING
481 dodoc "${GENTOO_PATCHDIR}"/docs/*
482
483 # drop in a convenient link to the manual
484 if use doc ; then
485 sed -i -e "s:VERSION:${PVR}:" "${D}/etc/apache2/modules.d/00_apache_manual.conf"
486 else
487 rm -f "${D}/etc/apache2/modules.d/00_apache_manual.conf"
488 rm -Rf "${D}/usr/share/doc/${PF}/manual"
489 fi
490
491 # the default webroot gets stored in /usr/share/doc
492 ebegin "Installing default webroot to /usr/share/doc/${PF}"
493 mv -f "${D}/var/www/localhost" "${D}/usr/share/doc/${PF}/webroot"
494 eend $?
495 keepdir /var/www/localhost/htdocs
496
497 # set some sane permissions for suexec
498 if use suexec ; then
499 fowners 0:apache /usr/sbin/suexec
500 fperms 4710 /usr/sbin/suexec
501 fi
502
503 # empty dirs
504 for i in /var/lib/dav /var/log/apache2 /var/cache/apache2 ; do
505 keepdir ${i}
506 fowners apache:apache ${i}
507 fperms 0755 ${i}
508 done
509
510 # we need /etc/apache2/ssl if USE=ssl
511 use ssl && keepdir /etc/apache2/ssl
512 }
513
514 # @FUNCTION: apache-2_pkg_postinst
515 # @DESCRIPTION:
516 # This function creates test certificates if SSL is enabled and installs the
517 # default webroot if /var/www/localhost does not exist. We do this here because
518 # the default webroot is a copy of the files that exist elsewhere and we don't
519 # want them to be managed/removed by portage when apache is upgraded.
520 apache-2_pkg_postinst() {
521 if use ssl && [[ ! -e "${ROOT}/etc/apache2/ssl/server.crt" ]] ; then
522 cd "${ROOT}"/etc/apache2/ssl
523 einfo
524 einfo "Generating self-signed test certificate in ${ROOT}etc/apache2/ssl ..."
525 yes "" 2>/dev/null | \
526 "${ROOT}"/usr/sbin/gentestcrt.sh >/dev/null 2>&1 || \
527 die "gentestcrt.sh failed"
528 einfo
529 fi
530
531 if [[ -e "${ROOT}/var/www/localhost" ]] ; then
532 elog "The default webroot has not been installed into"
533 elog "${ROOT}var/www/localhost because the directory already exists"
534 elog "and we do not want to overwrite any files you have put there."
535 elog
536 elog "If you would like to install the latest webroot, please run"
537 elog "emerge --config =${PF}"
538 elog
539 else
540 einfo "Installing default webroot to ${ROOT}var/www/localhost"
541 mkdir -p "${ROOT}"/var/www/localhost
542 cp -R "${ROOT}"/usr/share/doc/${PF}/webroot/* "${ROOT}"/var/www/localhost
543 chown -R apache:0 "${ROOT}"/var/www/localhost
544 fi
545 }
546
547 # @FUNCTION: apache-2_pkg_config
548 # @DESCRIPTION:
549 # This function installs -- and removes a previously existing -- default webroot
550 # to /var/www/localhost
551 apache-2_pkg_config() {
552 einfo "Installing default webroot to ${ROOT}var/www/localhost"
553 mkdir "${ROOT}"var{,/www{,/localhost}}
554 cp -R "${ROOT}"usr/share/doc/${PF}/webroot/* "${ROOT}"var/www/localhost/
555 }
556
557 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_postinst pkg_config
558
559
560
561 --
562 gentoo-commits@g.o mailing list