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

Diff of /eclass/webapp.eclass

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

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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.32

  ViewVC Help
Powered by ViewVC 1.1.20