/[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.31
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.31 2005/05/30 21:44:17 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
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 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# ------------------------------------------------------------------------
113# ------------------------------------------------------------------------ 117# ------------------------------------------------------------------------
114 118
115function webapp_configfile () 119function webapp_configfile ()
116{ 120{
117 webapp_checkfileexists "$1" "$D" 121 webapp_checkfileexists "$1" "$D"
118 echo $1 122
119 local MY_FILE="`webapp_strip_appdir $1`" 123 local MY_FILE="`webapp_strip_appdir \"$1\"`"
120 echo $MY_FILE 124 MY_FILE="`webapp_strip_cwd \"$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}
125 129
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}
148# 152#
149# @param $1 - language code (use 'en' for now) 153# @param $1 - language code (use 'en' for now)
150# @param $2 - the file to install 154# @param $2 - the file to install
151# ------------------------------------------------------------------------ 155# ------------------------------------------------------------------------
152 156
153function webapp_postinst_txt 157function webapp_postinst_txt ()
154{ 158{
155 webapp_checkfileexists "$2" 159 webapp_checkfileexists "$2"
156 160
157 einfo "(rtfm) $2 (lang: $1)" 161 einfo "(rtfm) $2 (lang: $1)"
158 cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt" 162 cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt"
159} 163}
160 164
161# ------------------------------------------------------------------------ 165# ------------------------------------------------------------------------
162# EXPORTED FUNCTION - FOR USE IN EBUILDS 166# EXPORTED FUNCTION - FOR USE IN EBUILDS
163# 167#
164# Identify a script file (usually, but not always PHP or Perl) which is 168# Install a text file containing post-upgrade instructions.
165# 169#
166# Files in this list may be modified to #! the required CGI engine when 170# @param $1 - language code (use 'en' for now)
167# installed by webapp-config tool in the future. 171# @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# ------------------------------------------------------------------------ 172# ------------------------------------------------------------------------
173
174function webapp_postupgrade_txt ()
175{
176 webapp_checkfileexists "$2"
177
178 einfo "(rtfm) $2 (lang: $1)"
179 cp "$2" "${D}${MY_APPDIR}/postupgrade-$1.txt"
180}
181
182# ------------------------------------------------------------------------
183# DEPRECATED FUNCTION
184#
185# It never worked anyway
173 186
174function webapp_runbycgibin () 187function webapp_runbycgibin ()
175{ 188{
176 webapp_checkfileexists "$2" "$D" 189 if [ -n "$WARN_RUNBYCGIBIN" ] ; then
177 local MY_FILE="`webapp_strip_appdir $2`" 190 return
178 MY_FILE="`webapp_strip_cwd $MY_FILE`" 191 fi
179 192
180 einfo "(cgi-bin) $1 - $MY_FILE" 193 ewarn "This ebuild uses webapp.eclass's webapp_runbycgibin, which is now"
181 echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST} 194 ewarn "deprecated. Please file a bug about this in Bugzilla."
195 WARN_RUNBYCGIBIN=1
182} 196}
183 197
184# ------------------------------------------------------------------------ 198# ------------------------------------------------------------------------
185# EXPORTED FUNCTION - FOR USE IN EBUILDS 199# EXPORTED FUNCTION - FOR USE IN EBUILDS
186# 200#
195# ------------------------------------------------------------------------ 209# ------------------------------------------------------------------------
196 210
197function webapp_serverowned () 211function webapp_serverowned ()
198{ 212{
199 webapp_checkfileexists "$1" "$D" 213 webapp_checkfileexists "$1" "$D"
200 local MY_FILE="`webapp_strip_appdir $1`" 214 local MY_FILE="`webapp_strip_appdir \"$1\"`"
215 MY_FILE="`webapp_strip_cwd \"$MY_FILE\"`"
201 216
202 einfo "(server owned) $MY_FILE" 217 einfo "(server owned) $MY_FILE"
203 echo "$MY_FILE" >> ${D}${WA_SOLIST} 218 echo "$MY_FILE" >> "${D}${WA_SOLIST}"
204} 219}
205 220
206# ------------------------------------------------------------------------ 221# ------------------------------------------------------------------------
207# EXPORTED FUNCTION - FOR USE IN EBUILDS 222# EXPORTED FUNCTION - FOR USE IN EBUILDS
208# 223#
215# NOTE: 230# NOTE:
216# this function will automagically prepend $1 to the front of your 231# this function will automagically prepend $1 to the front of your
217# config file's name 232# config file's name
218# ------------------------------------------------------------------------ 233# ------------------------------------------------------------------------
219 234
220function webapp_server_config () 235function webapp_server_configfile ()
221{ 236{
222 webapp_checkfileexists "$2" 237 webapp_checkfileexists "$2"
223 238
224 # sort out what the name will be of the config file 239 # sort out what the name will be of the config file
225 240
226 local my_file 241 local my_file
227 242
228 if [ -z "$3" ]; then 243 if [ -z "$3" ]; then
229 $my_file="$1-`basename $2`" 244 my_file="$1-`basename $2`"
230 else 245 else
231 $my_file="$1-$3" 246 my_file="$1-$3"
232 fi 247 fi
233 248
234 # warning: 249 # warning:
235 # 250 #
236 # do NOT change the naming convention used here without changing all 251 # do NOT change the naming convention used here without changing all
272 287
273 # are we dealing with an 'upgrade'-type script? 288 # are we dealing with an 'upgrade'-type script?
274 if [ -n "$3" ]; then 289 if [ -n "$3" ]; then
275 # yes we are 290 # yes we are
276 einfo "($1) upgrade script from ${PN}-${PVR} to $3" 291 einfo "($1) upgrade script from ${PN}-${PVR} to $3"
277 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql 292 cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql"
293 chmod 600 "${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql"
278 else 294 else
279 # no, we are not 295 # no, we are not
280 einfo "($1) create script for ${PN}-${PVR}" 296 einfo "($1) create script for ${PN}-${PVR}"
281 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql 297 cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql"
298 chmod 600 "${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql"
282 fi 299 fi
283} 300}
284 301
285# ------------------------------------------------------------------------ 302# ------------------------------------------------------------------------
286# EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER 303# EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
291# the final version! 308# the final version!
292# ------------------------------------------------------------------------ 309# ------------------------------------------------------------------------
293 310
294function webapp_src_install () 311function webapp_src_install ()
295{ 312{
296 chown -R ${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID} ${D}/ 313 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/"
297 chmod -R u-s ${D}/ 314 chmod -R u-s "${D}/"
298 chmod -R g-s ${D}/ 315 chmod -R g-s "${D}/"
299 316
300 keepdir ${MY_PERSISTDIR} 317 keepdir "${MY_PERSISTDIR}"
301 fowners root:root ${MY_PERSISTDIR} 318 fowners "root:root" "${MY_PERSISTDIR}"
302 fperms 755 ${MY_PERSISTDIR} 319 fperms 755 "${MY_PERSISTDIR}"
303 320
304 HAS_webapp_src_install=1 321 # to test whether or not the ebuild has correctly called this function
322 # we add an empty file to the filesystem
323 #
324 # we used to just set a variable in the shell script, but we can
325 # no longer rely on Portage calling both webapp_src_install() and
326 # webapp_pkg_postinst() within the same shell process
327
328 touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}"
305} 329}
306 330
307# ------------------------------------------------------------------------ 331# ------------------------------------------------------------------------
308# EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER 332# EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
309# everything else has run 333# everything else has run
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
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"
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"
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.31

  ViewVC Help
Powered by ViewVC 1.1.20