/[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.36
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.36 2005/08/23 14:55:11 swegener 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
17# your changes will be overwritten the next time Stu releases a new version 17# your changes will be overwritten the next time Stu releases a new version
18# of webapp-config. 18# of webapp-config.
19# 19#
20# ------------------------------------------------------------------------ 20# ------------------------------------------------------------------------
21 21
22ECLASS=webapp
23INHERITED="$INHERITED $ECLASS"
24SLOT="${PVR}" 22SLOT="${PVR}"
25IUSE="$IUSE vhosts" 23IUSE="vhosts"
26DEPEND="$DEPEND >=net-www/webapp-config-1.9 app-portage/gentoolkit" 24DEPEND="net-www/webapp-config app-portage/gentoolkit"
27 25
28EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm 26EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm
29 27
30INSTALL_DIR="/$PN" 28INSTALL_DIR="/$PN"
31IS_UPGRADE=0 29IS_UPGRADE=0
32IS_REPLACE=0 30IS_REPLACE=0
33 31
32INSTALL_CHECK_FILE="installed_by_webapp_eclass"
33
34ETC_CONFIG="/etc/vhosts/webapp-config"
35
34# ------------------------------------------------------------------------ 36# ------------------------------------------------------------------------
35# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 37# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
36# 38#
37# Check whether a specified file exists within the image/ directory 39# Check whether a specified file exists within the image/ directory
38# or not. 40# or not.
46{ 48{
47 local my_prefix 49 local my_prefix
48 50
49 [ -n "$2" ] && my_prefix="$2/" || my_prefix= 51 [ -n "$2" ] && my_prefix="$2/" || my_prefix=
50 52
51 if [ ! -e ${my_prefix}$1 ]; then 53 if [ ! -e "${my_prefix}$1" ]; then
52 msg="ebuild fault: file $1 not found" 54 msg="ebuild fault: file '$1' not found"
53 eerror "$msg" 55 eerror "$msg"
54 eerror "Please report this as a bug at http://bugs.gentoo.org/" 56 eerror "Please report this as a bug at http://bugs.gentoo.org/"
55 die "$msg" 57 die "$msg"
56 fi 58 fi
57} 59}
62 64
63function webapp_check_installedat 65function webapp_check_installedat
64{ 66{
65 local my_output 67 local my_output
66 68
67 /usr/sbin/webapp-config --show-installed -h localhost -d $INSTALL_DIR 2> /dev/null 69 /usr/sbin/webapp-config --show-installed -h localhost -d "$INSTALL_DIR" 2> /dev/null
68} 70}
69 71
70# ------------------------------------------------------------------------ 72# ------------------------------------------------------------------------
71# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 73# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
72# ------------------------------------------------------------------------ 74# ------------------------------------------------------------------------
113# ------------------------------------------------------------------------ 115# ------------------------------------------------------------------------
114 116
115function webapp_configfile () 117function webapp_configfile ()
116{ 118{
117 webapp_checkfileexists "$1" "$D" 119 webapp_checkfileexists "$1" "$D"
118 echo $1 120
119 local MY_FILE="`webapp_strip_appdir $1`" 121 local MY_FILE="`webapp_strip_appdir \"$1\"`"
120 echo $MY_FILE 122 MY_FILE="`webapp_strip_cwd \"$MY_FILE\"`"
121 123
122 einfo "(config) $MY_FILE" 124 einfo "(config) $MY_FILE"
123 echo "$MY_FILE" >> ${D}${WA_CONFIGLIST} 125 echo "$MY_FILE" >> ${D}${WA_CONFIGLIST}
124} 126}
125 127
132# @param $1 - the script to run 134# @param $1 - the script to run
133# ------------------------------------------------------------------------ 135# ------------------------------------------------------------------------
134 136
135function webapp_hook_script () 137function webapp_hook_script ()
136{ 138{
137 webapp_checkfileexists "$2" 139 webapp_checkfileexists "$1"
138 140
139 einfo "(hook) $1" 141 einfo "(hook) $1"
140 cp "$1" "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`" || die "Unable to install $1 into ${D}${MY_HOOKSCRIPTSDIR}/" 142 cp "$1" "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`" || die "Unable to install $1 into ${D}${MY_HOOKSCRIPTSDIR}/"
141 chmod 555 "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`" 143 chmod 555 "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`"
142} 144}
148# 150#
149# @param $1 - language code (use 'en' for now) 151# @param $1 - language code (use 'en' for now)
150# @param $2 - the file to install 152# @param $2 - the file to install
151# ------------------------------------------------------------------------ 153# ------------------------------------------------------------------------
152 154
153function webapp_postinst_txt 155function webapp_postinst_txt ()
154{ 156{
155 webapp_checkfileexists "$2" 157 webapp_checkfileexists "$2"
156 158
157 einfo "(rtfm) $2 (lang: $1)" 159 einfo "(rtfm) $2 (lang: $1)"
158 cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt" 160 cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt"
159} 161}
160 162
161# ------------------------------------------------------------------------ 163# ------------------------------------------------------------------------
162# EXPORTED FUNCTION - FOR USE IN EBUILDS 164# EXPORTED FUNCTION - FOR USE IN EBUILDS
163# 165#
164# Identify a script file (usually, but not always PHP or Perl) which is 166# Install a text file containing post-upgrade instructions.
165# 167#
166# Files in this list may be modified to #! the required CGI engine when 168# @param $1 - language code (use 'en' for now)
167# installed by webapp-config tool in the future. 169# @param $2 - the file to install
168#
169# @param $1 - the cgi engine to use
170# @param $2 - the script file that could run under a cgi-bin
171#
172# ------------------------------------------------------------------------ 170# ------------------------------------------------------------------------
171
172function webapp_postupgrade_txt ()
173{
174 webapp_checkfileexists "$2"
175
176 einfo "(rtfm) $2 (lang: $1)"
177 cp "$2" "${D}${MY_APPDIR}/postupgrade-$1.txt"
178}
179
180# ------------------------------------------------------------------------
181# DEPRECATED FUNCTION
182#
183# It never worked anyway
173 184
174function webapp_runbycgibin () 185function webapp_runbycgibin ()
175{ 186{
176 webapp_checkfileexists "$2" "$D" 187 if [ -n "$WARN_RUNBYCGIBIN" ] ; then
177 local MY_FILE="`webapp_strip_appdir $2`" 188 return
178 MY_FILE="`webapp_strip_cwd $MY_FILE`" 189 fi
179 190
180 einfo "(cgi-bin) $1 - $MY_FILE" 191 ewarn "This ebuild uses webapp.eclass's webapp_runbycgibin, which is now"
181 echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST} 192 ewarn "deprecated. Please file a bug about this in Bugzilla."
193 WARN_RUNBYCGIBIN=1
182} 194}
183 195
184# ------------------------------------------------------------------------ 196# ------------------------------------------------------------------------
185# EXPORTED FUNCTION - FOR USE IN EBUILDS 197# EXPORTED FUNCTION - FOR USE IN EBUILDS
186# 198#
187# Identify a file which must be owned by the webserver's user:group 199# Identify a file which must be owned by the webserver's user:group
188# settings. 200# settings.
189# 201#
190# The ownership of the file is NOT set until the application is installed 202# The ownership of the file is NOT set until the application is installed
191# using the webapp-config tool. 203# using the webapp-config tool.
192# 204#
193# @param $1 - file to be owned by the webserver user:group combo 205# @param $1 - file to be owned by the webserver user:group combo
194# 206#
195# ------------------------------------------------------------------------ 207# ------------------------------------------------------------------------
196 208
197function webapp_serverowned () 209function webapp_serverowned ()
198{ 210{
199 webapp_checkfileexists "$1" "$D" 211 webapp_checkfileexists "$1" "$D"
200 local MY_FILE="`webapp_strip_appdir $1`" 212 local MY_FILE="`webapp_strip_appdir \"$1\"`"
201 213 MY_FILE="`webapp_strip_cwd \"$MY_FILE\"`"
214
202 einfo "(server owned) $MY_FILE" 215 einfo "(server owned) $MY_FILE"
203 echo "$MY_FILE" >> ${D}${WA_SOLIST} 216 echo "$MY_FILE" >> "${D}${WA_SOLIST}"
204} 217}
205 218
206# ------------------------------------------------------------------------ 219# ------------------------------------------------------------------------
207# EXPORTED FUNCTION - FOR USE IN EBUILDS 220# EXPORTED FUNCTION - FOR USE IN EBUILDS
208# 221#
215# NOTE: 228# NOTE:
216# this function will automagically prepend $1 to the front of your 229# this function will automagically prepend $1 to the front of your
217# config file's name 230# config file's name
218# ------------------------------------------------------------------------ 231# ------------------------------------------------------------------------
219 232
220function webapp_server_config () 233function webapp_server_configfile ()
221{ 234{
222 webapp_checkfileexists "$2" 235 webapp_checkfileexists "$2"
223 236
224 # sort out what the name will be of the config file 237 # sort out what the name will be of the config file
225 238
226 local my_file 239 local my_file
227 240
228 if [ -z "$3" ]; then 241 if [ -z "$3" ]; then
229 $my_file="$1-`basename $2`" 242 my_file="$1-`basename $2`"
230 else 243 else
231 $my_file="$1-$3" 244 my_file="$1-$3"
232 fi 245 fi
233 246
234 # warning: 247 # warning:
235 # 248 #
236 # do NOT change the naming convention used here without changing all 249 # do NOT change the naming convention used here without changing all
237 # the other scripts that also rely upon these names 250 # the other scripts that also rely upon these names
238 251
239 einfo "($1) config file '$my_file'" 252 einfo "($1) config file '$my_file'"
240 cp "$2" "${D}${MY_SERVERCONFIGDIR}/${my_file}" 253 cp "$2" "${D}${MY_SERVERCONFIGDIR}/${my_file}"
241} 254}
242 255
243# ------------------------------------------------------------------------ 256# ------------------------------------------------------------------------
267 280
268 # warning: 281 # warning:
269 # 282 #
270 # do NOT change the naming convention used here without changing all 283 # do NOT change the naming convention used here without changing all
271 # the other scripts that also rely upon these names 284 # the other scripts that also rely upon these names
272 285
273 # are we dealing with an 'upgrade'-type script? 286 # are we dealing with an 'upgrade'-type script?
274 if [ -n "$3" ]; then 287 if [ -n "$3" ]; then
275 # yes we are 288 # yes we are
276 einfo "($1) upgrade script from ${PN}-${PVR} to $3" 289 einfo "($1) upgrade script from ${PN}-${PVR} to $3"
277 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql 290 cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql"
291 chmod 600 "${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql"
278 else 292 else
279 # no, we are not 293 # no, we are not
280 einfo "($1) create script for ${PN}-${PVR}" 294 einfo "($1) create script for ${PN}-${PVR}"
281 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql 295 cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql"
296 chmod 600 "${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql"
282 fi 297 fi
283} 298}
284 299
285# ------------------------------------------------------------------------ 300# ------------------------------------------------------------------------
286# EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER 301# EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
291# the final version! 306# the final version!
292# ------------------------------------------------------------------------ 307# ------------------------------------------------------------------------
293 308
294function webapp_src_install () 309function webapp_src_install ()
295{ 310{
296 chown -R ${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID} ${D}/ 311 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/"
297 chmod -R u-s ${D}/ 312 chmod -R u-s "${D}/"
298 chmod -R g-s ${D}/ 313 chmod -R g-s "${D}/"
299 314
300 keepdir ${MY_PERSISTDIR} 315 keepdir "${MY_PERSISTDIR}"
301 fowners root:root ${MY_PERSISTDIR} 316 fowners "root:root" "${MY_PERSISTDIR}"
302 fperms 755 ${MY_PERSISTDIR} 317 fperms 755 "${MY_PERSISTDIR}"
303 318
304 HAS_webapp_src_install=1 319 # to test whether or not the ebuild has correctly called this function
320 # we add an empty file to the filesystem
321 #
322 # we used to just set a variable in the shell script, but we can
323 # no longer rely on Portage calling both webapp_src_install() and
324 # webapp_pkg_postinst() within the same shell process
325
326 touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}"
305} 327}
306 328
307# ------------------------------------------------------------------------ 329# ------------------------------------------------------------------------
308# EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER 330# EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
309# everything else has run 331# everything else has run
315function webapp_pkg_setup () 337function webapp_pkg_setup ()
316{ 338{
317 # add sanity checks here 339 # add sanity checks here
318 340
319 if [ "$SLOT+" != "${PVR}+" ]; then 341 if [ "$SLOT+" != "${PVR}+" ]; then
342 if [ "$WEBAPP_MANUAL_SLOT" != "yes" ]; then
320 die "ebuild sets SLOT, overrides webapp.eclass" 343 die "ebuild sets SLOT, overrides webapp.eclass"
344 fi
321 fi 345 fi
322 346
323 # pull in the shared configuration file 347 # pull in the shared configuration file
324 348
325 G_HOSTNAME="localhost" 349 G_HOSTNAME="localhost"
326 . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file" 350 . "${ETC_CONFIG}" || die "Unable to open file ${ETC_CONFIG}"
327 351
328 # are we installing a webapp-config solution over the top of a 352 # are we installing a webapp-config solution over the top of a
329 # non-webapp-config solution? 353 # non-webapp-config solution?
330 354
331 if ! use vhosts ; then 355 if ! use vhosts ; then
332 local my_dir="$VHOST_ROOT/$MY_HTDOCSBASE/$PN" 356 local my_dir="$VHOST_ROOT/$MY_HTDOCSBASE/$PN"
333 local my_output 357 local my_output
343 # okay, whatever is there, it isn't webapp-config-compatible 367 # okay, whatever is there, it isn't webapp-config-compatible
344 ewarn 368 ewarn
345 ewarn "Whatever is in $my_dir, it's not" 369 ewarn "Whatever is in $my_dir, it's not"
346 ewarn "compatible with webapp-config." 370 ewarn "compatible with webapp-config."
347 ewarn 371 ewarn
348 372 ewarn "This ebuild may be overwriting important files."
349 my_output="`qpkg -nc -v -f $my_dir`" 373 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 374 elif [ "`echo $my_output | awk '{ print $1 }'`" != "$PN" ]; then
357 eerror "$my_dir contains $my_output" 375 eerror "$my_dir contains $my_output"
358 eerror "I cannot upgrade that" 376 eerror "I cannot upgrade that"
359 die "Cannot upgrade contents of $my_dir" 377 die "Cannot upgrade contents of $my_dir"
360 else 378 else
417 435
418function webapp_src_preinst () 436function webapp_src_preinst ()
419{ 437{
420 # create the directories that we need 438 # create the directories that we need
421 439
422 dodir ${MY_HTDOCSDIR} 440 dodir "${MY_HTDOCSDIR}"
423 dodir ${MY_HOSTROOTDIR} 441 dodir "${MY_HOSTROOTDIR}"
424 dodir ${MY_CGIBINDIR} 442 dodir "${MY_CGIBINDIR}"
425 dodir ${MY_ICONSDIR} 443 dodir "${MY_ICONSDIR}"
426 dodir ${MY_ERRORSDIR} 444 dodir "${MY_ERRORSDIR}"
427 dodir ${MY_SQLSCRIPTSDIR} 445 dodir "${MY_SQLSCRIPTSDIR}"
446 dodir "${MY_HOOKSCRIPTSDIR}"
447 dodir "${MY_SERVERCONFIGDIR}"
428} 448}
429 449
430function webapp_pkg_postinst () 450function webapp_pkg_postinst ()
431{ 451{
452 . "${ETC_CONFIG}"
453
432 # sanity checks, to catch bugs in the ebuild 454 # sanity checks, to catch bugs in the ebuild
433 455
434 if [ "$HAS_webapp_src_install+" == "+" ]; then 456 if [ ! -f "${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]; then
435 eerror 457 eerror
436 eerror "This ebuild did not call webapp_src_install() at the end" 458 eerror "This ebuild did not call webapp_src_install() at the end"
437 eerror "of the src_install() function" 459 eerror "of the src_install() function"
438 eerror 460 eerror
439 eerror "Please log a bug on http://bugs.gentoo.org" 461 eerror "Please log a bug on http://bugs.gentoo.org"
444 die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org" 466 die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org"
445 fi 467 fi
446 468
447 # if 'vhosts' is not set in your USE flags, we install a copy of 469 # if 'vhosts' is not set in your USE flags, we install a copy of
448 # this application in /var/www/localhost/htdocs/${PN}/ for you 470 # this application in /var/www/localhost/htdocs/${PN}/ for you
449 471
450 if ! use vhosts ; then 472 if ! use vhosts ; then
451 echo 473 echo
452 einfo "vhosts USE flag not set - auto-installing using webapp-config" 474 einfo "vhosts USE flag not set - auto-installing using webapp-config"
453 475
454 webapp_getinstalltype 476 webapp_getinstalltype
455 477
456 G_HOSTNAME="localhost" 478 G_HOSTNAME="localhost"
457 . /etc/vhosts/webapp-config 479 . "${ETC_CONFIG}"
458 480
459 local my_mode=-I 481 local my_mode=-I
460 482
461 if [ "$IS_REPLACE" = "1" ]; then 483 if [ "$IS_REPLACE" = "1" ]; then
462 einfo "${PN}-${PVR} is already installed - replacing" 484 einfo "${PN}-${PVR} is already installed - replacing"
463 /usr/sbin/webapp-config -C -d "$INSTALL_DIR" 485 my_mode=-I
464 elif [ "$IS_UPGRADE" = "1" ]; then 486 elif [ "$IS_UPGRADE" = "1" ]; then
465 einfo "$REMOVE_PKG is already installed - upgrading" 487 einfo "$REMOVE_PKG is already installed - upgrading"
466 my_mode=-U 488 my_mode=-U
467 else 489 else
468 einfo "${PN}-${PVR} is not installed - using install mode" 490 einfo "${PN}-${PVR} is not installed - using install mode"
469 fi 491 fi
470 492
471 my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $INSTALL_DIR ${PN} ${PVR}" 493 my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $INSTALL_DIR ${PN} ${PVR}"
472 einfo "Running $my_cmd" 494 einfo "Running $my_cmd"
473 $my_cmd 495 $my_cmd
474 496
475 # remove the old version 497 # remove the old version
484 # the user is relying on portage to do the magical thing for it 506 # the user is relying on portage to do the magical thing for it
485 507
486 if [ "$IS_UPGRADE" = "1" ] ; then 508 if [ "$IS_UPGRADE" = "1" ] ; then
487 einfo "Removing old version $REMOVE_PKG" 509 einfo "Removing old version $REMOVE_PKG"
488 510
489 emerge -C $CATEGORY/$REMOVE_PKG 511 emerge -C "$REMOVE_PKG"
490 fi 512 fi
491 else 513 else
492 # vhosts flag is on 514 # vhosts flag is on
493 # 515 #
494 # let's tell the administrator what to do next 516 # let's tell the administrator what to do next

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

  ViewVC Help
Powered by ViewVC 1.1.20