/[gentoo-x86]/eclass/webapp.eclass
Gentoo

Diff of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.57 Revision 1.70
1# Copyright 1999-2006 Gentoo Foundation 1# Copyright 1999-2011 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.57 2008/02/22 14:59:07 hollow Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.70 2011/12/27 17:55:12 fauli Exp $
4# 4
5# @ECLASS: webapp.eclass 5# @ECLASS: webapp.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# web-apps@gentoo.org 7# web-apps@gentoo.org
8# @BLURB: functions for installing applications to run under a web server 8# @BLURB: functions for installing applications to run under a web server
9# @DESCRIPTION: 9# @DESCRIPTION:
10# The webapp eclass contains functions to handle web applications with 10# The webapp eclass contains functions to handle web applications with
11# webapp-config. Part of the implementation of GLEP #11 11# webapp-config. Part of the implementation of GLEP #11
12 12
13# @ECLASS-VARIABLE: WEBAPP_DEPEND
14# @DESCRIPTION:
15# An ebuild should use WEBAPP_DEPEND if a custom DEPEND needs to be built, most
16# notably in combination with WEBAPP_OPTIONAL.
17WEBAPP_DEPEND=">=app-admin/webapp-config-1.50.15"
18
19# @ECLASS-VARIABLE: WEBAPP_NO_AUTO_INSTALL
20# @DESCRIPTION:
21# An ebuild sets this to `yes' if an automatic installation and/or upgrade is
22# not possible. The ebuild should overwrite pkg_postinst() and explain the
23# reason for this BEFORE calling webapp_pkg_postinst().
24
25# @ECLASS-VARIABLE: WEBAPP_OPTIONAL
26# @DESCRIPTION:
27# An ebuild sets this to `yes' to make webapp support optional, in which case
28# you also need to take care of USE-flags and dependencies.
29
30if [[ "${WEBAPP_OPTIONAL}" != "yes" ]]; then
31 [[ "${WEBAPP_NO_AUTO_INSTALL}" == "yes" ]] || IUSE="vhosts"
13SLOT="${PVR}" 32 SLOT="${PVR}"
14IUSE="vhosts" 33 DEPEND="${WEBAPP_DEPEND}"
15DEPEND=">=app-admin/webapp-config-1.50.15"
16RDEPEND="${DEPEND}" 34 RDEPEND="${DEPEND}"
35fi
17 36
18EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm 37EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm
19 38
20INSTALL_DIR="/${PN}" 39INSTALL_DIR="/${PN}"
21IS_UPGRADE=0 40IS_UPGRADE=0
38 debug-print-function $FUNCNAME $* 57 debug-print-function $FUNCNAME $*
39 58
40 if has_version '>=app-admin/webapp-config-1.50'; then 59 if has_version '>=app-admin/webapp-config-1.50'; then
41 ENVVAR=$(${WEBAPP_CONFIG} --query ${PN} ${PVR}) || die "Could not read settings from webapp-config!" 60 ENVVAR=$(${WEBAPP_CONFIG} --query ${PN} ${PVR}) || die "Could not read settings from webapp-config!"
42 eval ${ENVVAR} 61 eval ${ENVVAR}
43 else 62 elif [[ "${WEBAPP_OPTIONAL}" != "yes" ]]; then
63 # ETC_CONFIG might not be available
64 . ${ETC_CONFIG} || die "Unable to read ${ETC_CONFIG}"
65 elif [[ -f "${ETC_CONFIG}" ]]; then
66 # WEBAPP_OPTIONAL is set to yes
67 # and this must run only if ETC_CONFIG actually exists
44 . ${ETC_CONFIG} || die "Unable to read ${ETC_CONFIG}" 68 . ${ETC_CONFIG} || die "Unable to read ${ETC_CONFIG}"
45 fi 69 fi
46} 70}
47 71
48# Check whether a specified file exists in the given directory (`.' by default) 72# Check whether a specified file exists in the given directory (`.' by default)
79 echo "${1/#.\///}" 103 echo "${1/#.\///}"
80} 104}
81 105
82webapp_getinstalltype() { 106webapp_getinstalltype() {
83 debug-print-function $FUNCNAME $* 107 debug-print-function $FUNCNAME $*
84 use vhosts && return 108
109 if ! has vhosts ${IUSE} || use vhosts; then
110 return
111 fi
85 112
86 local my_output 113 local my_output
87 my_output="$(webapp_check_installedat)" 114 my_output="$(webapp_check_installedat)"
88 115
89 if [[ $? -eq 0 ]]; then 116 if [[ $? -eq 0 ]]; then
97 124
98 if [[ "${my_pn}" == "${PN}" ]]; then 125 if [[ "${my_pn}" == "${PN}" ]]; then
99 if [[ "${my_pvr}" != "${PVR}" ]]; then 126 if [[ "${my_pvr}" != "${PVR}" ]]; then
100 elog "This is an upgrade" 127 elog "This is an upgrade"
101 IS_UPGRADE=1 128 IS_UPGRADE=1
129 # for binpkgs, reset status, var declared in global scope
130 IS_REPLACE=0
102 else 131 else
103 elog "This is a re-installation" 132 elog "This is a re-installation"
104 IS_REPLACE=1 133 IS_REPLACE=1
134 # for binpkgs, reset status, var declared in global scope
135 IS_UPGRADE=0
105 fi 136 fi
106 else 137 else
107 elog "${my_output} is installed there" 138 elog "${my_output} is installed there"
108 fi 139 fi
109 else 140 else
141 # for binpkgs, reset status, var declared in global scope
142 IS_REPLACE=0
143 IS_UPGRADE=0
110 elog "This is an installation" 144 elog "This is an installation"
111 fi 145 fi
112} 146}
113 147
114# ============================================================================== 148# ==============================================================================
115# PUBLIC FUNCTIONS 149# PUBLIC FUNCTIONS
116# ============================================================================== 150# ==============================================================================
151
152# @FUNCTION: need_httpd
153# @DESCRIPTION:
154# Call this function AFTER your ebuilds DEPEND line if any of the available
155# webservers are able to run this application.
156need_httpd() {
157 DEPEND="${DEPEND}
158 || ( virtual/httpd-basic virtual/httpd-cgi virtual/httpd-fastcgi )"
159}
160
161# @FUNCTION: need_httpd_cgi
162# @DESCRIPTION:
163# Call this function AFTER your ebuilds DEPEND line if any of the available
164# CGI-capable webservers are able to run this application.
165need_httpd_cgi() {
166 DEPEND="${DEPEND}
167 || ( virtual/httpd-cgi virtual/httpd-fastcgi )"
168}
169
170# @FUNCTION: need_httpd_fastcgi
171# @DESCRIPTION:
172# Call this function AFTER your ebuilds DEPEND line if any of the available
173# FastCGI-capabale webservers are able to run this application.
174need_httpd_fastcgi() {
175 DEPEND="${DEPEND}
176 virtual/httpd-fastcgi"
177}
117 178
118# @FUNCTION: webapp_configfile 179# @FUNCTION: webapp_configfile
119# @USAGE: <file> [more files ...] 180# @USAGE: <file> [more files ...]
120# @DESCRIPTION: 181# @DESCRIPTION:
121# Mark a file config-protected for a web-based application. 182# Mark a file config-protected for a web-based application.
270# You need to call this function in src_install() BEFORE anything else has run. 331# You need to call this function in src_install() BEFORE anything else has run.
271# For now we just create required webapp-config directories. 332# For now we just create required webapp-config directories.
272webapp_src_preinst() { 333webapp_src_preinst() {
273 debug-print-function $FUNCNAME $* 334 debug-print-function $FUNCNAME $*
274 335
336 # sanity checks, to catch bugs in the ebuild
337 if [[ ! -f "${T}/${SETUP_CHECK_FILE}" ]]; then
338 eerror
339 eerror "This ebuild did not call webapp_pkg_setup() at the beginning"
340 eerror "of the pkg_setup() function"
341 eerror
342 eerror "Please log a bug on http://bugs.gentoo.org"
343 eerror
344 eerror "You should use emerge -C to remove this package, as the"
345 eerror "installation is incomplete"
346 eerror
347 die "Ebuild did not call webapp_pkg_setup() - report to http://bugs.gentoo.org"
348 fi
349
350 # Hint, see the webapp_read_config() function to find where these are
351 # defined.
275 dodir "${MY_HTDOCSDIR}" 352 dodir "${MY_HTDOCSDIR}"
276 dodir "${MY_HOSTROOTDIR}" 353 dodir "${MY_HOSTROOTDIR}"
277 dodir "${MY_CGIBINDIR}" 354 dodir "${MY_CGIBINDIR}"
278 dodir "${MY_ICONSDIR}" 355 dodir "${MY_ICONSDIR}"
279 dodir "${MY_ERRORSDIR}" 356 dodir "${MY_ERRORSDIR}"
315 webapp_read_config 392 webapp_read_config
316 393
317 local my_dir="${ROOT}${VHOST_ROOT}/${MY_HTDOCSBASE}/${PN}" 394 local my_dir="${ROOT}${VHOST_ROOT}/${MY_HTDOCSBASE}/${PN}"
318 395
319 # if USE=vhosts is enabled OR no application is installed we're done here 396 # if USE=vhosts is enabled OR no application is installed we're done here
320 use vhosts || [[ ! -d "${my_dir}" ]] && return 397 if ! has vhosts ${IUSE} || use vhosts || [[ ! -d "${my_dir}" ]]; then
398 return
399 fi
321 400
322 local my_output 401 local my_output
323 my_output="$(webapp_check_installedat)" 402 my_output="$(webapp_check_installedat)"
324 403
325 if [[ $? -ne 0 ]]; then 404 if [[ $? -ne 0 ]]; then
363 # we used to just set a variable in the shell script, but we can 442 # we used to just set a variable in the shell script, but we can
364 # no longer rely on Portage calling both webapp_src_install() and 443 # no longer rely on Portage calling both webapp_src_install() and
365 # webapp_pkg_postinst() within the same shell process 444 # webapp_pkg_postinst() within the same shell process
366 touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}" 445 touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}"
367 446
368 # sanity checks, to catch bugs in the ebuild
369 if [[ ! -f "${T}/${SETUP_CHECK_FILE}" ]]; then
370 eerror
371 eerror "This ebuild did not call webapp_pkg_setup() at the beginning"
372 eerror "of the pkg_setup() function"
373 eerror
374 eerror "Please log a bug on http://bugs.gentoo.org"
375 eerror
376 eerror "You should use emerge -C to remove this package, as the"
377 eerror "installation is incomplete"
378 eerror
379 die "Ebuild did not call webapp_pkg_setup() - report to http://bugs.gentoo.org"
380 fi
381
382 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/" 447 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/"
383 chmod -R u-s "${D}/" 448 chmod -R u-s "${D}/"
384 chmod -R g-s "${D}/" 449 chmod -R g-s "${D}/"
385 450
386 keepdir "${MY_PERSISTDIR}" 451 keepdir "${MY_PERSISTDIR}"
413 eerror "installation is incomplete" 478 eerror "installation is incomplete"
414 eerror 479 eerror
415 die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org" 480 die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org"
416 fi 481 fi
417 482
483 if has vhosts ${IUSE}; then
418 if ! use vhosts; then 484 if ! use vhosts; then
419 echo 485 echo
420 elog "vhosts USE flag not set - auto-installing using webapp-config" 486 elog "vhosts USE flag not set - auto-installing using webapp-config"
421 487
422 G_HOSTNAME="localhost" 488 G_HOSTNAME="localhost"
423 webapp_read_config 489 webapp_read_config
424 490
425 local my_mode=-I 491 local my_mode=-I
426 webapp_getinstalltype 492 webapp_getinstalltype
427 493
428 if [[ "${IS_REPLACE}" == "1" ]]; then 494 if [[ "${IS_REPLACE}" == "1" ]]; then
429 elog "${PN}-${PVR} is already installed - replacing" 495 elog "${PN}-${PVR} is already installed - replacing"
430 my_mode=-I 496 my_mode=-I
431 elif [[ "${IS_UPGRADE}" == "1" ]]; then 497 elif [[ "${IS_UPGRADE}" == "1" ]]; then
432 elog "${REMOVE_PKG} is already installed - upgrading" 498 elog "${REMOVE_PKG} is already installed - upgrading"
433 my_mode=-U 499 my_mode=-U
500 else
501 elog "${PN}-${PVR} is not installed - using install mode"
502 fi
503
504 my_cmd="${WEBAPP_CONFIG} ${my_mode} -h localhost -u root -d ${INSTALL_DIR} ${PN} ${PVR}"
505 elog "Running ${my_cmd}"
506 ${my_cmd}
507
508 echo
509 local cleaner="${WEBAPP_CLEANER} -p -C /${PN}"
510 einfo "Running ${cleaner}"
511 ${cleaner}
434 else 512 else
435 elog "${PN}-${PVR} is not installed - using install mode" 513 elog
514 elog "The 'vhosts' USE flag is switched ON"
515 elog "This means that Portage will not automatically run webapp-config to"
516 elog "complete the installation."
517 elog
518 elog "To install ${PN}-${PVR} into a virtual host, run the following command:"
519 elog
520 elog " webapp-config -I -h <host> -d ${PN} ${PN} ${PVR}"
521 elog
522 elog "For more details, see the webapp-config(8) man page"
436 fi 523 fi
437
438 my_cmd="${WEBAPP_CONFIG} ${my_mode} -h localhost -u root -d ${INSTALL_DIR} ${PN} ${PVR}"
439 elog "Running ${my_cmd}"
440 ${my_cmd}
441
442 echo
443 local cleaner="${WEBAPP_CLEANER} -p -C ${PN}"
444 einfo "Running ${cleaner}"
445 ${cleaner}
446 else 524 else
447 elog 525 elog
448 elog "The 'vhosts' USE flag is switched ON" 526 elog "This ebuild does not support the 'vhosts' USE flag."
449 elog "This means that Portage will not automatically run webapp-config to" 527 elog "This means that Portage will not automatically run webapp-config to"
450 elog "complete the installation." 528 elog "complete the installation."
451 elog 529 elog
452 elog "To install ${PN}-${PVR} into a virtual host, run the following command:" 530 elog "To install ${PN}-${PVR} into a virtual host, run the following command:"
453 elog 531 elog
468 local my_output= 546 local my_output=
469 my_output="$(${WEBAPP_CONFIG} --list-installs ${PN} ${PVR})" 547 my_output="$(${WEBAPP_CONFIG} --list-installs ${PN} ${PVR})"
470 [[ $? -ne 0 ]] && return 548 [[ $? -ne 0 ]] && return
471 549
472 local x 550 local x
473 if ! use vhosts; then 551 if has vhosts ${IUSE} && ! use vhosts; then
474 echo "${my_output}" | while read x; do 552 echo "${my_output}" | while read x; do
475 if [[ -f "${x}"/.webapp ]]; then 553 if [[ -f "${x}"/.webapp ]]; then
476 . "${x}"/.webapp 554 . "${x}"/.webapp
477 if [[ -n "${WEB_HOSTNAME}" && -n "${WEB_INSTALLDIR}" ]]; then 555 if [[ -n "${WEB_HOSTNAME}" && -n "${WEB_INSTALLDIR}" ]]; then
478 ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR} 556 ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR} ${PN} ${PVR}
479 fi 557 fi
480 else 558 else
481 ewarn "Cannot find file ${x}/.webapp" 559 ewarn "Cannot find file ${x}/.webapp"
482 fi 560 fi
483 done 561 done

Legend:
Removed from v.1.57  
changed lines
  Added in v.1.70

  ViewVC Help
Powered by ViewVC 1.1.20