/[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.34
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.34 2005/07/11 15:08:06 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="$IUSE vhosts"
26DEPEND="$DEPEND >=net-www/webapp-config-1.9 app-portage/gentoolkit" 24DEPEND="$DEPEND 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
321 fi 343 fi
322 344
323 # pull in the shared configuration file 345 # pull in the shared configuration file
324 346
325 G_HOSTNAME="localhost" 347 G_HOSTNAME="localhost"
326 . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file" 348 . "${ETC_CONFIG}" || die "Unable to open file ${ETC_CONFIG}"
327 349
328 # are we installing a webapp-config solution over the top of a 350 # are we installing a webapp-config solution over the top of a
329 # non-webapp-config solution? 351 # non-webapp-config solution?
330 352
331 if ! use vhosts ; then 353 if ! use vhosts ; then
332 local my_dir="$VHOST_ROOT/$MY_HTDOCSBASE/$PN" 354 local my_dir="$VHOST_ROOT/$MY_HTDOCSBASE/$PN"
333 local my_output 355 local my_output
343 # okay, whatever is there, it isn't webapp-config-compatible 365 # okay, whatever is there, it isn't webapp-config-compatible
344 ewarn 366 ewarn
345 ewarn "Whatever is in $my_dir, it's not" 367 ewarn "Whatever is in $my_dir, it's not"
346 ewarn "compatible with webapp-config." 368 ewarn "compatible with webapp-config."
347 ewarn 369 ewarn
348 370 ewarn "This ebuild may be overwriting important files."
349 my_output="`qpkg -nc -v -f $my_dir`" 371 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 372 elif [ "`echo $my_output | awk '{ print $1 }'`" != "$PN" ]; then
357 eerror "$my_dir contains $my_output" 373 eerror "$my_dir contains $my_output"
358 eerror "I cannot upgrade that" 374 eerror "I cannot upgrade that"
359 die "Cannot upgrade contents of $my_dir" 375 die "Cannot upgrade contents of $my_dir"
360 else 376 else
417 433
418function webapp_src_preinst () 434function webapp_src_preinst ()
419{ 435{
420 # create the directories that we need 436 # create the directories that we need
421 437
422 dodir ${MY_HTDOCSDIR} 438 dodir "${MY_HTDOCSDIR}"
423 dodir ${MY_HOSTROOTDIR} 439 dodir "${MY_HOSTROOTDIR}"
424 dodir ${MY_CGIBINDIR} 440 dodir "${MY_CGIBINDIR}"
425 dodir ${MY_ICONSDIR} 441 dodir "${MY_ICONSDIR}"
426 dodir ${MY_ERRORSDIR} 442 dodir "${MY_ERRORSDIR}"
427 dodir ${MY_SQLSCRIPTSDIR} 443 dodir "${MY_SQLSCRIPTSDIR}"
444 dodir "${MY_HOOKSCRIPTSDIR}"
445 dodir "${MY_SERVERCONFIGDIR}"
428} 446}
429 447
430function webapp_pkg_postinst () 448function webapp_pkg_postinst ()
431{ 449{
450 . "${ETC_CONFIG}"
451
432 # sanity checks, to catch bugs in the ebuild 452 # sanity checks, to catch bugs in the ebuild
433 453
434 if [ "$HAS_webapp_src_install+" == "+" ]; then 454 if [ ! -f "${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]; then
435 eerror 455 eerror
436 eerror "This ebuild did not call webapp_src_install() at the end" 456 eerror "This ebuild did not call webapp_src_install() at the end"
437 eerror "of the src_install() function" 457 eerror "of the src_install() function"
438 eerror 458 eerror
439 eerror "Please log a bug on http://bugs.gentoo.org" 459 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" 464 die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org"
445 fi 465 fi
446 466
447 # if 'vhosts' is not set in your USE flags, we install a copy of 467 # 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 468 # this application in /var/www/localhost/htdocs/${PN}/ for you
449 469
450 if ! use vhosts ; then 470 if ! use vhosts ; then
451 echo 471 echo
452 einfo "vhosts USE flag not set - auto-installing using webapp-config" 472 einfo "vhosts USE flag not set - auto-installing using webapp-config"
453 473
454 webapp_getinstalltype 474 webapp_getinstalltype
455 475
456 G_HOSTNAME="localhost" 476 G_HOSTNAME="localhost"
457 . /etc/vhosts/webapp-config 477 . "${ETC_CONFIG}"
458 478
459 local my_mode=-I 479 local my_mode=-I
460 480
461 if [ "$IS_REPLACE" = "1" ]; then 481 if [ "$IS_REPLACE" = "1" ]; then
462 einfo "${PN}-${PVR} is already installed - replacing" 482 einfo "${PN}-${PVR} is already installed - replacing"
463 /usr/sbin/webapp-config -C -d "$INSTALL_DIR" 483 my_mode=-I
464 elif [ "$IS_UPGRADE" = "1" ]; then 484 elif [ "$IS_UPGRADE" = "1" ]; then
465 einfo "$REMOVE_PKG is already installed - upgrading" 485 einfo "$REMOVE_PKG is already installed - upgrading"
466 my_mode=-U 486 my_mode=-U
467 else 487 else
468 einfo "${PN}-${PVR} is not installed - using install mode" 488 einfo "${PN}-${PVR} is not installed - using install mode"
469 fi 489 fi
470 490
471 my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $INSTALL_DIR ${PN} ${PVR}" 491 my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $INSTALL_DIR ${PN} ${PVR}"
472 einfo "Running $my_cmd" 492 einfo "Running $my_cmd"
473 $my_cmd 493 $my_cmd
474 494
475 # remove the old version 495 # remove the old version
484 # the user is relying on portage to do the magical thing for it 504 # the user is relying on portage to do the magical thing for it
485 505
486 if [ "$IS_UPGRADE" = "1" ] ; then 506 if [ "$IS_UPGRADE" = "1" ] ; then
487 einfo "Removing old version $REMOVE_PKG" 507 einfo "Removing old version $REMOVE_PKG"
488 508
489 emerge -C $CATEGORY/$REMOVE_PKG 509 emerge -C "$REMOVE_PKG"
490 fi 510 fi
491 else 511 else
492 # vhosts flag is on 512 # vhosts flag is on
493 # 513 #
494 # let's tell the administrator what to do next 514 # let's tell the administrator what to do next

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

  ViewVC Help
Powered by ViewVC 1.1.20