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

Diff of /eclass/webapp.eclass

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

Revision 1.58 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.58 2008/02/22 15:33:32 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# ==============================================================================
117 151
118# @FUNCTION: need_httpd 152# @FUNCTION: need_httpd
119# @DESCRIPTION: 153# @DESCRIPTION:
120# Call this function AFTER your ebuild's DEPEND line if any of the available 154# Call this function AFTER your ebuilds DEPEND line if any of the available
121# webservers are able to run this application. 155# webservers are able to run this application.
122need_httpd() { 156need_httpd() {
123 DEPEND="${DEPEND} 157 DEPEND="${DEPEND}
124 || ( virtual/httpd-basic virtual/httpd-cgi virtual/httpd-fastcgi )" 158 || ( virtual/httpd-basic virtual/httpd-cgi virtual/httpd-fastcgi )"
125} 159}
126 160
127# @FUNCTION: need_httpd_cgi 161# @FUNCTION: need_httpd_cgi
128# @DESCRIPTION: 162# @DESCRIPTION:
129# Call this function AFTER your ebuild's DEPEND line if any of the available 163# Call this function AFTER your ebuilds DEPEND line if any of the available
130# CGI-capable webservers are able to run this application. 164# CGI-capable webservers are able to run this application.
131need_httpd_cgi() { 165need_httpd_cgi() {
132 DEPEND="${DEPEND} 166 DEPEND="${DEPEND}
133 || ( virtual/httpd-cgi virtual/httpd-fastcgi )" 167 || ( virtual/httpd-cgi virtual/httpd-fastcgi )"
134} 168}
135 169
136# @FUNCTION: need_httpd_fastcgi 170# @FUNCTION: need_httpd_fastcgi
137# @DESCRIPTION: 171# @DESCRIPTION:
138# Call this function AFTER your ebuild's DEPEND line if any of the available 172# Call this function AFTER your ebuilds DEPEND line if any of the available
139# FastCGI-capabale webservers are able to run this application. 173# FastCGI-capabale webservers are able to run this application.
140need_httpd_fastcgi() { 174need_httpd_fastcgi() {
141 DEPEND="${DEPEND} 175 DEPEND="${DEPEND}
142 virtual/httpd-fastcgi" 176 virtual/httpd-fastcgi"
143} 177}
297# 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.
298# For now we just create required webapp-config directories. 332# For now we just create required webapp-config directories.
299webapp_src_preinst() { 333webapp_src_preinst() {
300 debug-print-function $FUNCNAME $* 334 debug-print-function $FUNCNAME $*
301 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.
302 dodir "${MY_HTDOCSDIR}" 352 dodir "${MY_HTDOCSDIR}"
303 dodir "${MY_HOSTROOTDIR}" 353 dodir "${MY_HOSTROOTDIR}"
304 dodir "${MY_CGIBINDIR}" 354 dodir "${MY_CGIBINDIR}"
305 dodir "${MY_ICONSDIR}" 355 dodir "${MY_ICONSDIR}"
306 dodir "${MY_ERRORSDIR}" 356 dodir "${MY_ERRORSDIR}"
342 webapp_read_config 392 webapp_read_config
343 393
344 local my_dir="${ROOT}${VHOST_ROOT}/${MY_HTDOCSBASE}/${PN}" 394 local my_dir="${ROOT}${VHOST_ROOT}/${MY_HTDOCSBASE}/${PN}"
345 395
346 # 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
347 use vhosts || [[ ! -d "${my_dir}" ]] && return 397 if ! has vhosts ${IUSE} || use vhosts || [[ ! -d "${my_dir}" ]]; then
398 return
399 fi
348 400
349 local my_output 401 local my_output
350 my_output="$(webapp_check_installedat)" 402 my_output="$(webapp_check_installedat)"
351 403
352 if [[ $? -ne 0 ]]; then 404 if [[ $? -ne 0 ]]; then
390 # 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
391 # no longer rely on Portage calling both webapp_src_install() and 443 # no longer rely on Portage calling both webapp_src_install() and
392 # webapp_pkg_postinst() within the same shell process 444 # webapp_pkg_postinst() within the same shell process
393 touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}" 445 touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}"
394 446
395 # sanity checks, to catch bugs in the ebuild
396 if [[ ! -f "${T}/${SETUP_CHECK_FILE}" ]]; then
397 eerror
398 eerror "This ebuild did not call webapp_pkg_setup() at the beginning"
399 eerror "of the pkg_setup() function"
400 eerror
401 eerror "Please log a bug on http://bugs.gentoo.org"
402 eerror
403 eerror "You should use emerge -C to remove this package, as the"
404 eerror "installation is incomplete"
405 eerror
406 die "Ebuild did not call webapp_pkg_setup() - report to http://bugs.gentoo.org"
407 fi
408
409 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/" 447 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/"
410 chmod -R u-s "${D}/" 448 chmod -R u-s "${D}/"
411 chmod -R g-s "${D}/" 449 chmod -R g-s "${D}/"
412 450
413 keepdir "${MY_PERSISTDIR}" 451 keepdir "${MY_PERSISTDIR}"
440 eerror "installation is incomplete" 478 eerror "installation is incomplete"
441 eerror 479 eerror
442 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"
443 fi 481 fi
444 482
483 if has vhosts ${IUSE}; then
445 if ! use vhosts; then 484 if ! use vhosts; then
446 echo 485 echo
447 elog "vhosts USE flag not set - auto-installing using webapp-config" 486 elog "vhosts USE flag not set - auto-installing using webapp-config"
448 487
449 G_HOSTNAME="localhost" 488 G_HOSTNAME="localhost"
450 webapp_read_config 489 webapp_read_config
451 490
452 local my_mode=-I 491 local my_mode=-I
453 webapp_getinstalltype 492 webapp_getinstalltype
454 493
455 if [[ "${IS_REPLACE}" == "1" ]]; then 494 if [[ "${IS_REPLACE}" == "1" ]]; then
456 elog "${PN}-${PVR} is already installed - replacing" 495 elog "${PN}-${PVR} is already installed - replacing"
457 my_mode=-I 496 my_mode=-I
458 elif [[ "${IS_UPGRADE}" == "1" ]]; then 497 elif [[ "${IS_UPGRADE}" == "1" ]]; then
459 elog "${REMOVE_PKG} is already installed - upgrading" 498 elog "${REMOVE_PKG} is already installed - upgrading"
460 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}
461 else 512 else
462 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"
463 fi 523 fi
464
465 my_cmd="${WEBAPP_CONFIG} ${my_mode} -h localhost -u root -d ${INSTALL_DIR} ${PN} ${PVR}"
466 elog "Running ${my_cmd}"
467 ${my_cmd}
468
469 echo
470 local cleaner="${WEBAPP_CLEANER} -p -C ${PN}"
471 einfo "Running ${cleaner}"
472 ${cleaner}
473 else 524 else
474 elog 525 elog
475 elog "The 'vhosts' USE flag is switched ON" 526 elog "This ebuild does not support the 'vhosts' USE flag."
476 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"
477 elog "complete the installation." 528 elog "complete the installation."
478 elog 529 elog
479 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:"
480 elog 531 elog
495 local my_output= 546 local my_output=
496 my_output="$(${WEBAPP_CONFIG} --list-installs ${PN} ${PVR})" 547 my_output="$(${WEBAPP_CONFIG} --list-installs ${PN} ${PVR})"
497 [[ $? -ne 0 ]] && return 548 [[ $? -ne 0 ]] && return
498 549
499 local x 550 local x
500 if ! use vhosts; then 551 if has vhosts ${IUSE} && ! use vhosts; then
501 echo "${my_output}" | while read x; do 552 echo "${my_output}" | while read x; do
502 if [[ -f "${x}"/.webapp ]]; then 553 if [[ -f "${x}"/.webapp ]]; then
503 . "${x}"/.webapp 554 . "${x}"/.webapp
504 if [[ -n "${WEB_HOSTNAME}" && -n "${WEB_INSTALLDIR}" ]]; then 555 if [[ -n "${WEB_HOSTNAME}" && -n "${WEB_INSTALLDIR}" ]]; then
505 ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR} 556 ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR} ${PN} ${PVR}
506 fi 557 fi
507 else 558 else
508 ewarn "Cannot find file ${x}/.webapp" 559 ewarn "Cannot find file ${x}/.webapp"
509 fi 560 fi
510 done 561 done

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

  ViewVC Help
Powered by ViewVC 1.1.20