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

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

  ViewVC Help
Powered by ViewVC 1.1.20