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

Contents of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.37 - (hide annotations) (download)
Sun Nov 20 12:26:22 2005 UTC (8 years, 8 months ago) by stuart
Branch: MAIN
Changes since 1.36: +132 -156 lines
Adds support for python version of webapp-config

1 stuart 1.37 # Copyright 1999-2005 Gentoo Foundation
2 stuart 1.1 # Distributed under the terms of the GNU General Public License v2
3 stuart 1.37 # $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.30 2005/05/10 22:55:17 beu Exp $
4 stuart 1.1 #
5     # eclass/webapp.eclass
6     # Eclass for installing applications to run under a web server
7     #
8     # Part of the implementation of GLEP #11
9     #
10     # Author(s) Stuart Herbert <stuart@gentoo.org>
11 stuart 1.37 # Renat Lumpau <rl03@gentoo.org>
12     # Gunnar Wrobel <php@gunnarwrobel.org>
13 stuart 1.1 #
14     # ------------------------------------------------------------------------
15     #
16 stuart 1.37 # The master copy of this eclass is held in our subversion repository.
17     # http://svn.gnqs.org/projects/vhost-tools/browser/
18 stuart 1.18 #
19 stuart 1.37 # 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 stuart 1.18 # of webapp-config.
22 stuart 1.1 #
23     # ------------------------------------------------------------------------
24    
25     SLOT="${PVR}"
26 swegener 1.36 IUSE="vhosts"
27 stuart 1.37 DEPEND="app-admin/webapp-config"
28     RDEPEND="${DEPEND}"
29 stuart 1.1
30 stuart 1.18 EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm
31 stuart 1.1
32 stuart 1.37 INSTALL_DIR="/${PN}"
33 stuart 1.14 IS_UPGRADE=0
34     IS_REPLACE=0
35    
36 stuart 1.19 INSTALL_CHECK_FILE="installed_by_webapp_eclass"
37    
38 stuart 1.37 ETC_CONFIG="${ROOT}/etc/vhosts/webapp-config"
39     WEBAPP_CONFIG="${ROOT}/usr/sbin/webapp-config"
40    
41     # ------------------------------------------------------------------------
42     # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
43     #
44     # Load the config file /etc/vhosts/webapp-config
45     #
46     # Supports both the old bash version, and the new python version
47     #
48     # ------------------------------------------------------------------------
49    
50     function webapp_read_config ()
51     {
52     if has_version '>=app-admin/webapp-config-1.50'; then
53     ENVVAR=$(${WEBAPP_CONFIG} --query ${PN} ${PVR}) || die "Could not read settings from webapp-config!"
54     eval ${ENVVAR}
55     else
56     . ${ETC_CONFIG} || die "Unable to read ${ETC_CONFIG}"
57     fi
58     }
59 stuart 1.21
60 stuart 1.1 # ------------------------------------------------------------------------
61     # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
62     #
63     # Check whether a specified file exists within the image/ directory
64     # or not.
65     #
66     # @param $1 - file to look for
67 stuart 1.3 # @param $2 - prefix directory to use
68 stuart 1.1 # @return 0 on success, never returns on an error
69     # ------------------------------------------------------------------------
70    
71     function webapp_checkfileexists ()
72     {
73 stuart 1.9 local my_prefix
74    
75 stuart 1.37 [ -n "${2}" ] && my_prefix="${2}/" || my_prefix=
76 stuart 1.9
77 stuart 1.37 if [ ! -e "${my_prefix}${1}" ]; then
78     msg="ebuild fault: file '${1}' not found"
79 stuart 1.1 eerror "$msg"
80     eerror "Please report this as a bug at http://bugs.gentoo.org/"
81     die "$msg"
82     fi
83     }
84    
85     # ------------------------------------------------------------------------
86 stuart 1.3 # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
87     # ------------------------------------------------------------------------
88    
89 stuart 1.14 function webapp_check_installedat
90     {
91     local my_output
92    
93 stuart 1.37 ${WEBAPP_CONFIG} --show-installed -h localhost -d "${INSTALL_DIR}" 2> /dev/null
94 stuart 1.3 }
95    
96     # ------------------------------------------------------------------------
97     # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
98 stuart 1.1 #
99     # ------------------------------------------------------------------------
100    
101 stuart 1.3 function webapp_strip_appdir ()
102     {
103 stuart 1.37 local my_stripped="${1}"
104     echo "${1}" | sed -e "s|${MY_APPDIR}/||g;"
105 stuart 1.3 }
106    
107     function webapp_strip_d ()
108     {
109 stuart 1.37 echo "${1}" | sed -e "s|${D}||g;"
110 stuart 1.3 }
111    
112     function webapp_strip_cwd ()
113 stuart 1.1 {
114 stuart 1.37 local my_stripped="${1}"
115     echo "${1}" | sed -e 's|/./|/|g;'
116 stuart 1.1 }
117    
118     # ------------------------------------------------------------------------
119     # EXPORTED FUNCTION - FOR USE IN EBUILDS
120     #
121     # Identify a config file for a web-based application.
122     #
123     # @param $1 - config file
124     # ------------------------------------------------------------------------
125    
126     function webapp_configfile ()
127     {
128 stuart 1.37 webapp_checkfileexists "${1}" "${D}"
129 stuart 1.27
130 stuart 1.37 local MY_FILE="$(webapp_strip_appdir ${1})"
131     MY_FILE="$(webapp_strip_cwd ${MY_FILE})"
132 stuart 1.3
133 stuart 1.37 einfo "(config) ${MY_FILE}"
134     echo "${MY_FILE}" >> ${D}/${WA_CONFIGLIST}
135 stuart 1.1 }
136    
137     # ------------------------------------------------------------------------
138     # EXPORTED FUNCTION - FOR USE IN EBUILDS
139     #
140 stuart 1.18 # Install a script that will run after a virtual copy is created, and
141     # before a virtual copy has been removed
142     #
143     # @param $1 - the script to run
144     # ------------------------------------------------------------------------
145    
146     function webapp_hook_script ()
147     {
148 stuart 1.37 webapp_checkfileexists "${1}"
149 stuart 1.18
150 stuart 1.37 einfo "(hook) ${1}"
151     cp "${1}" "${D}/${MY_HOOKSCRIPTSDIR}/$(basename ${1})" || die "Unable to install ${1} into ${D}/${MY_HOOKSCRIPTSDIR}/"
152     chmod 555 "${D}/${MY_HOOKSCRIPTSDIR}/$(basename ${1})"
153 stuart 1.18 }
154    
155     # ------------------------------------------------------------------------
156     # EXPORTED FUNCTION - FOR USE IN EBUILDS
157     #
158 stuart 1.5 # Install a text file containing post-installation instructions.
159     #
160     # @param $1 - language code (use 'en' for now)
161     # @param $2 - the file to install
162     # ------------------------------------------------------------------------
163    
164 stuart 1.31 function webapp_postinst_txt ()
165 stuart 1.5 {
166 stuart 1.37 webapp_checkfileexists "${2}"
167 stuart 1.5
168 stuart 1.37 einfo "(info) ${2} (lang: ${1})"
169     cp "${2}" "${D}/${MY_APPDIR}/postinst-${1}.txt"
170 stuart 1.5 }
171    
172     # ------------------------------------------------------------------------
173     # EXPORTED FUNCTION - FOR USE IN EBUILDS
174     #
175 stuart 1.31 # Install a text file containing post-upgrade instructions.
176 stuart 1.1 #
177 stuart 1.31 # @param $1 - language code (use 'en' for now)
178     # @param $2 - the file to install
179     # ------------------------------------------------------------------------
180    
181     function webapp_postupgrade_txt ()
182     {
183 stuart 1.37 webapp_checkfileexists "${2}"
184 stuart 1.31
185 stuart 1.37 einfo "(info) ${2} (lang: ${1})"
186     cp "${2}" "${D}/${MY_APPDIR}/postupgrade-${1}.txt"
187 stuart 1.3 }
188    
189     # ------------------------------------------------------------------------
190     # EXPORTED FUNCTION - FOR USE IN EBUILDS
191     #
192     # Identify a file which must be owned by the webserver's user:group
193     # settings.
194     #
195     # The ownership of the file is NOT set until the application is installed
196     # using the webapp-config tool.
197 stuart 1.37 #
198 stuart 1.3 # @param $1 - file to be owned by the webserver user:group combo
199     #
200     # ------------------------------------------------------------------------
201    
202     function webapp_serverowned ()
203     {
204 stuart 1.37 webapp_checkfileexists "${1}" "$D"
205     local MY_FILE="$(webapp_strip_appdir ${1})"
206     MY_FILE="$(webapp_strip_cwd ${MY_FILE})"
207    
208     einfo "(server owned) ${MY_FILE}"
209     echo "${MY_FILE}" >> "${D}/${WA_SOLIST}"
210 stuart 1.3 }
211    
212     # ------------------------------------------------------------------------
213     # EXPORTED FUNCTION - FOR USE IN EBUILDS
214     #
215 stuart 1.18 # @param $1 - the webserver to install the config file for
216     # (one of apache1, apache2, cherokee)
217     # @param $2 - the config file to install
218     # @param $3 - new name for the config file (default is `basename $2`)
219     # this is an optional parameter
220     #
221     # NOTE:
222     # this function will automagically prepend $1 to the front of your
223     # config file's name
224     # ------------------------------------------------------------------------
225    
226 stuart 1.26 function webapp_server_configfile ()
227 stuart 1.18 {
228 stuart 1.37 webapp_checkfileexists "${2}"
229 stuart 1.18
230     # sort out what the name will be of the config file
231    
232     local my_file
233    
234 stuart 1.37 if [ -z "${3}" ]; then
235     my_file="${1}-$(basename ${2})"
236 stuart 1.18 else
237 stuart 1.37 my_file="${1}-${3}"
238 stuart 1.18 fi
239    
240     # warning:
241     #
242     # do NOT change the naming convention used here without changing all
243     # the other scripts that also rely upon these names
244 stuart 1.37
245     einfo "(${1}) config file '${my_file}'"
246     cp "${2}" "${D}/${MY_SERVERCONFIGDIR}/${my_file}"
247 stuart 1.18 }
248    
249     # ------------------------------------------------------------------------
250     # EXPORTED FUNCTION - FOR USE IN EBUILDS
251 stuart 1.3 #
252     # @param $1 - the db engine that the script is for
253     # (one of: mysql|postgres)
254     # @param $2 - the sql script to be installed
255     # @param $3 - the older version of the app that this db script
256     # will upgrade from
257     # (do not pass this option if your SQL script only creates
258     # a new db from scratch)
259     # ------------------------------------------------------------------------
260    
261     function webapp_sqlscript ()
262     {
263 stuart 1.37 webapp_checkfileexists "${2}"
264 stuart 1.3
265     # create the directory where this script will go
266     #
267     # scripts for specific database engines go into their own subdirectory
268     # just to keep things readable on the filesystem
269    
270 stuart 1.37 if [ ! -d "${D}/${MY_SQLSCRIPTSDIR}/${1}" ]; then
271     mkdir -p "${D}/${MY_SQLSCRIPTSDIR}/${1}" || die "unable to create directory ${D}/${MY_SQLSCRIPTSDIR}/${1}"
272 stuart 1.3 fi
273    
274     # warning:
275     #
276     # do NOT change the naming convention used here without changing all
277     # the other scripts that also rely upon these names
278 stuart 1.37
279 stuart 1.3 # are we dealing with an 'upgrade'-type script?
280 stuart 1.37 if [ -n "${3}" ]; then
281 stuart 1.3 # yes we are
282 stuart 1.37 einfo "(${1}) upgrade script from ${PN}-${PVR} to ${3}"
283     cp "${2}" "${D}${MY_SQLSCRIPTSDIR}/${1}/${3}_to_${PVR}.sql"
284     chmod 600 "${D}${MY_SQLSCRIPTSDIR}/${1}/${3}_to_${PVR}.sql"
285 stuart 1.3 else
286     # no, we are not
287 stuart 1.37 einfo "(${1}) create script for ${PN}-${PVR}"
288     cp "${2}" "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql"
289     chmod 600 "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql"
290 stuart 1.3 fi
291 stuart 1.1 }
292    
293     # ------------------------------------------------------------------------
294     # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
295     # everything else has run
296     #
297     # For now, we just make sure that root owns everything, and that there
298 stuart 1.37 # are no setuid files.
299 stuart 1.1 # ------------------------------------------------------------------------
300    
301     function webapp_src_install ()
302     {
303 stuart 1.22 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/"
304     chmod -R u-s "${D}/"
305     chmod -R g-s "${D}/"
306    
307     keepdir "${MY_PERSISTDIR}"
308     fowners "root:root" "${MY_PERSISTDIR}"
309     fperms 755 "${MY_PERSISTDIR}"
310 stuart 1.15
311 stuart 1.19 # to test whether or not the ebuild has correctly called this function
312     # we add an empty file to the filesystem
313     #
314     # we used to just set a variable in the shell script, but we can
315     # no longer rely on Portage calling both webapp_src_install() and
316     # webapp_pkg_postinst() within the same shell process
317    
318 stuart 1.22 touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}"
319 stuart 1.1 }
320    
321     # ------------------------------------------------------------------------
322 stuart 1.3 # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
323 stuart 1.1 # everything else has run
324     #
325     # If 'vhosts' USE flag is not set, auto-install this app
326     #
327     # ------------------------------------------------------------------------
328    
329     function webapp_pkg_setup ()
330     {
331 stuart 1.15 # add sanity checks here
332    
333 stuart 1.37 if [ "${SLOT}+" != "${PVR}+" ]; then
334     # special case - some ebuilds *do* need to overwride the SLOT
335     if [ "${WEBAPP_MANUAL_SLOT}" != "yes" ]; then
336 dju 1.35 die "ebuild sets SLOT, overrides webapp.eclass"
337 stuart 1.37 else
338     ewarn
339     ewarn "This ebuild overrides the default SLOT behaviour for webapps"
340     ewarn "If this package installs files into the htdocs dir, this is"
341     ewarn "probably a bug in the ebuild."
342     ewarn
343 dju 1.35 fi
344 stuart 1.15 fi
345    
346 stuart 1.8 # pull in the shared configuration file
347    
348 stuart 1.18 G_HOSTNAME="localhost"
349 stuart 1.37 webapp_read_config
350 stuart 1.18
351 swegener 1.34 # are we installing a webapp-config solution over the top of a
352 stuart 1.18 # non-webapp-config solution?
353    
354     if ! use vhosts ; then
355 stuart 1.37 local my_dir="${ROOT}${VHOST_ROOT}/${MY_HTDOCSBASE}/${PN}"
356 stuart 1.18 local my_output
357    
358 stuart 1.37 if [ -d "${my_dir}" ] ; then
359     einfo "You already have something installed in ${my_dir}"
360 stuart 1.18 einfo "Are you trying to install over the top of something I cannot upgrade?"
361    
362 stuart 1.37 my_output="$(webapp_check_installedat)"
363 stuart 1.18
364     if [ "$?" != "0" ]; then
365    
366     # okay, whatever is there, it isn't webapp-config-compatible
367     ewarn
368 stuart 1.37 ewarn "Whatever is in ${my_dir}, it's not"
369 stuart 1.18 ewarn "compatible with webapp-config."
370     ewarn
371 stuart 1.20 ewarn "This ebuild may be overwriting important files."
372     ewarn
373 stuart 1.37 elif [ "$(echo ${my_output} | awk '{ print $1 }')" != "${PN}" ]; then
374     eerror "${my_dir} contains ${my_output}"
375 stuart 1.18 eerror "I cannot upgrade that"
376 stuart 1.37 die "Cannot upgrade contents of ${my_dir}"
377 stuart 1.18 else
378     einfo
379 stuart 1.37 einfo "I can upgrade the contents of ${my_dir}"
380 stuart 1.18 einfo
381     fi
382     fi
383     fi
384 stuart 1.14 }
385 stuart 1.6
386 stuart 1.18 function webapp_getinstalltype ()
387     {
388 stuart 1.14 # or are we upgrading?
389    
390     if ! use vhosts ; then
391     # we only run webapp-config if vhosts USE flag is not set
392    
393     local my_output
394    
395 stuart 1.37 my_output="$(webapp_check_installedat)"
396 stuart 1.14
397 stuart 1.37 if [ "${?}" = "0" ] ; then
398 stuart 1.14 # something is already installed there
399     #
400     # make sure it isn't the same version
401    
402 stuart 1.37 local my_pn="$(echo ${my_output} | awk '{ print $1 }')"
403     local my_pvr="$(echo ${my_output} | awk '{ print $2 }')"
404 stuart 1.14
405     REMOVE_PKG="${my_pn}-${my_pvr}"
406    
407 stuart 1.37 if [ "${my_pn}" == "${PN}" ]; then
408     if [ "${my_pvr}" != "${PVR}" ]; then
409 stuart 1.14 einfo "This is an upgrade"
410     IS_UPGRADE=1
411     else
412     einfo "This is a re-installation"
413     IS_REPLACE=1
414     fi
415 stuart 1.18 else
416 stuart 1.37 einfo "${my_output} is installed there"
417 stuart 1.14 fi
418 stuart 1.18 else
419     einfo "This is an installation"
420 stuart 1.14 fi
421     fi
422 stuart 1.9 }
423 stuart 1.3
424 stuart 1.9 function webapp_src_preinst ()
425     {
426 stuart 1.3 # create the directories that we need
427    
428 stuart 1.22 dodir "${MY_HTDOCSDIR}"
429     dodir "${MY_HOSTROOTDIR}"
430     dodir "${MY_CGIBINDIR}"
431     dodir "${MY_ICONSDIR}"
432     dodir "${MY_ERRORSDIR}"
433     dodir "${MY_SQLSCRIPTSDIR}"
434 stuart 1.25 dodir "${MY_HOOKSCRIPTSDIR}"
435 stuart 1.26 dodir "${MY_SERVERCONFIGDIR}"
436 stuart 1.3 }
437    
438 stuart 1.5 function webapp_pkg_postinst ()
439 stuart 1.3 {
440 stuart 1.37 webapp_read_config
441 stuart 1.21
442 stuart 1.15 # sanity checks, to catch bugs in the ebuild
443    
444 stuart 1.37 if [ ! -f "${ROOT}${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]; then
445 stuart 1.15 eerror
446     eerror "This ebuild did not call webapp_src_install() at the end"
447     eerror "of the src_install() function"
448     eerror
449     eerror "Please log a bug on http://bugs.gentoo.org"
450     eerror
451     eerror "You should use emerge -C to remove this package, as the"
452     eerror "installation is incomplete"
453     eerror
454     die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org"
455     fi
456    
457 stuart 1.10 # if 'vhosts' is not set in your USE flags, we install a copy of
458 stuart 1.37 # this application in ${ROOT}/var/www/localhost/htdocs/${PN}/ for you
459    
460 stuart 1.10 if ! use vhosts ; then
461 stuart 1.14 echo
462 stuart 1.11 einfo "vhosts USE flag not set - auto-installing using webapp-config"
463    
464 stuart 1.14 webapp_getinstalltype
465    
466 stuart 1.10 G_HOSTNAME="localhost"
467     local my_mode=-I
468 stuart 1.37 webapp_read_config
469 stuart 1.10
470 stuart 1.37 if [ "${IS_REPLACE}" = "1" ]; then
471 stuart 1.14 einfo "${PN}-${PVR} is already installed - replacing"
472 stuart 1.27 my_mode=-I
473 stuart 1.37 elif [ "${IS_UPGRADE}" = "1" ]; then
474     einfo "${REMOVE_PKG} is already installed - upgrading"
475 stuart 1.14 my_mode=-U
476 stuart 1.11 else
477     einfo "${PN}-${PVR} is not installed - using install mode"
478 stuart 1.10 fi
479 stuart 1.37
480     my_cmd="${WEBAPP_CONFIG} ${my_mode} -h localhost -u root -d ${INSTALL_DIR} ${PN} ${PVR}"
481     einfo "Running ${my_cmd}"
482     ${my_cmd}
483 stuart 1.14
484     # remove the old version
485     #
486     # why do we do this? well ...
487     #
488     # normally, emerge -u installs a new version and then removes the
489     # old version. however, if the new version goes into a different
490     # slot to the old version, then the old version gets left behind
491     #
492     # if USE=-vhosts, then we want to remove the old version, because
493     # the user is relying on portage to do the magical thing for it
494    
495 stuart 1.37 if [ "${IS_UPGRADE}" = "1" ] ; then
496     einfo "Removing old version ${REMOVE_PKG}"
497 stuart 1.14
498 stuart 1.37 emerge -C "${REMOVE_PKG}"
499 stuart 1.14 fi
500 stuart 1.18 else
501     # vhosts flag is on
502     #
503     # let's tell the administrator what to do next
504    
505     einfo
506     einfo "The 'vhosts' USE flag is switched ON"
507     einfo "This means that Portage will not automatically run webapp-config to"
508     einfo "complete the installation."
509     einfo
510 stuart 1.37 einfo "To install ${PN}-${PVR} into a virtual host, run the following command:"
511 stuart 1.18 einfo
512 stuart 1.37 einfo " webapp-config -I -h <host> -d ${PN} ${PN} ${PVR}"
513 stuart 1.18 einfo
514     einfo "For more details, see the webapp-config(8) man page"
515 stuart 1.10 fi
516 stuart 1.11
517     return 0
518 stuart 1.2 }
519 stuart 1.18
520     function webapp_pkg_prerm ()
521     {
522     # remove any virtual installs that there are
523    
524     local my_output
525     local x
526    
527 stuart 1.37 my_output="$(${WEBAPP_CONFIG} --list-installs ${PN} ${PVR})"
528 stuart 1.18
529 stuart 1.37 if [ "${?}" != "0" ]; then
530 stuart 1.18 return
531     fi
532    
533 stuart 1.37 for x in ${my_output} ; do
534     [ -f ${x}/.webapp ] && . ${x}/.webapp || ewarn "Cannot find file ${x}/.webapp"
535 stuart 1.18
536 stuart 1.37 if [ -z "${WEB_HOSTNAME}" -o -z "${WEB_INSTALLDIR}" ]; then
537 stuart 1.18 ewarn "Don't forget to use webapp-config to remove the copy of"
538     ewarn "${PN}-${PVR} installed in"
539     ewarn
540 stuart 1.37 ewarn " ${x}"
541 stuart 1.18 ewarn
542     else
543     # we have enough information to remove the virtual copy ourself
544    
545 stuart 1.37 ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR}
546 stuart 1.18
547     # if the removal fails - we carry on anyway!
548     fi
549     done
550     }

  ViewVC Help
Powered by ViewVC 1.1.20