| 1 | # Copyright 1999-2006 Gentoo Foundation |
1 | # Copyright 1999-2006 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.56 2008/02/22 14:44:16 hollow Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.66 2011/05/19 12:05:13 scarabeus 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 |
| 22 | IS_REPLACE=0 |
41 | IS_REPLACE=0 |
| 23 | |
42 | |
| 24 | INSTALL_CHECK_FILE="installed_by_webapp_eclass" |
43 | INSTALL_CHECK_FILE="installed_by_webapp_eclass" |
|
|
44 | SETUP_CHECK_FILE="setup_by_webapp_eclass" |
| 25 | |
45 | |
| 26 | ETC_CONFIG="${ROOT}etc/vhosts/webapp-config" |
46 | ETC_CONFIG="${ROOT}etc/vhosts/webapp-config" |
| 27 | WEBAPP_CONFIG="${ROOT}usr/sbin/webapp-config" |
47 | WEBAPP_CONFIG="${ROOT}usr/sbin/webapp-config" |
| 28 | WEBAPP_CLEANER="${ROOT}usr/sbin/webapp-cleaner" |
48 | WEBAPP_CLEANER="${ROOT}usr/sbin/webapp-cleaner" |
| 29 | |
49 | |
| … | |
… | |
| 78 | echo "${1/#.\///}" |
98 | echo "${1/#.\///}" |
| 79 | } |
99 | } |
| 80 | |
100 | |
| 81 | webapp_getinstalltype() { |
101 | webapp_getinstalltype() { |
| 82 | debug-print-function $FUNCNAME $* |
102 | debug-print-function $FUNCNAME $* |
| 83 | use vhosts && return |
103 | |
|
|
104 | if ! has vhosts ${IUSE} || use vhosts; then |
|
|
105 | return |
|
|
106 | fi |
| 84 | |
107 | |
| 85 | local my_output |
108 | local my_output |
| 86 | my_output="$(webapp_check_installedat)" |
109 | my_output="$(webapp_check_installedat)" |
| 87 | |
110 | |
| 88 | if [[ $? -eq 0 ]]; then |
111 | if [[ $? -eq 0 ]]; then |
| … | |
… | |
| 112 | |
135 | |
| 113 | # ============================================================================== |
136 | # ============================================================================== |
| 114 | # PUBLIC FUNCTIONS |
137 | # PUBLIC FUNCTIONS |
| 115 | # ============================================================================== |
138 | # ============================================================================== |
| 116 | |
139 | |
|
|
140 | # @FUNCTION: need_httpd |
|
|
141 | # @DESCRIPTION: |
|
|
142 | # Call this function AFTER your ebuilds DEPEND line if any of the available |
|
|
143 | # webservers are able to run this application. |
|
|
144 | need_httpd() { |
|
|
145 | DEPEND="${DEPEND} |
|
|
146 | || ( virtual/httpd-basic virtual/httpd-cgi virtual/httpd-fastcgi )" |
|
|
147 | } |
|
|
148 | |
|
|
149 | # @FUNCTION: need_httpd_cgi |
|
|
150 | # @DESCRIPTION: |
|
|
151 | # Call this function AFTER your ebuilds DEPEND line if any of the available |
|
|
152 | # CGI-capable webservers are able to run this application. |
|
|
153 | need_httpd_cgi() { |
|
|
154 | DEPEND="${DEPEND} |
|
|
155 | || ( virtual/httpd-cgi virtual/httpd-fastcgi )" |
|
|
156 | } |
|
|
157 | |
|
|
158 | # @FUNCTION: need_httpd_fastcgi |
|
|
159 | # @DESCRIPTION: |
|
|
160 | # Call this function AFTER your ebuilds DEPEND line if any of the available |
|
|
161 | # FastCGI-capabale webservers are able to run this application. |
|
|
162 | need_httpd_fastcgi() { |
|
|
163 | DEPEND="${DEPEND} |
|
|
164 | virtual/httpd-fastcgi" |
|
|
165 | } |
|
|
166 | |
| 117 | # @FUNCTION: webapp_configfile |
167 | # @FUNCTION: webapp_configfile |
| 118 | # @USAGE: <file> [more files ...] |
168 | # @USAGE: <file> [more files ...] |
| 119 | # @DESCRIPTION: |
169 | # @DESCRIPTION: |
| 120 | # Mark a file config-protected for a web-based application. |
170 | # Mark a file config-protected for a web-based application. |
| 121 | webapp_configfile() { |
171 | webapp_configfile() { |
| … | |
… | |
| 269 | # You need to call this function in src_install() BEFORE anything else has run. |
319 | # You need to call this function in src_install() BEFORE anything else has run. |
| 270 | # For now we just create required webapp-config directories. |
320 | # For now we just create required webapp-config directories. |
| 271 | webapp_src_preinst() { |
321 | webapp_src_preinst() { |
| 272 | debug-print-function $FUNCNAME $* |
322 | debug-print-function $FUNCNAME $* |
| 273 | |
323 | |
|
|
324 | # sanity checks, to catch bugs in the ebuild |
|
|
325 | if [[ ! -f "${T}/${SETUP_CHECK_FILE}" ]]; then |
|
|
326 | eerror |
|
|
327 | eerror "This ebuild did not call webapp_pkg_setup() at the beginning" |
|
|
328 | eerror "of the pkg_setup() function" |
|
|
329 | eerror |
|
|
330 | eerror "Please log a bug on http://bugs.gentoo.org" |
|
|
331 | eerror |
|
|
332 | eerror "You should use emerge -C to remove this package, as the" |
|
|
333 | eerror "installation is incomplete" |
|
|
334 | eerror |
|
|
335 | die "Ebuild did not call webapp_pkg_setup() - report to http://bugs.gentoo.org" |
|
|
336 | fi |
|
|
337 | |
|
|
338 | # Hint, see the webapp_read_config() function to find where these are |
|
|
339 | # defined. |
| 274 | dodir "${MY_HTDOCSDIR}" |
340 | dodir "${MY_HTDOCSDIR}" |
| 275 | dodir "${MY_HOSTROOTDIR}" |
341 | dodir "${MY_HOSTROOTDIR}" |
| 276 | dodir "${MY_CGIBINDIR}" |
342 | dodir "${MY_CGIBINDIR}" |
| 277 | dodir "${MY_ICONSDIR}" |
343 | dodir "${MY_ICONSDIR}" |
| 278 | dodir "${MY_ERRORSDIR}" |
344 | dodir "${MY_ERRORSDIR}" |
| … | |
… | |
| 283 | |
349 | |
| 284 | # ============================================================================== |
350 | # ============================================================================== |
| 285 | # EXPORTED FUNCTIONS |
351 | # EXPORTED FUNCTIONS |
| 286 | # ============================================================================== |
352 | # ============================================================================== |
| 287 | |
353 | |
| 288 | # @FUNCTION: webapp_src_install |
|
|
| 289 | # @DESCRIPTION: |
|
|
| 290 | # This is the default src_install(). For now, we just make sure that root owns |
|
|
| 291 | # everything, and that there are no setuid files. |
|
|
| 292 | # |
|
|
| 293 | # You need to call this function AFTER everything else has run in your custom |
|
|
| 294 | # src_install(). |
|
|
| 295 | webapp_src_install() { |
|
|
| 296 | debug-print-function $FUNCNAME $* |
|
|
| 297 | |
|
|
| 298 | chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/" |
|
|
| 299 | chmod -R u-s "${D}/" |
|
|
| 300 | chmod -R g-s "${D}/" |
|
|
| 301 | |
|
|
| 302 | keepdir "${MY_PERSISTDIR}" |
|
|
| 303 | fowners "root:0" "${MY_PERSISTDIR}" |
|
|
| 304 | fperms 755 "${MY_PERSISTDIR}" |
|
|
| 305 | |
|
|
| 306 | # to test whether or not the ebuild has correctly called this function |
|
|
| 307 | # we add an empty file to the filesystem |
|
|
| 308 | # |
|
|
| 309 | # we used to just set a variable in the shell script, but we can |
|
|
| 310 | # no longer rely on Portage calling both webapp_src_install() and |
|
|
| 311 | # webapp_pkg_postinst() within the same shell process |
|
|
| 312 | |
|
|
| 313 | touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}" |
|
|
| 314 | } |
|
|
| 315 | |
|
|
| 316 | # @FUNCTION: webapp_pkg_setup |
354 | # @FUNCTION: webapp_pkg_setup |
| 317 | # @DESCRIPTION: |
355 | # @DESCRIPTION: |
| 318 | # The default pkg_setup() for this eclass. This will gather required variables |
356 | # The default pkg_setup() for this eclass. This will gather required variables |
| 319 | # from webapp-config and check if there is an application installed to |
357 | # from webapp-config and check if there is an application installed to |
| 320 | # `${ROOT}/var/www/localhost/htdocs/${PN}/' if USE=vhosts is not set. |
358 | # `${ROOT}/var/www/localhost/htdocs/${PN}/' if USE=vhosts is not set. |
| … | |
… | |
| 322 | # You need to call this function BEFORE anything else has run in your custom |
360 | # You need to call this function BEFORE anything else has run in your custom |
| 323 | # pkg_setup(). |
361 | # pkg_setup(). |
| 324 | webapp_pkg_setup() { |
362 | webapp_pkg_setup() { |
| 325 | debug-print-function $FUNCNAME $* |
363 | debug-print-function $FUNCNAME $* |
| 326 | |
364 | |
|
|
365 | # to test whether or not the ebuild has correctly called this function |
|
|
366 | # we add an empty file to the filesystem |
|
|
367 | # |
|
|
368 | # we used to just set a variable in the shell script, but we can |
|
|
369 | # no longer rely on Portage calling both webapp_pkg_setup() and |
|
|
370 | # webapp_src_install() within the same shell process |
|
|
371 | touch "${T}/${SETUP_CHECK_FILE}" |
|
|
372 | |
| 327 | # special case - some ebuilds *do* need to overwride the SLOT |
373 | # special case - some ebuilds *do* need to overwride the SLOT |
| 328 | if [[ "${SLOT}+" != "${PVR}+" && "${WEBAPP_MANUAL_SLOT}" != "yes" ]]; then |
374 | if [[ "${SLOT}+" != "${PVR}+" && "${WEBAPP_MANUAL_SLOT}" != "yes" ]]; then |
| 329 | die "Set WEBAPP_MANUAL_SLOT=\"yes\" if you need to SLOT manually" |
375 | die "Set WEBAPP_MANUAL_SLOT=\"yes\" if you need to SLOT manually" |
| 330 | fi |
376 | fi |
| 331 | |
377 | |
| … | |
… | |
| 334 | webapp_read_config |
380 | webapp_read_config |
| 335 | |
381 | |
| 336 | local my_dir="${ROOT}${VHOST_ROOT}/${MY_HTDOCSBASE}/${PN}" |
382 | local my_dir="${ROOT}${VHOST_ROOT}/${MY_HTDOCSBASE}/${PN}" |
| 337 | |
383 | |
| 338 | # if USE=vhosts is enabled OR no application is installed we're done here |
384 | # if USE=vhosts is enabled OR no application is installed we're done here |
| 339 | use vhosts || [[ ! -d "${my_dir}" ]] && return |
385 | if ! has vhosts ${IUSE} || use vhosts || [[ ! -d "${my_dir}" ]]; then |
|
|
386 | return |
|
|
387 | fi |
| 340 | |
388 | |
| 341 | local my_output |
389 | local my_output |
| 342 | my_output="$(webapp_check_installedat)" |
390 | my_output="$(webapp_check_installedat)" |
| 343 | |
391 | |
| 344 | if [[ $? -ne 0 ]]; then |
392 | if [[ $? -ne 0 ]]; then |
| … | |
… | |
| 361 | eerror "I cannot upgrade a different application" |
409 | eerror "I cannot upgrade a different application" |
| 362 | eerror |
410 | eerror |
| 363 | echo |
411 | echo |
| 364 | die "Cannot upgrade contents of ${my_dir}" |
412 | die "Cannot upgrade contents of ${my_dir}" |
| 365 | fi |
413 | fi |
|
|
414 | |
|
|
415 | } |
|
|
416 | |
|
|
417 | # @FUNCTION: webapp_src_install |
|
|
418 | # @DESCRIPTION: |
|
|
419 | # This is the default src_install(). For now, we just make sure that root owns |
|
|
420 | # everything, and that there are no setuid files. |
|
|
421 | # |
|
|
422 | # You need to call this function AFTER everything else has run in your custom |
|
|
423 | # src_install(). |
|
|
424 | webapp_src_install() { |
|
|
425 | debug-print-function $FUNCNAME $* |
|
|
426 | |
|
|
427 | # to test whether or not the ebuild has correctly called this function |
|
|
428 | # we add an empty file to the filesystem |
|
|
429 | # |
|
|
430 | # we used to just set a variable in the shell script, but we can |
|
|
431 | # no longer rely on Portage calling both webapp_src_install() and |
|
|
432 | # webapp_pkg_postinst() within the same shell process |
|
|
433 | touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}" |
|
|
434 | |
|
|
435 | chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/" |
|
|
436 | chmod -R u-s "${D}/" |
|
|
437 | chmod -R g-s "${D}/" |
|
|
438 | |
|
|
439 | keepdir "${MY_PERSISTDIR}" |
|
|
440 | fowners "root:0" "${MY_PERSISTDIR}" |
|
|
441 | fperms 755 "${MY_PERSISTDIR}" |
| 366 | } |
442 | } |
| 367 | |
443 | |
| 368 | # @FUNCTION: webapp_pkg_postinst |
444 | # @FUNCTION: webapp_pkg_postinst |
| 369 | # @DESCRIPTION: |
445 | # @DESCRIPTION: |
| 370 | # The default pkg_postinst() for this eclass. This installs the web application to |
446 | # The default pkg_postinst() for this eclass. This installs the web application to |
| … | |
… | |
| 390 | eerror "installation is incomplete" |
466 | eerror "installation is incomplete" |
| 391 | eerror |
467 | eerror |
| 392 | die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org" |
468 | die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org" |
| 393 | fi |
469 | fi |
| 394 | |
470 | |
|
|
471 | if has vhosts ${IUSE}; then |
| 395 | if ! use vhosts; then |
472 | if ! use vhosts; then |
| 396 | echo |
473 | echo |
| 397 | elog "vhosts USE flag not set - auto-installing using webapp-config" |
474 | elog "vhosts USE flag not set - auto-installing using webapp-config" |
| 398 | |
475 | |
| 399 | G_HOSTNAME="localhost" |
476 | G_HOSTNAME="localhost" |
| 400 | webapp_read_config |
477 | webapp_read_config |
| 401 | |
478 | |
| 402 | local my_mode=-I |
479 | local my_mode=-I |
| 403 | webapp_getinstalltype |
480 | webapp_getinstalltype |
| 404 | |
481 | |
| 405 | if [[ "${IS_REPLACE}" == "1" ]]; then |
482 | if [[ "${IS_REPLACE}" == "1" ]]; then |
| 406 | elog "${PN}-${PVR} is already installed - replacing" |
483 | elog "${PN}-${PVR} is already installed - replacing" |
| 407 | my_mode=-I |
484 | my_mode=-I |
| 408 | elif [[ "${IS_UPGRADE}" == "1" ]]; then |
485 | elif [[ "${IS_UPGRADE}" == "1" ]]; then |
| 409 | elog "${REMOVE_PKG} is already installed - upgrading" |
486 | elog "${REMOVE_PKG} is already installed - upgrading" |
| 410 | my_mode=-U |
487 | my_mode=-U |
|
|
488 | else |
|
|
489 | elog "${PN}-${PVR} is not installed - using install mode" |
|
|
490 | fi |
|
|
491 | |
|
|
492 | my_cmd="${WEBAPP_CONFIG} ${my_mode} -h localhost -u root -d ${INSTALL_DIR} ${PN} ${PVR}" |
|
|
493 | elog "Running ${my_cmd}" |
|
|
494 | ${my_cmd} |
|
|
495 | |
|
|
496 | echo |
|
|
497 | local cleaner="${WEBAPP_CLEANER} -p -C ${PN}" |
|
|
498 | einfo "Running ${cleaner}" |
|
|
499 | ${cleaner} |
| 411 | else |
500 | else |
| 412 | elog "${PN}-${PVR} is not installed - using install mode" |
501 | elog |
|
|
502 | elog "The 'vhosts' USE flag is switched ON" |
|
|
503 | elog "This means that Portage will not automatically run webapp-config to" |
|
|
504 | elog "complete the installation." |
|
|
505 | elog |
|
|
506 | elog "To install ${PN}-${PVR} into a virtual host, run the following command:" |
|
|
507 | elog |
|
|
508 | elog " webapp-config -I -h <host> -d ${PN} ${PN} ${PVR}" |
|
|
509 | elog |
|
|
510 | elog "For more details, see the webapp-config(8) man page" |
| 413 | fi |
511 | fi |
| 414 | |
|
|
| 415 | my_cmd="${WEBAPP_CONFIG} ${my_mode} -h localhost -u root -d ${INSTALL_DIR} ${PN} ${PVR}" |
|
|
| 416 | elog "Running ${my_cmd}" |
|
|
| 417 | ${my_cmd} |
|
|
| 418 | |
|
|
| 419 | echo |
|
|
| 420 | local cleaner="${WEBAPP_CLEANER} -p -C ${PN}" |
|
|
| 421 | einfo "Running ${cleaner}" |
|
|
| 422 | ${cleaner} |
|
|
| 423 | else |
512 | else |
| 424 | elog |
513 | elog |
| 425 | elog "The 'vhosts' USE flag is switched ON" |
514 | elog "This ebuild does not support the 'vhosts' USE flag." |
| 426 | elog "This means that Portage will not automatically run webapp-config to" |
515 | elog "This means that Portage will not automatically run webapp-config to" |
| 427 | elog "complete the installation." |
516 | elog "complete the installation." |
| 428 | elog |
517 | elog |
| 429 | elog "To install ${PN}-${PVR} into a virtual host, run the following command:" |
518 | elog "To install ${PN}-${PVR} into a virtual host, run the following command:" |
| 430 | elog |
519 | elog |
| … | |
… | |
| 445 | local my_output= |
534 | local my_output= |
| 446 | my_output="$(${WEBAPP_CONFIG} --list-installs ${PN} ${PVR})" |
535 | my_output="$(${WEBAPP_CONFIG} --list-installs ${PN} ${PVR})" |
| 447 | [[ $? -ne 0 ]] && return |
536 | [[ $? -ne 0 ]] && return |
| 448 | |
537 | |
| 449 | local x |
538 | local x |
| 450 | if ! use vhosts; then |
539 | if has vhosts ${IUSE} && ! use vhosts; then |
| 451 | echo "${my_output}" | while read x; do |
540 | echo "${my_output}" | while read x; do |
| 452 | if [[ -f "${x}"/.webapp ]]; then |
541 | if [[ -f "${x}"/.webapp ]]; then |
| 453 | . "${x}"/.webapp |
542 | . "${x}"/.webapp |
| 454 | if [[ -n "${WEB_HOSTNAME}" && -n "${WEB_INSTALLDIR}" ]]; then |
543 | if [[ -n "${WEB_HOSTNAME}" && -n "${WEB_INSTALLDIR}" ]]; then |
| 455 | ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR} |
544 | ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR} |