| 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.72 2012/07/18 14:59:29 blueness 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. |
|
|
17 | WEBAPP_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 | |
|
|
30 | if [[ "${WEBAPP_OPTIONAL}" != "yes" ]]; then |
|
|
31 | [[ "${WEBAPP_NO_AUTO_INSTALL}" == "yes" ]] || IUSE="vhosts" |
| 13 | SLOT="${PVR}" |
32 | SLOT="${PVR}" |
| 14 | IUSE="vhosts" |
33 | DEPEND="${WEBAPP_DEPEND}" |
| 15 | DEPEND=">=app-admin/webapp-config-1.50.15" |
|
|
| 16 | RDEPEND="${DEPEND}" |
34 | RDEPEND="${DEPEND}" |
|
|
35 | fi |
| 17 | |
36 | |
| 18 | EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm |
37 | EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm |
| 19 | |
38 | |
| 20 | INSTALL_DIR="/${PN}" |
39 | INSTALL_DIR="/${PN}" |
| 21 | IS_UPGRADE=0 |
40 | IS_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 | |
| 82 | webapp_getinstalltype() { |
106 | webapp_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. |
|
|
156 | need_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. |
|
|
165 | need_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. |
|
|
174 | need_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. |
| 272 | webapp_src_preinst() { |
333 | webapp_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 |
| … | |
… | |
| 332 | ewarn "compatible with webapp-config." |
411 | ewarn "compatible with webapp-config." |
| 333 | ewarn |
412 | ewarn |
| 334 | ewarn "This ebuild may be overwriting important files." |
413 | ewarn "This ebuild may be overwriting important files." |
| 335 | ewarn |
414 | ewarn |
| 336 | echo |
415 | echo |
|
|
416 | if has "${EAPI:-0}" 0 1 2; then |
| 337 | ebeep 10 |
417 | ebeep 10 |
|
|
418 | fi |
| 338 | elif [[ "$(echo ${my_output} | awk '{ print $1 }')" != "${PN}" ]]; then |
419 | elif [[ "$(echo ${my_output} | awk '{ print $1 }')" != "${PN}" ]]; then |
| 339 | echo |
420 | echo |
| 340 | eerror "You already have ${my_output} installed in ${my_dir}" |
421 | eerror "You already have ${my_output} installed in ${my_dir}" |
| 341 | eerror |
422 | eerror |
| 342 | eerror "I cannot upgrade a different application" |
423 | eerror "I cannot upgrade a different application" |
| … | |
… | |
| 363 | # we used to just set a variable in the shell script, but we can |
444 | # 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 |
445 | # no longer rely on Portage calling both webapp_src_install() and |
| 365 | # webapp_pkg_postinst() within the same shell process |
446 | # webapp_pkg_postinst() within the same shell process |
| 366 | touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}" |
447 | touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}" |
| 367 | |
448 | |
| 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}/" |
449 | chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/" |
| 383 | chmod -R u-s "${D}/" |
450 | chmod -R u-s "${D}/" |
| 384 | chmod -R g-s "${D}/" |
451 | chmod -R g-s "${D}/" |
| 385 | |
452 | |
| 386 | keepdir "${MY_PERSISTDIR}" |
453 | keepdir "${MY_PERSISTDIR}" |
| … | |
… | |
| 413 | eerror "installation is incomplete" |
480 | eerror "installation is incomplete" |
| 414 | eerror |
481 | eerror |
| 415 | die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org" |
482 | die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org" |
| 416 | fi |
483 | fi |
| 417 | |
484 | |
|
|
485 | if has vhosts ${IUSE}; then |
| 418 | if ! use vhosts; then |
486 | if ! use vhosts; then |
| 419 | echo |
487 | echo |
| 420 | elog "vhosts USE flag not set - auto-installing using webapp-config" |
488 | elog "vhosts USE flag not set - auto-installing using webapp-config" |
| 421 | |
489 | |
| 422 | G_HOSTNAME="localhost" |
490 | G_HOSTNAME="localhost" |
| 423 | webapp_read_config |
491 | webapp_read_config |
| 424 | |
492 | |
| 425 | local my_mode=-I |
493 | local my_mode=-I |
| 426 | webapp_getinstalltype |
494 | webapp_getinstalltype |
| 427 | |
495 | |
| 428 | if [[ "${IS_REPLACE}" == "1" ]]; then |
496 | if [[ "${IS_REPLACE}" == "1" ]]; then |
| 429 | elog "${PN}-${PVR} is already installed - replacing" |
497 | elog "${PN}-${PVR} is already installed - replacing" |
| 430 | my_mode=-I |
498 | my_mode=-I |
| 431 | elif [[ "${IS_UPGRADE}" == "1" ]]; then |
499 | elif [[ "${IS_UPGRADE}" == "1" ]]; then |
| 432 | elog "${REMOVE_PKG} is already installed - upgrading" |
500 | elog "${REMOVE_PKG} is already installed - upgrading" |
| 433 | my_mode=-U |
501 | my_mode=-U |
|
|
502 | else |
|
|
503 | elog "${PN}-${PVR} is not installed - using install mode" |
|
|
504 | fi |
|
|
505 | |
|
|
506 | my_cmd="${WEBAPP_CONFIG} ${my_mode} -h localhost -u root -d ${INSTALL_DIR} ${PN} ${PVR}" |
|
|
507 | elog "Running ${my_cmd}" |
|
|
508 | ${my_cmd} |
|
|
509 | |
|
|
510 | echo |
|
|
511 | local cleaner="${WEBAPP_CLEANER} -p -C /${PN}" |
|
|
512 | einfo "Running ${cleaner}" |
|
|
513 | ${cleaner} |
| 434 | else |
514 | else |
| 435 | elog "${PN}-${PVR} is not installed - using install mode" |
515 | elog |
|
|
516 | elog "The 'vhosts' USE flag is switched ON" |
|
|
517 | elog "This means that Portage will not automatically run webapp-config to" |
|
|
518 | elog "complete the installation." |
|
|
519 | elog |
|
|
520 | elog "To install ${PN}-${PVR} into a virtual host, run the following command:" |
|
|
521 | elog |
|
|
522 | elog " webapp-config -I -h <host> -d ${PN} ${PN} ${PVR}" |
|
|
523 | elog |
|
|
524 | elog "For more details, see the webapp-config(8) man page" |
| 436 | fi |
525 | 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 |
526 | else |
| 447 | elog |
527 | elog |
| 448 | elog "The 'vhosts' USE flag is switched ON" |
528 | elog "This ebuild does not support the 'vhosts' USE flag." |
| 449 | elog "This means that Portage will not automatically run webapp-config to" |
529 | elog "This means that Portage will not automatically run webapp-config to" |
| 450 | elog "complete the installation." |
530 | elog "complete the installation." |
| 451 | elog |
531 | elog |
| 452 | elog "To install ${PN}-${PVR} into a virtual host, run the following command:" |
532 | elog "To install ${PN}-${PVR} into a virtual host, run the following command:" |
| 453 | elog |
533 | elog |
| … | |
… | |
| 468 | local my_output= |
548 | local my_output= |
| 469 | my_output="$(${WEBAPP_CONFIG} --list-installs ${PN} ${PVR})" |
549 | my_output="$(${WEBAPP_CONFIG} --list-installs ${PN} ${PVR})" |
| 470 | [[ $? -ne 0 ]] && return |
550 | [[ $? -ne 0 ]] && return |
| 471 | |
551 | |
| 472 | local x |
552 | local x |
| 473 | if ! use vhosts; then |
553 | if has vhosts ${IUSE} && ! use vhosts; then |
| 474 | echo "${my_output}" | while read x; do |
554 | echo "${my_output}" | while read x; do |
| 475 | if [[ -f "${x}"/.webapp ]]; then |
555 | if [[ -f "${x}"/.webapp ]]; then |
| 476 | . "${x}"/.webapp |
556 | . "${x}"/.webapp |
| 477 | if [[ -n "${WEB_HOSTNAME}" && -n "${WEB_INSTALLDIR}" ]]; then |
557 | if [[ -n "${WEB_HOSTNAME}" && -n "${WEB_INSTALLDIR}" ]]; then |
| 478 | ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR} |
558 | ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR} ${PN} ${PVR} |
| 479 | fi |
559 | fi |
| 480 | else |
560 | else |
| 481 | ewarn "Cannot find file ${x}/.webapp" |
561 | ewarn "Cannot find file ${x}/.webapp" |
| 482 | fi |
562 | fi |
| 483 | done |
563 | done |