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

Diff of /eclass/webapp.eclass

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

Revision 1.18 Revision 1.24
1# Copyright 1999-2004 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.18 2004/05/17 22:44:35 stuart Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.24 2004/06/25 00:39:48 vapier 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
21 21
22ECLASS=webapp 22ECLASS=webapp
23INHERITED="$INHERITED $ECLASS" 23INHERITED="$INHERITED $ECLASS"
24SLOT="${PVR}" 24SLOT="${PVR}"
25IUSE="$IUSE vhosts" 25IUSE="$IUSE vhosts"
26DEPEND="$DEPEND >=net-www/webapp-config-1.9 app-portage/gentoolkit" 26DEPEND="$DEPEND >=net-www/webapp-config-1.7 app-portage/gentoolkit"
27 27
28EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm 28EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm
29 29
30INSTALL_DIR="/$PN" 30INSTALL_DIR="/$PN"
31IS_UPGRADE=0 31IS_UPGRADE=0
32IS_REPLACE=0 32IS_REPLACE=0
33 33
34INSTALL_CHECK_FILE="installed_by_webapp_eclass"
35
36ETC_CONFIG="/etc/vhosts/webapp-config"
37
34# ------------------------------------------------------------------------ 38# ------------------------------------------------------------------------
35# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 39# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
36# 40#
37# Check whether a specified file exists within the image/ directory 41# Check whether a specified file exists within the image/ directory
38# or not. 42# or not.
46{ 50{
47 local my_prefix 51 local my_prefix
48 52
49 [ -n "$2" ] && my_prefix="$2/" || my_prefix= 53 [ -n "$2" ] && my_prefix="$2/" || my_prefix=
50 54
51 if [ ! -e ${my_prefix}$1 ]; then 55 if [ ! -e "${my_prefix}$1" ]; then
52 msg="ebuild fault: file $1 not found" 56 msg="ebuild fault: file '$1' not found"
53 eerror "$msg" 57 eerror "$msg"
54 eerror "Please report this as a bug at http://bugs.gentoo.org/" 58 eerror "Please report this as a bug at http://bugs.gentoo.org/"
55 die "$msg" 59 die "$msg"
56 fi 60 fi
57} 61}
62 66
63function webapp_check_installedat 67function webapp_check_installedat
64{ 68{
65 local my_output 69 local my_output
66 70
67 /usr/sbin/webapp-config --show-installed -h localhost -d $INSTALL_DIR 2> /dev/null 71 /usr/sbin/webapp-config --show-installed -h localhost -d "$INSTALL_DIR" 2> /dev/null
68} 72}
69 73
70# ------------------------------------------------------------------------ 74# ------------------------------------------------------------------------
71# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 75# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
72# ------------------------------------------------------------------------ 76# ------------------------------------------------------------------------
114 118
115function webapp_configfile () 119function webapp_configfile ()
116{ 120{
117 webapp_checkfileexists "$1" "$D" 121 webapp_checkfileexists "$1" "$D"
118 echo $1 122 echo $1
119 local MY_FILE="`webapp_strip_appdir $1`" 123 local MY_FILE="`webapp_strip_appdir \"$1\"`"
120 echo $MY_FILE 124 echo $MY_FILE
121 125
122 einfo "(config) $MY_FILE" 126 einfo "(config) $MY_FILE"
123 echo "$MY_FILE" >> ${D}${WA_CONFIGLIST} 127 echo "$MY_FILE" >> ${D}${WA_CONFIGLIST}
124} 128}
132# @param $1 - the script to run 136# @param $1 - the script to run
133# ------------------------------------------------------------------------ 137# ------------------------------------------------------------------------
134 138
135function webapp_hook_script () 139function webapp_hook_script ()
136{ 140{
137 webapp_checkfileexists "$2" 141 webapp_checkfileexists "$1"
138 142
139 einfo "(hook) $1" 143 einfo "(hook) $1"
140 cp "$1" "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`" || die "Unable to install $1 into ${D}${MY_HOOKSCRIPTSDIR}/" 144 cp "$1" "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`" || die "Unable to install $1 into ${D}${MY_HOOKSCRIPTSDIR}/"
141 chmod 555 "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`" 145 chmod 555 "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`"
142} 146}
172# ------------------------------------------------------------------------ 176# ------------------------------------------------------------------------
173 177
174function webapp_runbycgibin () 178function webapp_runbycgibin ()
175{ 179{
176 webapp_checkfileexists "$2" "$D" 180 webapp_checkfileexists "$2" "$D"
177 local MY_FILE="`webapp_strip_appdir $2`" 181 local MY_FILE="`webapp_strip_appdir \"$2\"`"
178 MY_FILE="`webapp_strip_cwd $MY_FILE`" 182 MY_FILE="`webapp_strip_cwd \"$MY_FILE\"`"
179 183
180 einfo "(cgi-bin) $1 - $MY_FILE" 184 einfo "(cgi-bin) $1 - $MY_FILE"
181 echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST} 185 echo "\"$1\" \"$MY_FILE\"" >> "${D}${WA_RUNBYCGIBINLIST}"
182} 186}
183 187
184# ------------------------------------------------------------------------ 188# ------------------------------------------------------------------------
185# EXPORTED FUNCTION - FOR USE IN EBUILDS 189# EXPORTED FUNCTION - FOR USE IN EBUILDS
186# 190#
195# ------------------------------------------------------------------------ 199# ------------------------------------------------------------------------
196 200
197function webapp_serverowned () 201function webapp_serverowned ()
198{ 202{
199 webapp_checkfileexists "$1" "$D" 203 webapp_checkfileexists "$1" "$D"
200 local MY_FILE="`webapp_strip_appdir $1`" 204 local MY_FILE="`webapp_strip_appdir \"$1\"`"
201 205
202 einfo "(server owned) $MY_FILE" 206 einfo "(server owned) $MY_FILE"
203 echo "$MY_FILE" >> ${D}${WA_SOLIST} 207 echo "$MY_FILE" >> "${D}${WA_SOLIST}"
204} 208}
205 209
206# ------------------------------------------------------------------------ 210# ------------------------------------------------------------------------
207# EXPORTED FUNCTION - FOR USE IN EBUILDS 211# EXPORTED FUNCTION - FOR USE IN EBUILDS
208# 212#
224 # sort out what the name will be of the config file 228 # sort out what the name will be of the config file
225 229
226 local my_file 230 local my_file
227 231
228 if [ -z "$3" ]; then 232 if [ -z "$3" ]; then
229 $my_file="$1-`basename $2`" 233 my_file="$1-`basename $2`"
230 else 234 else
231 $my_file="$1-$3" 235 my_file="$1-$3"
232 fi 236 fi
233 237
234 # warning: 238 # warning:
235 # 239 #
236 # do NOT change the naming convention used here without changing all 240 # do NOT change the naming convention used here without changing all
272 276
273 # are we dealing with an 'upgrade'-type script? 277 # are we dealing with an 'upgrade'-type script?
274 if [ -n "$3" ]; then 278 if [ -n "$3" ]; then
275 # yes we are 279 # yes we are
276 einfo "($1) upgrade script from ${PN}-${PVR} to $3" 280 einfo "($1) upgrade script from ${PN}-${PVR} to $3"
277 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql 281 cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql"
278 else 282 else
279 # no, we are not 283 # no, we are not
280 einfo "($1) create script for ${PN}-${PVR}" 284 einfo "($1) create script for ${PN}-${PVR}"
281 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql 285 cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql"
282 fi 286 fi
283} 287}
284 288
285# ------------------------------------------------------------------------ 289# ------------------------------------------------------------------------
286# EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER 290# EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
291# the final version! 295# the final version!
292# ------------------------------------------------------------------------ 296# ------------------------------------------------------------------------
293 297
294function webapp_src_install () 298function webapp_src_install ()
295{ 299{
296 chown -R ${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID} ${D}/ 300 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/"
297 chmod -R u-s ${D}/ 301 chmod -R u-s "${D}/"
298 chmod -R g-s ${D}/ 302 chmod -R g-s "${D}/"
299 303
300 keepdir ${MY_PERSISTDIR} 304 keepdir "${MY_PERSISTDIR}"
301 fowners root:root ${MY_PERSISTDIR} 305 fowners "root:root" "${MY_PERSISTDIR}"
302 fperms 755 ${MY_PERSISTDIR} 306 fperms 755 "${MY_PERSISTDIR}"
303 307
304 HAS_webapp_src_install=1 308 # to test whether or not the ebuild has correctly called this function
309 # we add an empty file to the filesystem
310 #
311 # we used to just set a variable in the shell script, but we can
312 # no longer rely on Portage calling both webapp_src_install() and
313 # webapp_pkg_postinst() within the same shell process
314
315 touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}"
305} 316}
306 317
307# ------------------------------------------------------------------------ 318# ------------------------------------------------------------------------
308# EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER 319# EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
309# everything else has run 320# everything else has run
321 fi 332 fi
322 333
323 # pull in the shared configuration file 334 # pull in the shared configuration file
324 335
325 G_HOSTNAME="localhost" 336 G_HOSTNAME="localhost"
326 . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file" 337 . "${ETC_CONFIG}" || die "Unable to open file ${ETC_CONFIG}"
327 338
328 # 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
329 # non-webapp-config solution? 340 # non-webapp-config solution?
330 341
331 if ! use vhosts ; then 342 if ! use vhosts ; then
343 # okay, whatever is there, it isn't webapp-config-compatible 354 # okay, whatever is there, it isn't webapp-config-compatible
344 ewarn 355 ewarn
345 ewarn "Whatever is in $my_dir, it's not" 356 ewarn "Whatever is in $my_dir, it's not"
346 ewarn "compatible with webapp-config." 357 ewarn "compatible with webapp-config."
347 ewarn 358 ewarn
348 359 ewarn "This ebuild may be overwriting important files."
349 my_output="`qpkg -nc -v -f $my_dir`" 360 ewarn
350 if [ -n "$my_output" ]; then
351 eerror "Please remove $my_output and re-emerge."
352 else
353 eerror "Please remove the contents of $my_dir, and then re-emerge."
354 fi
355 die "Cannot upgrade contents of $my_dir"
356 elif [ "`echo $my_output | awk '{ print $1 }'`" != "$PN" ]; then 361 elif [ "`echo $my_output | awk '{ print $1 }'`" != "$PN" ]; then
357 eerror "$my_dir contains $my_output" 362 eerror "$my_dir contains $my_output"
358 eerror "I cannot upgrade that" 363 eerror "I cannot upgrade that"
359 die "Cannot upgrade contents of $my_dir" 364 die "Cannot upgrade contents of $my_dir"
360 else 365 else
417 422
418function webapp_src_preinst () 423function webapp_src_preinst ()
419{ 424{
420 # create the directories that we need 425 # create the directories that we need
421 426
422 dodir ${MY_HTDOCSDIR} 427 dodir "${MY_HTDOCSDIR}"
423 dodir ${MY_HOSTROOTDIR} 428 dodir "${MY_HOSTROOTDIR}"
424 dodir ${MY_CGIBINDIR} 429 dodir "${MY_CGIBINDIR}"
425 dodir ${MY_ICONSDIR} 430 dodir "${MY_ICONSDIR}"
426 dodir ${MY_ERRORSDIR} 431 dodir "${MY_ERRORSDIR}"
427 dodir ${MY_SQLSCRIPTSDIR} 432 dodir "${MY_SQLSCRIPTSDIR}"
428} 433}
429 434
430function webapp_pkg_postinst () 435function webapp_pkg_postinst ()
431{ 436{
437 . "${ETC_CONFIG}"
438
432 # sanity checks, to catch bugs in the ebuild 439 # sanity checks, to catch bugs in the ebuild
433 440
434 if [ "$HAS_webapp_src_install+" == "+" ]; then 441 if [ ! -f "${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]; then
435 eerror 442 eerror
436 eerror "This ebuild did not call webapp_src_install() at the end" 443 eerror "This ebuild did not call webapp_src_install() at the end"
437 eerror "of the src_install() function" 444 eerror "of the src_install() function"
438 eerror 445 eerror
439 eerror "Please log a bug on http://bugs.gentoo.org" 446 eerror "Please log a bug on http://bugs.gentoo.org"
452 einfo "vhosts USE flag not set - auto-installing using webapp-config" 459 einfo "vhosts USE flag not set - auto-installing using webapp-config"
453 460
454 webapp_getinstalltype 461 webapp_getinstalltype
455 462
456 G_HOSTNAME="localhost" 463 G_HOSTNAME="localhost"
457 . /etc/vhosts/webapp-config 464 . "${ETC_CONFIG}"
458 465
459 local my_mode=-I 466 local my_mode=-I
460 467
461 if [ "$IS_REPLACE" = "1" ]; then 468 if [ "$IS_REPLACE" = "1" ]; then
462 einfo "${PN}-${PVR} is already installed - replacing" 469 einfo "${PN}-${PVR} is already installed - replacing"
484 # the user is relying on portage to do the magical thing for it 491 # the user is relying on portage to do the magical thing for it
485 492
486 if [ "$IS_UPGRADE" = "1" ] ; then 493 if [ "$IS_UPGRADE" = "1" ] ; then
487 einfo "Removing old version $REMOVE_PKG" 494 einfo "Removing old version $REMOVE_PKG"
488 495
489 emerge -C $CATEGORY/$REMOVE_PKG 496 emerge -C "$CATEGORY/$REMOVE_PKG"
490 fi 497 fi
491 else 498 else
492 # vhosts flag is on 499 # vhosts flag is on
493 # 500 #
494 # let's tell the administrator what to do next 501 # let's tell the administrator what to do next

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.24

  ViewVC Help
Powered by ViewVC 1.1.20