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

Diff of /eclass/webapp.eclass

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

Revision 1.12 Revision 1.17
1# Copyright 1999-2004 Gentoo Technologies, Inc. 1# Copyright 1999-2004 Gentoo Technologies, Inc.
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.12 2004/04/29 13:53:24 stuart Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.17 2004/05/11 19:31:29 stuart 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
18 18
19ECLASS=webapp 19ECLASS=webapp
20INHERITED="$INHERITED $ECLASS" 20INHERITED="$INHERITED $ECLASS"
21SLOT="${PVR}" 21SLOT="${PVR}"
22IUSE="$IUSE vhosts" 22IUSE="$IUSE vhosts"
23DEPEND="$DEPEND >=net-www/webapp-config-1.5" 23DEPEND="$DEPEND >=net-www/webapp-config-1.8"
24 24
25EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install 25EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install
26
27INSTALL_DIR="/$PN"
28IS_UPGRADE=0
29IS_REPLACE=0
26 30
27# ------------------------------------------------------------------------ 31# ------------------------------------------------------------------------
28# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 32# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
29# 33#
30# Check whether a specified file exists within the image/ directory 34# Check whether a specified file exists within the image/ directory
51 55
52# ------------------------------------------------------------------------ 56# ------------------------------------------------------------------------
53# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 57# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
54# ------------------------------------------------------------------------ 58# ------------------------------------------------------------------------
55 59
60function webapp_check_installedat
61{
62 local my_output
63
64 /usr/sbin/webapp-config --show-installed -h localhost -d $INSTALL_DIR 2> /dev/null
65}
66
67# ------------------------------------------------------------------------
68# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
69# ------------------------------------------------------------------------
70
56function webapp_import_config () 71function webapp_import_config ()
57{ 72{
58 if [ -z "${MY_HTDOCSDIR}" ]; then 73 if [ -z "${MY_HTDOCSDIR}" ]; then
59 . /etc/conf.d/webapp-config 74 . /etc/conf.d/webapp-config
60 fi 75 fi
69# 84#
70# ------------------------------------------------------------------------ 85# ------------------------------------------------------------------------
71 86
72function webapp_strip_appdir () 87function webapp_strip_appdir ()
73{ 88{
89 local my_stripped="$1"
74 echo "$1" | sed -e "s|${MY_APPDIR}/||g;" 90 echo "$1" | sed -e "s|${MY_APPDIR}/||g;"
75} 91}
76 92
77function webapp_strip_d () 93function webapp_strip_d ()
78{ 94{
79 echo "$1" | sed -e "s|${D}||g;" 95 echo "$1" | sed -e "s|${D}||g;"
80} 96}
81 97
82function webapp_strip_cwd () 98function webapp_strip_cwd ()
83{ 99{
100 local my_stripped="$1"
84 echo "$1" | sed -e 's|/./|/|g;' 101 echo "$1" | sed -e 's|/./|/|g;'
85} 102}
86 103
87# ------------------------------------------------------------------------ 104# ------------------------------------------------------------------------
88# EXPORTED FUNCTION - FOR USE IN EBUILDS 105# EXPORTED FUNCTION - FOR USE IN EBUILDS
224 chmod -R g-s ${D}/ 241 chmod -R g-s ${D}/
225 242
226 keepdir ${MY_PERSISTDIR} 243 keepdir ${MY_PERSISTDIR}
227 fowners root:root ${MY_PERSISTDIR} 244 fowners root:root ${MY_PERSISTDIR}
228 fperms 755 ${MY_PERSISTDIR} 245 fperms 755 ${MY_PERSISTDIR}
246
247 HAS_webapp_src_install=1
229} 248}
230 249
231# ------------------------------------------------------------------------ 250# ------------------------------------------------------------------------
232# EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER 251# EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
233# everything else has run 252# everything else has run
236# 255#
237# ------------------------------------------------------------------------ 256# ------------------------------------------------------------------------
238 257
239function webapp_pkg_setup () 258function webapp_pkg_setup ()
240{ 259{
260 # add sanity checks here
261
262 if [ "$SLOT+" != "${PVR}+" ]; then
263 die "ebuild sets SLOT, overrides webapp.eclass"
264 fi
265
241 # pull in the shared configuration file 266 # pull in the shared configuration file
242 267
243 . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file" 268 . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file"
269}
244 270
271function webapp_getinstalltype ()
272{
245 # are we emerging something that is already installed? 273 # are we emerging something that is already installed?
246 274
247 if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then 275 if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then
248 # yes we are 276 # yes we are
249 ewarn "Removing existing copy of ${PN}-${PVR}" 277 ewarn "Removing existing copy of ${PN}-${PVR}"
250 rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}" 278 rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}"
279 fi
280
281 # or are we upgrading?
282
283 if ! use vhosts ; then
284 # we only run webapp-config if vhosts USE flag is not set
285
286 local my_output
287
288 my_output="`webapp_check_installedat`"
289
290 if [ "$?" = "0" ] ; then
291 # something is already installed there
292 #
293 # make sure it isn't the same version
294
295 local my_pn="`echo $my_output | awk '{ print $1 }'`"
296 local my_pvr="`echo $my_output | awk '{ print $2 }'`"
297
298 REMOVE_PKG="${my_pn}-${my_pvr}"
299
300 if [ "$my_pn" == "$PN" ]; then
301 if [ "$my_pvr" != "$PVR" ]; then
302 einfo "This is an upgrade"
303 IS_UPGRADE=1
304 else
305 einfo "This is a re-installation"
306 IS_REPLACE=1
307 fi
308 fi
309 fi
251 fi 310 fi
252} 311}
253 312
254function webapp_src_preinst () 313function webapp_src_preinst ()
255{ 314{
263 dodir ${MY_SQLSCRIPTSDIR} 322 dodir ${MY_SQLSCRIPTSDIR}
264} 323}
265 324
266function webapp_pkg_postinst () 325function webapp_pkg_postinst ()
267{ 326{
327 # sanity checks, to catch bugs in the ebuild
328
329 if [ "$HAS_webapp_src_install+" == "+" ]; then
330 eerror
331 eerror "This ebuild did not call webapp_src_install() at the end"
332 eerror "of the src_install() function"
333 eerror
334 eerror "Please log a bug on http://bugs.gentoo.org"
335 eerror
336 eerror "You should use emerge -C to remove this package, as the"
337 eerror "installation is incomplete"
338 eerror
339 die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org"
340 fi
341
268 # if 'vhosts' is not set in your USE flags, we install a copy of 342 # if 'vhosts' is not set in your USE flags, we install a copy of
269 # this application in /var/www/localhost/htdocs/${PN}/ for you 343 # this application in /var/www/localhost/htdocs/${PN}/ for you
270
271 344
272 if ! use vhosts ; then 345 if ! use vhosts ; then
346 echo
273 einfo "vhosts USE flag not set - auto-installing using webapp-config" 347 einfo "vhosts USE flag not set - auto-installing using webapp-config"
348
349 webapp_getinstalltype
274 350
275 G_HOSTNAME="localhost" 351 G_HOSTNAME="localhost"
276 . /etc/vhosts/webapp-config 352 . /etc/vhosts/webapp-config
277 353
278 local my_mode=-I 354 local my_mode=-I
279 local my_dir="${VHOST_ROOT}/htdocs/${PN}"
280 355
281 # are we installing afresh - or are we upgrading?
282 # find out by looking to see what (if anything) is installed
283 # in there already
284
285 my_cmd="/usr/sbin/webapp-config --show-installed -d $my_dir 2> /dev/null"
286 einfo "$my_cmd"
287
288 my_output="`/usr/sbin/webapp-config --show-installed -d $my_dir 2> /dev/null`"
289
290 # we can't use the exit status from webapp-config
291
292 if [ "$?" = "0" ]; then 356 if [ "$IS_REPLACE" = "1" ]; then
293 357 einfo "${PN}-${PVR} is already installed - replacing"
294 # something is in there - but the question has to be ... what?
295
296 ewarn "$my_output already installed"
297
298 if [ "`echo $my_output | awk '{ print $1 }'`" = "${PN}" ]; then
299 einfo "$my_output is a copy of ${PN}"
300 if [ "`echo $my_output | awk '{ print $2 }'`" = "${PVR}" ]; then
301 # this version is already installed
302 # we need to remove it first
303
304 /usr/sbin/webapp-config -C -d $my_dir 358 /usr/sbin/webapp-config -C -d "$INSTALL_DIR"
305 else 359 elif [ "$IS_UPGRADE" = "1" ]; then
306 # we have an older version of whatever it is our ebuild is 360 einfo "$REMOVE_PKG is already installed - upgrading"
307 # trying to install ;-)
308 #
309 # this is the situation we can deal with
310
311 einfo "selecting upgrade mode"
312 my_mode=-U 361 my_mode=-U
313 fi
314 else
315 # this should never happen - but just in case ...
316 #
317 # whatever is in that directory, it isn't the application
318 # that we are currently trying to install
319 #
320 # rather than overwrite the contents, we bail with an error
321 # instead
322
323 die "$my_output is already installed in $my_dir"
324 fi
325 else 362 else
326 einfo "${PN}-${PVR} is not installed - using install mode" 363 einfo "${PN}-${PVR} is not installed - using install mode"
327 fi 364 fi
328 365
329 my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $my_dir ${PN} ${PVR}" 366 my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $INSTALL_DIR ${PN} ${PVR}"
330 einfo "Running $my_cmd" 367 einfo "Running $my_cmd"
331 $my_cmd 368 $my_cmd
369
370 # remove the old version
371 #
372 # why do we do this? well ...
373 #
374 # normally, emerge -u installs a new version and then removes the
375 # old version. however, if the new version goes into a different
376 # slot to the old version, then the old version gets left behind
377 #
378 # if USE=-vhosts, then we want to remove the old version, because
379 # the user is relying on portage to do the magical thing for it
380
381 if [ "$IS_UPGRADE" = "1" ] ; then
382 einfo "Removing old version $REMOVE_PKG"
383
384 echo emerge -C $CATEGORY/$REMOVE_PKG
385 fi
332 fi 386 fi
333 387
334 return 0 388 return 0
335} 389}

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.17

  ViewVC Help
Powered by ViewVC 1.1.20