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

Diff of /eclass/webapp.eclass

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

Revision 1.47 Revision 1.49
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.47 2006/12/31 19:16:31 rl03 Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.49 2008/02/22 09:33:45 hollow Exp $
4# 4#
5# eclass/webapp.eclass 5# @ECLASS: webapp.eclass
6# @MAINTAINER:
7# web-apps@gentoo.org
6# Eclass for installing applications to run under a web server 8# @BLURB: functions for installing applications to run under a web server
7# 9# @DESCRIPTION:
10# The webapp eclass contains functions to handle web applications with
8# Part of the implementation of GLEP #11 11# webapp-config. Part of the implementation of GLEP #11
9#
10# Author(s) Stuart Herbert
11# Renat Lumpau <rl03@gentoo.org>
12# Gunnar Wrobel <wrobel@gentoo.org>
13#
14# ------------------------------------------------------------------------
15#
16# The master copy of this eclass is held in our subversion repository.
17# http://svn.gnqs.org/projects/vhost-tools/browser/
18#
19# If you make changes to this file and don't tell us, chances are that
20# your changes will be overwritten the next time we release a new version
21# of webapp-config.
22#
23# ------------------------------------------------------------------------
24 12
25SLOT="${PVR}" 13SLOT="${PVR}"
26IUSE="vhosts" 14IUSE="vhosts"
27DEPEND=">=app-admin/webapp-config-1.50.15" 15DEPEND=">=app-admin/webapp-config-1.50.15"
28RDEPEND="${DEPEND}" 16RDEPEND="${DEPEND}"
37 25
38ETC_CONFIG="${ROOT}/etc/vhosts/webapp-config" 26ETC_CONFIG="${ROOT}/etc/vhosts/webapp-config"
39WEBAPP_CONFIG="${ROOT}/usr/sbin/webapp-config" 27WEBAPP_CONFIG="${ROOT}/usr/sbin/webapp-config"
40WEBAPP_CLEANER="${ROOT}/usr/sbin/webapp-cleaner" 28WEBAPP_CLEANER="${ROOT}/usr/sbin/webapp-cleaner"
41 29
42# ------------------------------------------------------------------------ 30# ==============================================================================
43# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 31# INTERNAL FUNCTIONS
44# 32# ==============================================================================
33
45# Load the config file /etc/vhosts/webapp-config 34# Load the config file /etc/vhosts/webapp-config
46#
47# Supports both the old bash version, and the new python version 35# Supports both the old bash version, and the new python version
48#
49# ------------------------------------------------------------------------
50
51function webapp_read_config () 36webapp_read_config() {
52{
53 if has_version '>=app-admin/webapp-config-1.50'; then 37 if has_version '>=app-admin/webapp-config-1.50'; then
54 ENVVAR=$(${WEBAPP_CONFIG} --query ${PN} ${PVR}) || die "Could not read settings from webapp-config!" 38 ENVVAR=$(${WEBAPP_CONFIG} --query ${PN} ${PVR}) || die "Could not read settings from webapp-config!"
55 eval ${ENVVAR} 39 eval ${ENVVAR}
56 else 40 else
57 . ${ETC_CONFIG} || die "Unable to read ${ETC_CONFIG}" 41 . ${ETC_CONFIG} || die "Unable to read ${ETC_CONFIG}"
58 fi 42 fi
59} 43}
60 44
61# ------------------------------------------------------------------------
62# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
63#
64# Check whether a specified file exists within the image/ directory 45# Check whether a specified file exists in the given directory (`.' by default)
65# or not. 46# or not.
66#
67# @param $1 - file to look for
68# @param $2 - prefix directory to use
69# @return 0 on success, never returns on an error
70# ------------------------------------------------------------------------
71
72function webapp_checkfileexists () 47webapp_checkfileexists() {
73{
74 local my_prefix 48 local my_prefix
75 49
76 [ -n "${2}" ] && my_prefix="${2}/" || my_prefix= 50 [ -n "${2}" ] && my_prefix="${2}/" || my_prefix=
77 51
78 if [ ! -e "${my_prefix}${1}" ]; then 52 if [ ! -e "${my_prefix}${1}" ]; then
81 eerror "Please report this as a bug at http://bugs.gentoo.org/" 55 eerror "Please report this as a bug at http://bugs.gentoo.org/"
82 die "$msg" 56 die "$msg"
83 fi 57 fi
84} 58}
85 59
86# ------------------------------------------------------------------------
87# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
88# ------------------------------------------------------------------------
89
90function webapp_check_installedat 60webapp_check_installedat() {
91{
92 local my_output
93
94 ${WEBAPP_CONFIG} --show-installed -h localhost -d "${INSTALL_DIR}" 2> /dev/null 61 ${WEBAPP_CONFIG} --show-installed -h localhost -d "${INSTALL_DIR}" 2> /dev/null
95} 62}
96 63
97# ------------------------------------------------------------------------
98# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
99#
100# ------------------------------------------------------------------------
101
102function webapp_strip_appdir () 64webapp_strip_appdir() {
103{
104 local my_stripped="${1}" 65 local my_stripped="${1}"
105 echo "${1}" | sed -e "s|${MY_APPDIR}/||g;" 66 echo "${1}" | sed -e "s|${MY_APPDIR}/||g;"
106} 67}
107 68
108function webapp_strip_d () 69webapp_strip_d() {
109{
110 echo "${1}" | sed -e "s|${D}||g;" 70 echo "${1}" | sed -e "s|${D}||g;"
111} 71}
112 72
113function webapp_strip_cwd () 73webapp_strip_cwd() {
114{
115 local my_stripped="${1}" 74 local my_stripped="${1}"
116 echo "${1}" | sed -e 's|/./|/|g;' 75 echo "${1}" | sed -e 's|/./|/|g;'
117} 76}
118 77
119# ------------------------------------------------------------------------ 78# ==============================================================================
120# EXPORTED FUNCTION - FOR USE IN EBUILDS 79# PUBLIC FUNCTIONS
121# 80# ==============================================================================
122# Identify a config file for a web-based application.
123#
124# @param $1 - config file
125# ------------------------------------------------------------------------
126 81
82# @FUNCTION: webapp_configfile
83# @USAGE: <file> [more files ...]
84# @DESCRIPTION:
85# Mark a file config-protected for a web-based application.
127function webapp_configfile () 86webapp_configfile() {
128{
129 local m="" 87 local m=""
130 for m in "$@" ; do 88 for m in "$@" ; do
131 webapp_checkfileexists "${m}" "${D}" 89 webapp_checkfileexists "${m}" "${D}"
132 90
133 local MY_FILE="$(webapp_strip_appdir "${m}")" 91 local MY_FILE="$(webapp_strip_appdir "${m}")"
136 elog "(config) ${MY_FILE}" 94 elog "(config) ${MY_FILE}"
137 echo "${MY_FILE}" >> ${D}/${WA_CONFIGLIST} 95 echo "${MY_FILE}" >> ${D}/${WA_CONFIGLIST}
138 done 96 done
139} 97}
140 98
141# ------------------------------------------------------------------------ 99# @FUNCTION: webapp_hook_script
142# EXPORTED FUNCTION - FOR USE IN EBUILDS 100# @USAGE: <file>
143# 101# @DESCRIPTION:
144# Install a script that will run after a virtual copy is created, and 102# Install a script that will run after a virtual copy is created, and
145# before a virtual copy has been removed 103# before a virtual copy has been removed.
146#
147# @param $1 - the script to run
148# ------------------------------------------------------------------------
149
150function webapp_hook_script () 104webapp_hook_script() {
151{
152 webapp_checkfileexists "${1}" 105 webapp_checkfileexists "${1}"
153 106
154 elog "(hook) ${1}" 107 elog "(hook) ${1}"
155 cp "${1}" "${D}/${MY_HOOKSCRIPTSDIR}/$(basename "${1}")" || die "Unable to install ${1} into ${D}/${MY_HOOKSCRIPTSDIR}/" 108 cp "${1}" "${D}/${MY_HOOKSCRIPTSDIR}/$(basename "${1}")" || die "Unable to install ${1} into ${D}/${MY_HOOKSCRIPTSDIR}/"
156 chmod 555 "${D}/${MY_HOOKSCRIPTSDIR}/$(basename "${1}")" 109 chmod 555 "${D}/${MY_HOOKSCRIPTSDIR}/$(basename "${1}")"
157} 110}
158 111
159# ------------------------------------------------------------------------ 112# @FUNCTION: webapp_postinst_txt
160# EXPORTED FUNCTION - FOR USE IN EBUILDS 113# @USAGE: <lang> <file>
161# 114# @DESCRIPTION:
162# Install a text file containing post-installation instructions. 115# Install a text file containing post-installation instructions.
163#
164# @param $1 - language code (use 'en' for now)
165# @param $2 - the file to install
166# ------------------------------------------------------------------------
167
168function webapp_postinst_txt () 116webapp_postinst_txt() {
169{
170 webapp_checkfileexists "${2}" 117 webapp_checkfileexists "${2}"
171 118
172 elog "(info) ${2} (lang: ${1})" 119 elog "(info) ${2} (lang: ${1})"
173 cp "${2}" "${D}/${MY_APPDIR}/postinst-${1}.txt" 120 cp "${2}" "${D}/${MY_APPDIR}/postinst-${1}.txt"
174} 121}
175 122
176# ------------------------------------------------------------------------ 123# @FUNCTION: webapp_postupgrade_txt
177# EXPORTED FUNCTION - FOR USE IN EBUILDS 124# @USAGE: <lang> <file>
178# 125# @DESCRIPTION:
179# Install a text file containing post-upgrade instructions. 126# Install a text file containing post-upgrade instructions.
180#
181# @param $1 - language code (use 'en' for now)
182# @param $2 - the file to install
183# ------------------------------------------------------------------------
184
185function webapp_postupgrade_txt () 127webapp_postupgrade_txt() {
186{
187 webapp_checkfileexists "${2}" 128 webapp_checkfileexists "${2}"
188 129
189 elog "(info) ${2} (lang: ${1})" 130 elog "(info) ${2} (lang: ${1})"
190 cp "${2}" "${D}/${MY_APPDIR}/postupgrade-${1}.txt" 131 cp "${2}" "${D}/${MY_APPDIR}/postupgrade-${1}.txt"
191} 132}
192 133
193# ------------------------------------------------------------------------ 134# @FUNCTION: webapp_serverowned
194# EXPORTED FUNCTION - FOR USE IN EBUILDS 135# @USAGE: [-R] <file> [more files ...]
195# 136# @DESCRIPTION:
196# Identify a file which must be owned by the webserver's user:group 137# Identify a file which must be owned by the webserver's user:group settings.
197# settings.
198#
199# The ownership of the file is NOT set until the application is installed 138# The ownership of the file is NOT set until the application is installed using
200# using the webapp-config tool. 139# the webapp-config tool. If -R is given directories are handled recursively.
201#
202# @param $1 - file to be owned by the webserver user:group combo
203#
204# ------------------------------------------------------------------------
205
206function webapp_serverowned () 140webapp_serverowned() {
207{
208 local a="" 141 local a=""
209 local m="" 142 local m=""
210 if [ "${1}" = "-R" ]; then 143 if [ "${1}" = "-R" ]; then
211 shift 144 shift
212 for m in "$@" ; do 145 for m in "$@" ; do
230 echo "${MY_FILE}" >> "${D}/${WA_SOLIST}" 163 echo "${MY_FILE}" >> "${D}/${WA_SOLIST}"
231 done 164 done
232 fi 165 fi
233} 166}
234 167
235# ------------------------------------------------------------------------ 168# @FUNCTION: webapp_server_configfile
236# EXPORTED FUNCTION - FOR USE IN EBUILDS 169# @USAGE: <server> <file> [new name]
237# 170# @DESCRIPTION:
238# @param $1 - the webserver to install the config file for 171# Install a configuration file for the webserver. You need to specify a
239# (one of apache1, apache2, cherokee) 172# webapp-config supported <server>. if no new name is given `basename $2' is
240# @param $2 - the config file to install 173# used by default. Note: this function will automagically prepend $1 to the
241# @param $3 - new name for the config file (default is `basename $2`) 174# front of your config file's name.
242# this is an optional parameter
243#
244# NOTE:
245# this function will automagically prepend $1 to the front of your
246# config file's name
247# ------------------------------------------------------------------------
248
249function webapp_server_configfile () 175webapp_server_configfile() {
250{
251 webapp_checkfileexists "${2}" 176 webapp_checkfileexists "${2}"
252 177
253 # sort out what the name will be of the config file 178 # sort out what the name will be of the config file
254 179
255 local my_file 180 local my_file
267 192
268 elog "(${1}) config file '${my_file}'" 193 elog "(${1}) config file '${my_file}'"
269 cp "${2}" "${D}/${MY_SERVERCONFIGDIR}/${my_file}" 194 cp "${2}" "${D}/${MY_SERVERCONFIGDIR}/${my_file}"
270} 195}
271 196
272# ------------------------------------------------------------------------ 197# @FUNCTION: webapp_sqlscript
273# EXPORTED FUNCTION - FOR USE IN EBUILDS 198# @USAGE: <db> <file> [version]
274# 199# @DESCRIPTION:
275# @param $1 - the db engine that the script is for 200# Install a SQL script that creates/upgrades a database schema for the web
276# (one of: mysql|postgres) 201# application. Currently supported database engines are mysql and postgres.
277# @param $2 - the sql script to be installed 202# If a version is given the script should upgrade the database schema from
278# @param $3 - the older version of the app that this db script 203# the given version to $PVR.
279# will upgrade from
280# (do not pass this option if your SQL script only creates
281# a new db from scratch)
282# ------------------------------------------------------------------------
283
284function webapp_sqlscript () 204webapp_sqlscript() {
285{
286 webapp_checkfileexists "${2}" 205 webapp_checkfileexists "${2}"
287 206
288 # create the directory where this script will go 207 # create the directory where this script will go
289 # 208 #
290 # scripts for specific database engines go into their own subdirectory 209 # scripts for specific database engines go into their own subdirectory
311 cp "${2}" "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql" 230 cp "${2}" "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql"
312 chmod 600 "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql" 231 chmod 600 "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql"
313 fi 232 fi
314} 233}
315 234
316# ------------------------------------------------------------------------ 235# ==============================================================================
317# EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER 236# EXPORTED FUNCTIONS
318# everything else has run 237# ==============================================================================
319# 238
239# @FUNCTION: webapp_src_install
240# @DESCRIPTION:
241# You need to call this function in src_install() AFTER everything else has run.
320# For now, we just make sure that root owns everything, and that there 242# For now, we just make sure that root owns everything, and that there are no
321# are no setuid files. 243# setuid files.
322# ------------------------------------------------------------------------
323
324function webapp_src_install () 244webapp_src_install() {
325{
326 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/" 245 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/"
327 chmod -R u-s "${D}/" 246 chmod -R u-s "${D}/"
328 chmod -R g-s "${D}/" 247 chmod -R g-s "${D}/"
329 248
330 keepdir "${MY_PERSISTDIR}" 249 keepdir "${MY_PERSISTDIR}"
339 # webapp_pkg_postinst() within the same shell process 258 # webapp_pkg_postinst() within the same shell process
340 259
341 touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}" 260 touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}"
342} 261}
343 262
344# ------------------------------------------------------------------------ 263# @FUNCTION: webapp_pkg_setup
345# EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER 264# @DESCRIPTION:
346# everything else has run 265# You need to call this function in pkg_config() AFTER everything else has run.
347#
348# If 'vhosts' USE flag is not set, auto-install this app 266# If 'vhosts' USE flag is not set, auto-install this app.
349#
350# ------------------------------------------------------------------------
351
352function webapp_pkg_setup () 267webapp_pkg_setup() {
353{
354 # add sanity checks here 268 # add sanity checks here
355 269
356 # special case - some ebuilds *do* need to overwride the SLOT 270 # special case - some ebuilds *do* need to overwride the SLOT
357 if [[ "${SLOT}+" != "${PVR}+" && "${WEBAPP_MANUAL_SLOT}" != "yes" ]]; then 271 if [[ "${SLOT}+" != "${PVR}+" && "${WEBAPP_MANUAL_SLOT}" != "yes" ]]; then
358 die "Set WEBAPP_MANUAL_SLOT=\"yes\" if you need to SLOT manually" 272 die "Set WEBAPP_MANUAL_SLOT=\"yes\" if you need to SLOT manually"
389 fi 303 fi
390 fi 304 fi
391 fi 305 fi
392} 306}
393 307
394function webapp_getinstalltype () 308webapp_getinstalltype() {
395{
396 # or are we upgrading? 309 # or are we upgrading?
397 310
398 if ! use vhosts ; then 311 if ! use vhosts ; then
399 # we only run webapp-config if vhosts USE flag is not set 312 # we only run webapp-config if vhosts USE flag is not set
400 313
427 elog "This is an installation" 340 elog "This is an installation"
428 fi 341 fi
429 fi 342 fi
430} 343}
431 344
432function webapp_src_preinst () 345webapp_src_preinst() {
433{
434 # create the directories that we need 346 # create the directories that we need
435 347
436 dodir "${MY_HTDOCSDIR}" 348 dodir "${MY_HTDOCSDIR}"
437 dodir "${MY_HOSTROOTDIR}" 349 dodir "${MY_HOSTROOTDIR}"
438 dodir "${MY_CGIBINDIR}" 350 dodir "${MY_CGIBINDIR}"
441 dodir "${MY_SQLSCRIPTSDIR}" 353 dodir "${MY_SQLSCRIPTSDIR}"
442 dodir "${MY_HOOKSCRIPTSDIR}" 354 dodir "${MY_HOOKSCRIPTSDIR}"
443 dodir "${MY_SERVERCONFIGDIR}" 355 dodir "${MY_SERVERCONFIGDIR}"
444} 356}
445 357
446function webapp_pkg_postinst () 358webapp_pkg_postinst() {
447{
448 webapp_read_config 359 webapp_read_config
449 360
450 # sanity checks, to catch bugs in the ebuild 361 # sanity checks, to catch bugs in the ebuild
451 362
452 if [ ! -f "${ROOT}${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]; then 363 if [ ! -f "${ROOT}${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]; then
512 fi 423 fi
513 424
514 return 0 425 return 0
515} 426}
516 427
517function webapp_pkg_prerm () 428webapp_pkg_prerm() {
518{
519 # remove any virtual installs that there are 429 # remove any virtual installs that there are
520 430
521 local my_output 431 local my_output
522 local x 432 local x
523 433
525 435
526 if [ "${?}" != "0" ]; then 436 if [ "${?}" != "0" ]; then
527 return 437 return
528 fi 438 fi
529 439
440 if ! use vhosts ; then # remove any installed copies
441
530 for x in ${my_output} ; do 442 for x in ${my_output} ; do
531 [ -f ${x}/.webapp ] && . ${x}/.webapp || ewarn "Cannot find file ${x}/.webapp" 443 [ -f ${x}/.webapp ] && . ${x}/.webapp || ewarn "Cannot find file ${x}/.webapp"
532
533 if [ -z "${WEB_HOSTNAME}" -o -z "${WEB_INSTALLDIR}" ]; then 444 if [ "${WEB_HOSTNAME}" -a "${WEB_INSTALLDIR}" ]; then
445 ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR}
446 fi
447 done
448 else # don't remove anything, but warn user. bug #136959
449
534 ewarn "Don't forget to use webapp-config to remove the copy of" 450 ewarn "Don't forget to use webapp-config to remove any copies of"
535 ewarn "${PN}-${PVR} installed in" 451 ewarn "${PN}-${PVR} installed in"
536 ewarn 452 ewarn
453
454 for x in ${my_output} ; do
455 [ -f ${x}/.webapp ] && . ${x}/.webapp || ewarn "Cannot find file ${x}/.webapp"
537 ewarn " ${x}" 456 ewarn " ${x}"
538 ewarn
539 else
540 # we have enough information to remove the virtual copy ourself
541
542 ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR}
543
544 # if the removal fails - we carry on anyway!
545 fi
546 done 457 done
458 fi
547} 459}

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.49

  ViewVC Help
Powered by ViewVC 1.1.20