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

Contents of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.32 - (hide annotations) (download)
Wed Jul 6 20:20:04 2005 UTC (9 years ago) by agriffis
Branch: MAIN
Changes since 1.31: +1 -2 lines
Remove ECLASS= and INHERITED= which haven't been necessary for a long time now

1 vapier 1.24 # Copyright 1999-2004 Gentoo Foundation
2 stuart 1.1 # Distributed under the terms of the GNU General Public License v2
3 agriffis 1.32 # $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.31 2005/05/30 21:44:17 stuart 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     #
12     # ------------------------------------------------------------------------
13     #
14 stuart 1.18 # The master copy of this eclass is held in Stu's subversion repository.
15     #
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.
19 stuart 1.1 #
20     # ------------------------------------------------------------------------
21    
22     INHERITED="$INHERITED $ECLASS"
23     SLOT="${PVR}"
24     IUSE="$IUSE vhosts"
25 stuart 1.31 DEPEND="$DEPEND net-www/webapp-config app-portage/gentoolkit"
26 stuart 1.1
27 stuart 1.18 EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm
28 stuart 1.1
29 stuart 1.14 INSTALL_DIR="/$PN"
30     IS_UPGRADE=0
31     IS_REPLACE=0
32    
33 stuart 1.19 INSTALL_CHECK_FILE="installed_by_webapp_eclass"
34    
35 stuart 1.21 ETC_CONFIG="/etc/vhosts/webapp-config"
36    
37 stuart 1.1 # ------------------------------------------------------------------------
38     # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
39     #
40     # Check whether a specified file exists within the image/ directory
41     # or not.
42     #
43     # @param $1 - file to look for
44 stuart 1.3 # @param $2 - prefix directory to use
45 stuart 1.1 # @return 0 on success, never returns on an error
46     # ------------------------------------------------------------------------
47    
48     function webapp_checkfileexists ()
49     {
50 stuart 1.9 local my_prefix
51    
52     [ -n "$2" ] && my_prefix="$2/" || my_prefix=
53    
54 stuart 1.22 if [ ! -e "${my_prefix}$1" ]; then
55 stuart 1.23 msg="ebuild fault: file '$1' not found"
56 stuart 1.1 eerror "$msg"
57     eerror "Please report this as a bug at http://bugs.gentoo.org/"
58     die "$msg"
59     fi
60     }
61    
62     # ------------------------------------------------------------------------
63 stuart 1.3 # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
64     # ------------------------------------------------------------------------
65    
66 stuart 1.14 function webapp_check_installedat
67     {
68     local my_output
69    
70 stuart 1.22 /usr/sbin/webapp-config --show-installed -h localhost -d "$INSTALL_DIR" 2> /dev/null
71 stuart 1.14 }
72    
73     # ------------------------------------------------------------------------
74     # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
75     # ------------------------------------------------------------------------
76    
77 stuart 1.3 function 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 stuart 1.1 #
91     # ------------------------------------------------------------------------
92    
93 stuart 1.3 function webapp_strip_appdir ()
94     {
95 stuart 1.14 local my_stripped="$1"
96 stuart 1.11 echo "$1" | sed -e "s|${MY_APPDIR}/||g;"
97 stuart 1.3 }
98    
99     function webapp_strip_d ()
100     {
101     echo "$1" | sed -e "s|${D}||g;"
102     }
103    
104     function webapp_strip_cwd ()
105 stuart 1.1 {
106 stuart 1.14 local my_stripped="$1"
107 stuart 1.3 echo "$1" | sed -e 's|/./|/|g;'
108 stuart 1.1 }
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    
118     function webapp_configfile ()
119     {
120 stuart 1.3 webapp_checkfileexists "$1" "$D"
121 stuart 1.27
122 stuart 1.22 local MY_FILE="`webapp_strip_appdir \"$1\"`"
123 stuart 1.29 MY_FILE="`webapp_strip_cwd \"$MY_FILE\"`"
124 stuart 1.3
125     einfo "(config) $MY_FILE"
126 stuart 1.23 echo "$MY_FILE" >> ${D}${WA_CONFIGLIST}
127 stuart 1.1 }
128    
129     # ------------------------------------------------------------------------
130     # EXPORTED FUNCTION - FOR USE IN EBUILDS
131     #
132 stuart 1.18 # 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    
138     function webapp_hook_script ()
139     {
140 stuart 1.23 webapp_checkfileexists "$1"
141 stuart 1.18
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 stuart 1.5 # 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    
156 stuart 1.31 function webapp_postinst_txt ()
157 stuart 1.5 {
158     webapp_checkfileexists "$2"
159    
160     einfo "(rtfm) $2 (lang: $1)"
161 stuart 1.8 cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt"
162 stuart 1.5 }
163    
164     # ------------------------------------------------------------------------
165     # EXPORTED FUNCTION - FOR USE IN EBUILDS
166     #
167 stuart 1.31 # Install a text file containing post-upgrade instructions.
168 stuart 1.1 #
169 stuart 1.31 # @param $1 - language code (use 'en' for now)
170     # @param $2 - the file to install
171     # ------------------------------------------------------------------------
172    
173     function 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 stuart 1.1 #
184 stuart 1.31 # It never worked anyway
185 stuart 1.1
186     function webapp_runbycgibin ()
187     {
188 stuart 1.31 if [ -n "$WARN_RUNBYCGIBIN" ] ; then
189     return
190     fi
191 stuart 1.3
192 stuart 1.31 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
195 stuart 1.3 }
196    
197     # ------------------------------------------------------------------------
198     # EXPORTED FUNCTION - FOR USE IN EBUILDS
199     #
200     # Identify a file which must be owned by the webserver's user:group
201     # settings.
202     #
203     # The ownership of the file is NOT set until the application is installed
204     # using the webapp-config tool.
205     #
206     # @param $1 - file to be owned by the webserver user:group combo
207     #
208     # ------------------------------------------------------------------------
209    
210     function webapp_serverowned ()
211     {
212     webapp_checkfileexists "$1" "$D"
213 stuart 1.22 local MY_FILE="`webapp_strip_appdir \"$1\"`"
214 stuart 1.29 MY_FILE="`webapp_strip_cwd \"$MY_FILE\"`"
215 stuart 1.3
216     einfo "(server owned) $MY_FILE"
217 stuart 1.23 echo "$MY_FILE" >> "${D}${WA_SOLIST}"
218 stuart 1.3 }
219    
220     # ------------------------------------------------------------------------
221     # EXPORTED FUNCTION - FOR USE IN EBUILDS
222     #
223 stuart 1.18 # @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
228     #
229     # NOTE:
230     # this function will automagically prepend $1 to the front of your
231     # config file's name
232     # ------------------------------------------------------------------------
233    
234 stuart 1.26 function webapp_server_configfile ()
235 stuart 1.18 {
236     webapp_checkfileexists "$2"
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 stuart 1.22 my_file="$1-`basename $2`"
244 stuart 1.18 else
245 stuart 1.22 my_file="$1-$3"
246 stuart 1.18 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 stuart 1.3 #
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    
269     function 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 stuart 1.8 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 stuart 1.3 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 stuart 1.22 cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql"
292 stuart 1.31 chmod 600 "${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql"
293 stuart 1.3 else
294     # no, we are not
295     einfo "($1) create script for ${PN}-${PVR}"
296 stuart 1.22 cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql"
297 stuart 1.31 chmod 600 "${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql"
298 stuart 1.3 fi
299 stuart 1.1 }
300    
301     # ------------------------------------------------------------------------
302     # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
303     # everything else has run
304     #
305     # For now, we just make sure that root owns everything, and that there
306     # are no setuid files. I'm sure this will change significantly before
307     # the final version!
308     # ------------------------------------------------------------------------
309    
310     function webapp_src_install ()
311     {
312 stuart 1.22 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/"
313     chmod -R u-s "${D}/"
314     chmod -R g-s "${D}/"
315    
316     keepdir "${MY_PERSISTDIR}"
317     fowners "root:root" "${MY_PERSISTDIR}"
318     fperms 755 "${MY_PERSISTDIR}"
319 stuart 1.15
320 stuart 1.19 # 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 stuart 1.22 touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}"
328 stuart 1.1 }
329    
330     # ------------------------------------------------------------------------
331 stuart 1.3 # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
332 stuart 1.1 # everything else has run
333     #
334     # If 'vhosts' USE flag is not set, auto-install this app
335     #
336     # ------------------------------------------------------------------------
337    
338     function webapp_pkg_setup ()
339     {
340 stuart 1.15 # add sanity checks here
341    
342     if [ "$SLOT+" != "${PVR}+" ]; then
343     die "ebuild sets SLOT, overrides webapp.eclass"
344     fi
345    
346 stuart 1.8 # pull in the shared configuration file
347    
348 stuart 1.18 G_HOSTNAME="localhost"
349 stuart 1.22 . "${ETC_CONFIG}" || die "Unable to open file ${ETC_CONFIG}"
350 stuart 1.18
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 stuart 1.20 ewarn "This ebuild may be overwriting important files."
372     ewarn
373 stuart 1.18 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 stuart 1.14 }
385 stuart 1.6
386 stuart 1.18 function webapp_someunusedfunction ()
387 stuart 1.14 {
388 stuart 1.3 # are we emerging something that is already installed?
389    
390 stuart 1.8 if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then
391 stuart 1.3 # yes we are
392     ewarn "Removing existing copy of ${PN}-${PVR}"
393 stuart 1.8 rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}"
394 stuart 1.3 fi
395 stuart 1.18 }
396 stuart 1.14
397 stuart 1.18 function webapp_getinstalltype ()
398     {
399 stuart 1.14 # 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 stuart 1.18 else
427     einfo "$my_ouptut is installed there"
428 stuart 1.14 fi
429 stuart 1.18 else
430     einfo "This is an installation"
431 stuart 1.14 fi
432     fi
433 stuart 1.9 }
434 stuart 1.3
435 stuart 1.9 function webapp_src_preinst ()
436     {
437 stuart 1.3 # create the directories that we need
438    
439 stuart 1.22 dodir "${MY_HTDOCSDIR}"
440     dodir "${MY_HOSTROOTDIR}"
441     dodir "${MY_CGIBINDIR}"
442     dodir "${MY_ICONSDIR}"
443     dodir "${MY_ERRORSDIR}"
444     dodir "${MY_SQLSCRIPTSDIR}"
445 stuart 1.25 dodir "${MY_HOOKSCRIPTSDIR}"
446 stuart 1.26 dodir "${MY_SERVERCONFIGDIR}"
447 stuart 1.3 }
448    
449 stuart 1.5 function webapp_pkg_postinst ()
450 stuart 1.3 {
451 stuart 1.22 . "${ETC_CONFIG}"
452 stuart 1.21
453 stuart 1.15 # sanity checks, to catch bugs in the ebuild
454    
455 stuart 1.22 if [ ! -f "${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]; then
456 stuart 1.15 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 stuart 1.10 # 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 stuart 1.11
471 stuart 1.10 if ! use vhosts ; then
472 stuart 1.14 echo
473 stuart 1.11 einfo "vhosts USE flag not set - auto-installing using webapp-config"
474    
475 stuart 1.14 webapp_getinstalltype
476    
477 stuart 1.10 G_HOSTNAME="localhost"
478 stuart 1.22 . "${ETC_CONFIG}"
479 stuart 1.10
480     local my_mode=-I
481    
482 stuart 1.14 if [ "$IS_REPLACE" = "1" ]; then
483     einfo "${PN}-${PVR} is already installed - replacing"
484 stuart 1.27 my_mode=-I
485 stuart 1.14 elif [ "$IS_UPGRADE" = "1" ]; then
486     einfo "$REMOVE_PKG is already installed - upgrading"
487     my_mode=-U
488 stuart 1.11 else
489     einfo "${PN}-${PVR} is not installed - using install mode"
490 stuart 1.10 fi
491    
492 stuart 1.14 my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $INSTALL_DIR ${PN} ${PVR}"
493 stuart 1.11 einfo "Running $my_cmd"
494     $my_cmd
495 stuart 1.14
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 stuart 1.28 emerge -C "$REMOVE_PKG"
511 stuart 1.14 fi
512 stuart 1.18 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 stuart 1.10 fi
528 stuart 1.11
529     return 0
530 stuart 1.2 }
531 stuart 1.18
532     function 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     }

  ViewVC Help
Powered by ViewVC 1.1.20