| 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.52 2008/02/22 13:53:38 hollow Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.53 2008/02/22 14:06:05 hollow 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 |
| … | |
… | |
| 48 | webapp_checkfileexists() { |
48 | webapp_checkfileexists() { |
| 49 | debug-print-function $FUNCNAME $* |
49 | debug-print-function $FUNCNAME $* |
| 50 | |
50 | |
| 51 | local my_prefix=${2:+${2}/} |
51 | local my_prefix=${2:+${2}/} |
| 52 | |
52 | |
| 53 | if [ ! -e "${my_prefix}${1}" ]; then |
53 | if [[ ! -e "${my_prefix}${1}" ]]; then |
| 54 | msg="ebuild fault: file '${1}' not found" |
54 | msg="ebuild fault: file '${1}' not found" |
| 55 | eerror "$msg" |
55 | eerror "$msg" |
| 56 | eerror "Please report this as a bug at http://bugs.gentoo.org/" |
56 | eerror "Please report this as a bug at http://bugs.gentoo.org/" |
| 57 | die "$msg" |
57 | die "$msg" |
| 58 | fi |
58 | fi |
| … | |
… | |
| 79 | } |
79 | } |
| 80 | |
80 | |
| 81 | webapp_getinstalltype() { |
81 | webapp_getinstalltype() { |
| 82 | debug-print-function $FUNCNAME $* |
82 | debug-print-function $FUNCNAME $* |
| 83 | |
83 | |
| 84 | if ! use vhosts ; then |
84 | if ! use vhosts; then |
| 85 | local my_output |
85 | local my_output |
| 86 | |
86 | |
| 87 | my_output="$(webapp_check_installedat)" |
87 | my_output="$(webapp_check_installedat)" |
| 88 | |
88 | |
| 89 | if [ "${?}" = "0" ] ; then |
89 | if [[ $? -eq 0 ]]; then |
| 90 | # something is already installed there |
90 | # something is already installed there |
| 91 | # make sure it isn't the same version |
91 | # make sure it isn't the same version |
| 92 | |
92 | |
| 93 | local my_pn="$(echo ${my_output} | awk '{ print $1 }')" |
93 | local my_pn="$(echo ${my_output} | awk '{ print $1 }')" |
| 94 | local my_pvr="$(echo ${my_output} | awk '{ print $2 }')" |
94 | local my_pvr="$(echo ${my_output} | awk '{ print $2 }')" |
| 95 | |
95 | |
| 96 | REMOVE_PKG="${my_pn}-${my_pvr}" |
96 | REMOVE_PKG="${my_pn}-${my_pvr}" |
| 97 | |
97 | |
| 98 | if [ "${my_pn}" == "${PN}" ]; then |
98 | if [[ "${my_pn}" == "${PN}" ]]; then |
| 99 | if [ "${my_pvr}" != "${PVR}" ]; then |
99 | if [[ "${my_pvr}" != "${PVR}" ]]; then |
| 100 | elog "This is an upgrade" |
100 | elog "This is an upgrade" |
| 101 | IS_UPGRADE=1 |
101 | IS_UPGRADE=1 |
| 102 | else |
102 | else |
| 103 | elog "This is a re-installation" |
103 | elog "This is a re-installation" |
| 104 | IS_REPLACE=1 |
104 | IS_REPLACE=1 |
| … | |
… | |
| 122 | # Mark a file config-protected for a web-based application. |
122 | # Mark a file config-protected for a web-based application. |
| 123 | webapp_configfile() { |
123 | webapp_configfile() { |
| 124 | debug-print-function $FUNCNAME $* |
124 | debug-print-function $FUNCNAME $* |
| 125 | |
125 | |
| 126 | local m="" |
126 | local m="" |
| 127 | for m in "$@" ; do |
127 | for m in "$@"; do |
| 128 | webapp_checkfileexists "${m}" "${D}" |
128 | webapp_checkfileexists "${m}" "${D}" |
| 129 | |
129 | |
| 130 | local MY_FILE="$(webapp_strip_appdir "${m}")" |
130 | local MY_FILE="$(webapp_strip_appdir "${m}")" |
| 131 | MY_FILE="$(webapp_strip_cwd "${MY_FILE}")" |
131 | MY_FILE="$(webapp_strip_cwd "${MY_FILE}")" |
| 132 | |
132 | |
| … | |
… | |
| 185 | webapp_serverowned() { |
185 | webapp_serverowned() { |
| 186 | debug-print-function $FUNCNAME $* |
186 | debug-print-function $FUNCNAME $* |
| 187 | |
187 | |
| 188 | local a="" |
188 | local a="" |
| 189 | local m="" |
189 | local m="" |
| 190 | if [ "${1}" = "-R" ]; then |
190 | if [[ "${1}" == "-R" ]]; then |
| 191 | shift |
191 | shift |
| 192 | for m in "$@" ; do |
192 | for m in "$@"; do |
| 193 | for a in $(find ${D}/${m}); do |
193 | for a in $(find ${D}/${m}); do |
| 194 | a=${a/${D}\/\///} |
194 | a=${a/${D}\/\///} |
| 195 | webapp_checkfileexists "${a}" "$D" |
195 | webapp_checkfileexists "${a}" "$D" |
| 196 | local MY_FILE="$(webapp_strip_appdir "${a}")" |
196 | local MY_FILE="$(webapp_strip_appdir "${a}")" |
| 197 | MY_FILE="$(webapp_strip_cwd "${MY_FILE}")" |
197 | MY_FILE="$(webapp_strip_cwd "${MY_FILE}")" |
| … | |
… | |
| 199 | elog "(server owned) ${MY_FILE}" |
199 | elog "(server owned) ${MY_FILE}" |
| 200 | echo "${MY_FILE}" >> "${D}/${WA_SOLIST}" |
200 | echo "${MY_FILE}" >> "${D}/${WA_SOLIST}" |
| 201 | done |
201 | done |
| 202 | done |
202 | done |
| 203 | else |
203 | else |
| 204 | for m in "$@" ; do |
204 | for m in "$@"; do |
| 205 | webapp_checkfileexists "${m}" "$D" |
205 | webapp_checkfileexists "${m}" "$D" |
| 206 | local MY_FILE="$(webapp_strip_appdir "${m}")" |
206 | local MY_FILE="$(webapp_strip_appdir "${m}")" |
| 207 | MY_FILE="$(webapp_strip_cwd "${MY_FILE}")" |
207 | MY_FILE="$(webapp_strip_cwd "${MY_FILE}")" |
| 208 | |
208 | |
| 209 | elog "(server owned) ${MY_FILE}" |
209 | elog "(server owned) ${MY_FILE}" |
| … | |
… | |
| 245 | webapp_sqlscript() { |
245 | webapp_sqlscript() { |
| 246 | debug-print-function $FUNCNAME $* |
246 | debug-print-function $FUNCNAME $* |
| 247 | |
247 | |
| 248 | webapp_checkfileexists "${2}" |
248 | webapp_checkfileexists "${2}" |
| 249 | |
249 | |
| 250 | if [ ! -d "${D}/${MY_SQLSCRIPTSDIR}/${1}" ]; then |
250 | if [[ ! -d "${D}/${MY_SQLSCRIPTSDIR}/${1}" ]]; then |
| 251 | mkdir -p "${D}/${MY_SQLSCRIPTSDIR}/${1}" || die "unable to create directory ${D}/${MY_SQLSCRIPTSDIR}/${1}" |
251 | mkdir -p "${D}/${MY_SQLSCRIPTSDIR}/${1}" || die "unable to create directory ${D}/${MY_SQLSCRIPTSDIR}/${1}" |
| 252 | fi |
252 | fi |
| 253 | |
253 | |
| 254 | # WARNING: |
254 | # WARNING: |
| 255 | # |
255 | # |
| 256 | # do NOT change the naming convention used here without changing all |
256 | # do NOT change the naming convention used here without changing all |
| 257 | # the other scripts that also rely upon these names |
257 | # the other scripts that also rely upon these names |
| 258 | |
258 | |
| 259 | if [ -n "${3}" ]; then |
259 | if [[ -n "${3}" ]]; then |
| 260 | elog "(${1}) upgrade script from ${PN}-${PVR} to ${3}" |
260 | elog "(${1}) upgrade script for ${PN}-${3} to ${PVR}" |
| 261 | cp "${2}" "${D}${MY_SQLSCRIPTSDIR}/${1}/${3}_to_${PVR}.sql" |
261 | cp "${2}" "${D}${MY_SQLSCRIPTSDIR}/${1}/${3}_to_${PVR}.sql" |
| 262 | chmod 600 "${D}${MY_SQLSCRIPTSDIR}/${1}/${3}_to_${PVR}.sql" |
262 | chmod 600 "${D}${MY_SQLSCRIPTSDIR}/${1}/${3}_to_${PVR}.sql" |
| 263 | else |
263 | else |
| 264 | elog "(${1}) create script for ${PN}-${PVR}" |
264 | elog "(${1}) create script for ${PN}-${PVR}" |
| 265 | cp "${2}" "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql" |
265 | cp "${2}" "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql" |
| … | |
… | |
| 336 | G_HOSTNAME="localhost" |
336 | G_HOSTNAME="localhost" |
| 337 | webapp_read_config |
337 | webapp_read_config |
| 338 | |
338 | |
| 339 | # are we installing a webapp-config solution over the top of a |
339 | # are we installing a webapp-config solution over the top of a |
| 340 | # non-webapp-config solution? |
340 | # non-webapp-config solution? |
| 341 | if ! use vhosts ; then |
341 | if ! use vhosts; then |
| 342 | local my_dir="${ROOT}${VHOST_ROOT}/${MY_HTDOCSBASE}/${PN}" |
342 | local my_dir="${ROOT}${VHOST_ROOT}/${MY_HTDOCSBASE}/${PN}" |
| 343 | local my_output |
343 | local my_output |
| 344 | |
344 | |
| 345 | if [ -d "${my_dir}" ] ; then |
345 | if [[ -d "${my_dir}" ]]; then |
| 346 | my_output="$(webapp_check_installedat)" |
346 | my_output="$(webapp_check_installedat)" |
| 347 | |
347 | |
| 348 | if [ "$?" != "0" ]; then |
348 | if [[ $? -ne 0 ]]; then |
| 349 | # okay, whatever is there, it isn't webapp-config-compatible |
349 | # okay, whatever is there, it isn't webapp-config-compatible |
| 350 | ewarn "You already have something installed in ${my_dir}" |
350 | ewarn "You already have something installed in ${my_dir}" |
| 351 | ewarn |
351 | ewarn |
| 352 | ewarn "Whatever is in ${my_dir}, it's not" |
352 | ewarn "Whatever is in ${my_dir}, it's not" |
| 353 | ewarn "compatible with webapp-config." |
353 | ewarn "compatible with webapp-config." |
| 354 | ewarn |
354 | ewarn |
| 355 | ewarn "This ebuild may be overwriting important files." |
355 | ewarn "This ebuild may be overwriting important files." |
| 356 | ewarn |
356 | ewarn |
| 357 | elif [ "$(echo ${my_output} | awk '{ print $1 }')" != "${PN}" ]; then |
357 | elif [[ "$(echo ${my_output} | awk '{ print $1 }')" != "${PN}" ]]; then |
| 358 | eerror "${my_dir} contains ${my_output}" |
358 | eerror "${my_dir} contains ${my_output}" |
| 359 | eerror "I cannot upgrade that" |
359 | eerror "I cannot upgrade that" |
| 360 | die "Cannot upgrade contents of ${my_dir}" |
360 | die "Cannot upgrade contents of ${my_dir}" |
| 361 | fi |
361 | fi |
| 362 | fi |
362 | fi |
| … | |
… | |
| 375 | debug-print-function $FUNCNAME $* |
375 | debug-print-function $FUNCNAME $* |
| 376 | |
376 | |
| 377 | webapp_read_config |
377 | webapp_read_config |
| 378 | |
378 | |
| 379 | # sanity checks, to catch bugs in the ebuild |
379 | # sanity checks, to catch bugs in the ebuild |
| 380 | if [ ! -f "${ROOT}${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]; then |
380 | if [[ ! -f "${ROOT}${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]]; then |
| 381 | eerror |
381 | eerror |
| 382 | eerror "This ebuild did not call webapp_src_install() at the end" |
382 | eerror "This ebuild did not call webapp_src_install() at the end" |
| 383 | eerror "of the src_install() function" |
383 | eerror "of the src_install() function" |
| 384 | eerror |
384 | eerror |
| 385 | eerror "Please log a bug on http://bugs.gentoo.org" |
385 | eerror "Please log a bug on http://bugs.gentoo.org" |
| … | |
… | |
| 388 | eerror "installation is incomplete" |
388 | eerror "installation is incomplete" |
| 389 | eerror |
389 | eerror |
| 390 | die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org" |
390 | die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org" |
| 391 | fi |
391 | fi |
| 392 | |
392 | |
| 393 | if ! use vhosts ; then |
393 | if ! use vhosts; then |
| 394 | echo |
394 | echo |
| 395 | elog "vhosts USE flag not set - auto-installing using webapp-config" |
395 | elog "vhosts USE flag not set - auto-installing using webapp-config" |
| 396 | |
396 | |
| 397 | webapp_getinstalltype |
397 | webapp_getinstalltype |
| 398 | |
398 | |
| 399 | G_HOSTNAME="localhost" |
399 | G_HOSTNAME="localhost" |
| 400 | local my_mode=-I |
400 | local my_mode=-I |
| 401 | webapp_read_config |
401 | webapp_read_config |
| 402 | |
402 | |
| 403 | if [ "${IS_REPLACE}" = "1" ]; then |
403 | if [[ "${IS_REPLACE}" == "1" ]]; then |
| 404 | elog "${PN}-${PVR} is already installed - replacing" |
404 | elog "${PN}-${PVR} is already installed - replacing" |
| 405 | my_mode=-I |
405 | my_mode=-I |
| 406 | elif [ "${IS_UPGRADE}" = "1" ]; then |
406 | elif [[ "${IS_UPGRADE}" == "1" ]]; then |
| 407 | elog "${REMOVE_PKG} is already installed - upgrading" |
407 | elog "${REMOVE_PKG} is already installed - upgrading" |
| 408 | my_mode=-U |
408 | my_mode=-U |
| 409 | else |
409 | else |
| 410 | elog "${PN}-${PVR} is not installed - using install mode" |
410 | elog "${PN}-${PVR} is not installed - using install mode" |
| 411 | fi |
411 | fi |
| … | |
… | |
| 428 | elog |
428 | elog |
| 429 | elog " webapp-config -I -h <host> -d ${PN} ${PN} ${PVR}" |
429 | elog " webapp-config -I -h <host> -d ${PN} ${PN} ${PVR}" |
| 430 | elog |
430 | elog |
| 431 | elog "For more details, see the webapp-config(8) man page" |
431 | elog "For more details, see the webapp-config(8) man page" |
| 432 | fi |
432 | fi |
| 433 | |
|
|
| 434 | return 0 |
|
|
| 435 | } |
433 | } |
| 436 | |
434 | |
| 437 | # @FUNCTION: webapp_pkg_prerm |
435 | # @FUNCTION: webapp_pkg_prerm |
| 438 | # @DESCRIPTION: |
436 | # @DESCRIPTION: |
| 439 | # This is the default pkg_prerm() for this eclass. If USE=vhosts is not set |
437 | # This is the default pkg_prerm() for this eclass. If USE=vhosts is not set |
| 440 | # remove all installed copies of this web application. Otherwise instruct the |
438 | # remove all installed copies of this web application. Otherwise instruct the |
| 441 | # user to manually remove those copies. See bug #136959. |
439 | # user to manually remove those copies. See bug #136959. |
| 442 | webapp_pkg_prerm() { |
440 | webapp_pkg_prerm() { |
| 443 | debug-print-function $FUNCNAME $* |
441 | debug-print-function $FUNCNAME $* |
| 444 | |
442 | |
| 445 | local my_output |
443 | local my_output= |
|
|
444 | my_output="$(${WEBAPP_CONFIG} --list-installs ${PN} ${PVR})" |
|
|
445 | [[ $? -ne 0 ]] && return |
|
|
446 | |
| 446 | local x |
447 | local x |
| 447 | |
|
|
| 448 | my_output="$(${WEBAPP_CONFIG} --list-installs ${PN} ${PVR})" |
|
|
| 449 | |
|
|
| 450 | if [ "${?}" != "0" ]; then |
|
|
| 451 | return |
|
|
| 452 | fi |
|
|
| 453 | |
|
|
| 454 | if ! use vhosts ; then |
448 | if ! use vhosts; then |
| 455 | |
449 | |
| 456 | for x in ${my_output} ; do |
450 | for x in ${my_output}; do |
| 457 | [ -f ${x}/.webapp ] && . ${x}/.webapp || ewarn "Cannot find file ${x}/.webapp" |
451 | [[ -f ${x}/.webapp ]] && . ${x}/.webapp || ewarn "Cannot find file ${x}/.webapp" |
| 458 | if [ "${WEB_HOSTNAME}" -a "${WEB_INSTALLDIR}" ]; then |
452 | if [[ -n "${WEB_HOSTNAME}" && -n "${WEB_INSTALLDIR}" ]]; then |
| 459 | ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR} |
453 | ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR} |
| 460 | fi |
454 | fi |
| 461 | done |
455 | done |
| 462 | else |
456 | else |
| 463 | |
457 | |
| 464 | ewarn "Don't forget to use webapp-config to remove any copies of" |
458 | ewarn "Don't forget to use webapp-config to remove any copies of" |
| 465 | ewarn "${PN}-${PVR} installed in" |
459 | ewarn "${PN}-${PVR} installed in" |
| 466 | ewarn |
460 | ewarn |
| 467 | |
461 | |
| 468 | for x in ${my_output} ; do |
462 | for x in ${my_output}; do |
| 469 | [ -f ${x}/.webapp ] && . ${x}/.webapp || ewarn "Cannot find file ${x}/.webapp" |
463 | [[ -f ${x}/.webapp ]] && . ${x}/.webapp || ewarn "Cannot find file ${x}/.webapp" |
| 470 | ewarn " ${x}" |
464 | ewarn " ${x}" |
| 471 | done |
465 | done |
| 472 | fi |
466 | fi |
| 473 | } |
467 | } |