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

Diff of /eclass/webapp.eclass

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

Revision 1.1.1.1 Revision 1.47
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2006 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.1.1.1 2005/11/30 09:59:13 chriswhite Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.47 2006/12/31 19:16:31 rl03 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
9# 9#
10# Author(s) Stuart Herbert <stuart@gentoo.org> 10# Author(s) Stuart Herbert
11# Renat Lumpau <rl03@gentoo.org> 11# Renat Lumpau <rl03@gentoo.org>
12# Gunnar Wrobel <php@gunnarwrobel.org> 12# Gunnar Wrobel <wrobel@gentoo.org>
13# 13#
14# ------------------------------------------------------------------------ 14# ------------------------------------------------------------------------
15# 15#
16# The master copy of this eclass is held in our subversion repository. 16# The master copy of this eclass is held in our subversion repository.
17# http://svn.gnqs.org/projects/vhost-tools/browser/ 17# http://svn.gnqs.org/projects/vhost-tools/browser/
22# 22#
23# ------------------------------------------------------------------------ 23# ------------------------------------------------------------------------
24 24
25SLOT="${PVR}" 25SLOT="${PVR}"
26IUSE="vhosts" 26IUSE="vhosts"
27DEPEND="app-admin/webapp-config" 27DEPEND=">=app-admin/webapp-config-1.50.15"
28RDEPEND="${DEPEND}" 28RDEPEND="${DEPEND}"
29 29
30EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm 30EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm
31 31
32INSTALL_DIR="/${PN}" 32INSTALL_DIR="/${PN}"
35 35
36INSTALL_CHECK_FILE="installed_by_webapp_eclass" 36INSTALL_CHECK_FILE="installed_by_webapp_eclass"
37 37
38ETC_CONFIG="${ROOT}/etc/vhosts/webapp-config" 38ETC_CONFIG="${ROOT}/etc/vhosts/webapp-config"
39WEBAPP_CONFIG="${ROOT}/usr/sbin/webapp-config" 39WEBAPP_CONFIG="${ROOT}/usr/sbin/webapp-config"
40WEBAPP_CLEANER="${ROOT}/usr/sbin/webapp-cleaner"
40 41
41# ------------------------------------------------------------------------ 42# ------------------------------------------------------------------------
42# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 43# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
43# 44#
44# Load the config file /etc/vhosts/webapp-config 45# Load the config file /etc/vhosts/webapp-config
123# @param $1 - config file 124# @param $1 - config file
124# ------------------------------------------------------------------------ 125# ------------------------------------------------------------------------
125 126
126function webapp_configfile () 127function webapp_configfile ()
127{ 128{
129 local m=""
130 for m in "$@" ; do
128 webapp_checkfileexists "${1}" "${D}" 131 webapp_checkfileexists "${m}" "${D}"
129 132
130 local MY_FILE="$(webapp_strip_appdir ${1})" 133 local MY_FILE="$(webapp_strip_appdir "${m}")"
131 MY_FILE="$(webapp_strip_cwd ${MY_FILE})" 134 MY_FILE="$(webapp_strip_cwd "${MY_FILE}")"
132 135
133 einfo "(config) ${MY_FILE}" 136 elog "(config) ${MY_FILE}"
134 echo "${MY_FILE}" >> ${D}/${WA_CONFIGLIST} 137 echo "${MY_FILE}" >> ${D}/${WA_CONFIGLIST}
138 done
135} 139}
136 140
137# ------------------------------------------------------------------------ 141# ------------------------------------------------------------------------
138# EXPORTED FUNCTION - FOR USE IN EBUILDS 142# EXPORTED FUNCTION - FOR USE IN EBUILDS
139# 143#
145 149
146function webapp_hook_script () 150function webapp_hook_script ()
147{ 151{
148 webapp_checkfileexists "${1}" 152 webapp_checkfileexists "${1}"
149 153
150 einfo "(hook) ${1}" 154 elog "(hook) ${1}"
151 cp "${1}" "${D}/${MY_HOOKSCRIPTSDIR}/$(basename ${1})" || die "Unable to install ${1} into ${D}/${MY_HOOKSCRIPTSDIR}/" 155 cp "${1}" "${D}/${MY_HOOKSCRIPTSDIR}/$(basename "${1}")" || die "Unable to install ${1} into ${D}/${MY_HOOKSCRIPTSDIR}/"
152 chmod 555 "${D}/${MY_HOOKSCRIPTSDIR}/$(basename ${1})" 156 chmod 555 "${D}/${MY_HOOKSCRIPTSDIR}/$(basename "${1}")"
153} 157}
154 158
155# ------------------------------------------------------------------------ 159# ------------------------------------------------------------------------
156# EXPORTED FUNCTION - FOR USE IN EBUILDS 160# EXPORTED FUNCTION - FOR USE IN EBUILDS
157# 161#
163 167
164function webapp_postinst_txt () 168function webapp_postinst_txt ()
165{ 169{
166 webapp_checkfileexists "${2}" 170 webapp_checkfileexists "${2}"
167 171
168 einfo "(info) ${2} (lang: ${1})" 172 elog "(info) ${2} (lang: ${1})"
169 cp "${2}" "${D}/${MY_APPDIR}/postinst-${1}.txt" 173 cp "${2}" "${D}/${MY_APPDIR}/postinst-${1}.txt"
170} 174}
171 175
172# ------------------------------------------------------------------------ 176# ------------------------------------------------------------------------
173# EXPORTED FUNCTION - FOR USE IN EBUILDS 177# EXPORTED FUNCTION - FOR USE IN EBUILDS
180 184
181function webapp_postupgrade_txt () 185function webapp_postupgrade_txt ()
182{ 186{
183 webapp_checkfileexists "${2}" 187 webapp_checkfileexists "${2}"
184 188
185 einfo "(info) ${2} (lang: ${1})" 189 elog "(info) ${2} (lang: ${1})"
186 cp "${2}" "${D}/${MY_APPDIR}/postupgrade-${1}.txt" 190 cp "${2}" "${D}/${MY_APPDIR}/postupgrade-${1}.txt"
187} 191}
188 192
189# ------------------------------------------------------------------------ 193# ------------------------------------------------------------------------
190# EXPORTED FUNCTION - FOR USE IN EBUILDS 194# EXPORTED FUNCTION - FOR USE IN EBUILDS
192# Identify a file which must be owned by the webserver's user:group 196# Identify a file which must be owned by the webserver's user:group
193# settings. 197# settings.
194# 198#
195# The ownership of the file is NOT set until the application is installed 199# The ownership of the file is NOT set until the application is installed
196# using the webapp-config tool. 200# using the webapp-config tool.
197# 201#
198# @param $1 - file to be owned by the webserver user:group combo 202# @param $1 - file to be owned by the webserver user:group combo
199# 203#
200# ------------------------------------------------------------------------ 204# ------------------------------------------------------------------------
201 205
202function webapp_serverowned () 206function webapp_serverowned ()
203{ 207{
208 local a=""
209 local m=""
210 if [ "${1}" = "-R" ]; then
211 shift
212 for m in "$@" ; do
213 for a in $(find ${D}/${m}); do
214 a=${a/${D}\/\///}
215 webapp_checkfileexists "${a}" "$D"
216 local MY_FILE="$(webapp_strip_appdir "${a}")"
217 MY_FILE="$(webapp_strip_cwd "${MY_FILE}")"
218
219 elog "(server owned) ${MY_FILE}"
220 echo "${MY_FILE}" >> "${D}/${WA_SOLIST}"
221 done
222 done
223 else
224 for m in "$@" ; do
204 webapp_checkfileexists "${1}" "$D" 225 webapp_checkfileexists "${m}" "$D"
205 local MY_FILE="$(webapp_strip_appdir ${1})" 226 local MY_FILE="$(webapp_strip_appdir "${m}")"
206 MY_FILE="$(webapp_strip_cwd ${MY_FILE})" 227 MY_FILE="$(webapp_strip_cwd "${MY_FILE}")"
207 228
208 einfo "(server owned) ${MY_FILE}" 229 elog "(server owned) ${MY_FILE}"
209 echo "${MY_FILE}" >> "${D}/${WA_SOLIST}" 230 echo "${MY_FILE}" >> "${D}/${WA_SOLIST}"
231 done
232 fi
210} 233}
211 234
212# ------------------------------------------------------------------------ 235# ------------------------------------------------------------------------
213# EXPORTED FUNCTION - FOR USE IN EBUILDS 236# EXPORTED FUNCTION - FOR USE IN EBUILDS
214# 237#
230 # sort out what the name will be of the config file 253 # sort out what the name will be of the config file
231 254
232 local my_file 255 local my_file
233 256
234 if [ -z "${3}" ]; then 257 if [ -z "${3}" ]; then
235 my_file="${1}-$(basename ${2})" 258 my_file="${1}-$(basename "${2}")"
236 else 259 else
237 my_file="${1}-${3}" 260 my_file="${1}-${3}"
238 fi 261 fi
239 262
240 # warning: 263 # warning:
241 # 264 #
242 # do NOT change the naming convention used here without changing all 265 # do NOT change the naming convention used here without changing all
243 # the other scripts that also rely upon these names 266 # the other scripts that also rely upon these names
244 267
245 einfo "(${1}) config file '${my_file}'" 268 elog "(${1}) config file '${my_file}'"
246 cp "${2}" "${D}/${MY_SERVERCONFIGDIR}/${my_file}" 269 cp "${2}" "${D}/${MY_SERVERCONFIGDIR}/${my_file}"
247} 270}
248 271
249# ------------------------------------------------------------------------ 272# ------------------------------------------------------------------------
250# EXPORTED FUNCTION - FOR USE IN EBUILDS 273# EXPORTED FUNCTION - FOR USE IN EBUILDS
273 296
274 # warning: 297 # warning:
275 # 298 #
276 # do NOT change the naming convention used here without changing all 299 # do NOT change the naming convention used here without changing all
277 # the other scripts that also rely upon these names 300 # the other scripts that also rely upon these names
278 301
279 # are we dealing with an 'upgrade'-type script? 302 # are we dealing with an 'upgrade'-type script?
280 if [ -n "${3}" ]; then 303 if [ -n "${3}" ]; then
281 # yes we are 304 # yes we are
282 einfo "(${1}) upgrade script from ${PN}-${PVR} to ${3}" 305 elog "(${1}) upgrade script from ${PN}-${PVR} to ${3}"
283 cp "${2}" "${D}${MY_SQLSCRIPTSDIR}/${1}/${3}_to_${PVR}.sql" 306 cp "${2}" "${D}${MY_SQLSCRIPTSDIR}/${1}/${3}_to_${PVR}.sql"
284 chmod 600 "${D}${MY_SQLSCRIPTSDIR}/${1}/${3}_to_${PVR}.sql" 307 chmod 600 "${D}${MY_SQLSCRIPTSDIR}/${1}/${3}_to_${PVR}.sql"
285 else 308 else
286 # no, we are not 309 # no, we are not
287 einfo "(${1}) create script for ${PN}-${PVR}" 310 elog "(${1}) create script for ${PN}-${PVR}"
288 cp "${2}" "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql" 311 cp "${2}" "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql"
289 chmod 600 "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql" 312 chmod 600 "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql"
290 fi 313 fi
291} 314}
292 315
303 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/" 326 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/"
304 chmod -R u-s "${D}/" 327 chmod -R u-s "${D}/"
305 chmod -R g-s "${D}/" 328 chmod -R g-s "${D}/"
306 329
307 keepdir "${MY_PERSISTDIR}" 330 keepdir "${MY_PERSISTDIR}"
308 fowners "root:root" "${MY_PERSISTDIR}" 331 fowners "root:0" "${MY_PERSISTDIR}"
309 fperms 755 "${MY_PERSISTDIR}" 332 fperms 755 "${MY_PERSISTDIR}"
310 333
311 # to test whether or not the ebuild has correctly called this function 334 # to test whether or not the ebuild has correctly called this function
312 # we add an empty file to the filesystem 335 # we add an empty file to the filesystem
313 # 336 #
328 351
329function webapp_pkg_setup () 352function webapp_pkg_setup ()
330{ 353{
331 # add sanity checks here 354 # add sanity checks here
332 355
333 if [ "${SLOT}+" != "${PVR}+" ]; then
334 # special case - some ebuilds *do* need to overwride the SLOT 356 # special case - some ebuilds *do* need to overwride the SLOT
335 if [ "${WEBAPP_MANUAL_SLOT}" != "yes" ]; then 357 if [[ "${SLOT}+" != "${PVR}+" && "${WEBAPP_MANUAL_SLOT}" != "yes" ]]; then
336 die "ebuild sets SLOT, overrides webapp.eclass" 358 die "Set WEBAPP_MANUAL_SLOT=\"yes\" if you need to SLOT manually"
337 else
338 ewarn
339 ewarn "This ebuild overrides the default SLOT behaviour for webapps"
340 ewarn "If this package installs files into the htdocs dir, this is"
341 ewarn "probably a bug in the ebuild."
342 ewarn
343 fi
344 fi 359 fi
345 360
346 # pull in the shared configuration file 361 # pull in the shared configuration file
347 362
348 G_HOSTNAME="localhost" 363 G_HOSTNAME="localhost"
354 if ! use vhosts ; then 369 if ! use vhosts ; then
355 local my_dir="${ROOT}${VHOST_ROOT}/${MY_HTDOCSBASE}/${PN}" 370 local my_dir="${ROOT}${VHOST_ROOT}/${MY_HTDOCSBASE}/${PN}"
356 local my_output 371 local my_output
357 372
358 if [ -d "${my_dir}" ] ; then 373 if [ -d "${my_dir}" ] ; then
359 einfo "You already have something installed in ${my_dir}"
360 einfo "Are you trying to install over the top of something I cannot upgrade?"
361
362 my_output="$(webapp_check_installedat)" 374 my_output="$(webapp_check_installedat)"
363 375
364 if [ "$?" != "0" ]; then 376 if [ "$?" != "0" ]; then
365
366 # okay, whatever is there, it isn't webapp-config-compatible 377 # okay, whatever is there, it isn't webapp-config-compatible
378 ewarn "You already have something installed in ${my_dir}"
367 ewarn 379 ewarn
368 ewarn "Whatever is in ${my_dir}, it's not" 380 ewarn "Whatever is in ${my_dir}, it's not"
369 ewarn "compatible with webapp-config." 381 ewarn "compatible with webapp-config."
370 ewarn 382 ewarn
371 ewarn "This ebuild may be overwriting important files." 383 ewarn "This ebuild may be overwriting important files."
372 ewarn 384 ewarn
373 elif [ "$(echo ${my_output} | awk '{ print $1 }')" != "${PN}" ]; then 385 elif [ "$(echo ${my_output} | awk '{ print $1 }')" != "${PN}" ]; then
374 eerror "${my_dir} contains ${my_output}" 386 eerror "${my_dir} contains ${my_output}"
375 eerror "I cannot upgrade that" 387 eerror "I cannot upgrade that"
376 die "Cannot upgrade contents of ${my_dir}" 388 die "Cannot upgrade contents of ${my_dir}"
377 else
378 einfo
379 einfo "I can upgrade the contents of ${my_dir}"
380 einfo
381 fi 389 fi
382 fi 390 fi
383 fi 391 fi
384} 392}
385 393
404 412
405 REMOVE_PKG="${my_pn}-${my_pvr}" 413 REMOVE_PKG="${my_pn}-${my_pvr}"
406 414
407 if [ "${my_pn}" == "${PN}" ]; then 415 if [ "${my_pn}" == "${PN}" ]; then
408 if [ "${my_pvr}" != "${PVR}" ]; then 416 if [ "${my_pvr}" != "${PVR}" ]; then
409 einfo "This is an upgrade" 417 elog "This is an upgrade"
410 IS_UPGRADE=1 418 IS_UPGRADE=1
411 else 419 else
412 einfo "This is a re-installation" 420 elog "This is a re-installation"
413 IS_REPLACE=1 421 IS_REPLACE=1
414 fi 422 fi
415 else 423 else
416 einfo "${my_output} is installed there" 424 elog "${my_output} is installed there"
417 fi 425 fi
418 else 426 else
419 einfo "This is an installation" 427 elog "This is an installation"
420 fi 428 fi
421 fi 429 fi
422} 430}
423 431
424function webapp_src_preinst () 432function webapp_src_preinst ()
454 die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org" 462 die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org"
455 fi 463 fi
456 464
457 # if 'vhosts' is not set in your USE flags, we install a copy of 465 # if 'vhosts' is not set in your USE flags, we install a copy of
458 # this application in ${ROOT}/var/www/localhost/htdocs/${PN}/ for you 466 # this application in ${ROOT}/var/www/localhost/htdocs/${PN}/ for you
459 467
460 if ! use vhosts ; then 468 if ! use vhosts ; then
461 echo 469 echo
462 einfo "vhosts USE flag not set - auto-installing using webapp-config" 470 elog "vhosts USE flag not set - auto-installing using webapp-config"
463 471
464 webapp_getinstalltype 472 webapp_getinstalltype
465 473
466 G_HOSTNAME="localhost" 474 G_HOSTNAME="localhost"
467 local my_mode=-I 475 local my_mode=-I
468 webapp_read_config 476 webapp_read_config
469 477
470 if [ "${IS_REPLACE}" = "1" ]; then 478 if [ "${IS_REPLACE}" = "1" ]; then
471 einfo "${PN}-${PVR} is already installed - replacing" 479 elog "${PN}-${PVR} is already installed - replacing"
472 my_mode=-I 480 my_mode=-I
473 elif [ "${IS_UPGRADE}" = "1" ]; then 481 elif [ "${IS_UPGRADE}" = "1" ]; then
474 einfo "${REMOVE_PKG} is already installed - upgrading" 482 elog "${REMOVE_PKG} is already installed - upgrading"
475 my_mode=-U 483 my_mode=-U
476 else 484 else
477 einfo "${PN}-${PVR} is not installed - using install mode" 485 elog "${PN}-${PVR} is not installed - using install mode"
478 fi 486 fi
479 487
480 my_cmd="${WEBAPP_CONFIG} ${my_mode} -h localhost -u root -d ${INSTALL_DIR} ${PN} ${PVR}" 488 my_cmd="${WEBAPP_CONFIG} ${my_mode} -h localhost -u root -d ${INSTALL_DIR} ${PN} ${PVR}"
481 einfo "Running ${my_cmd}" 489 elog "Running ${my_cmd}"
482 ${my_cmd} 490 ${my_cmd}
483 491
484 # remove the old version 492 # run webapp-cleaner instead of emerge
485 # 493 echo
486 # why do we do this? well ... 494 local cleaner="${WEBAPP_CLEANER} -p -C ${PN}"
487 # 495 einfo "Running ${cleaner}"
488 # normally, emerge -u installs a new version and then removes the 496 ${cleaner}
489 # old version. however, if the new version goes into a different
490 # slot to the old version, then the old version gets left behind
491 #
492 # if USE=-vhosts, then we want to remove the old version, because
493 # the user is relying on portage to do the magical thing for it
494
495 if [ "${IS_UPGRADE}" = "1" ] ; then
496 einfo "Removing old version ${REMOVE_PKG}"
497
498 emerge -C "${REMOVE_PKG}"
499 fi
500 else 497 else
501 # vhosts flag is on 498 # vhosts flag is on
502 # 499 #
503 # let's tell the administrator what to do next 500 # let's tell the administrator what to do next
504 501
505 einfo 502 elog
506 einfo "The 'vhosts' USE flag is switched ON" 503 elog "The 'vhosts' USE flag is switched ON"
507 einfo "This means that Portage will not automatically run webapp-config to" 504 elog "This means that Portage will not automatically run webapp-config to"
508 einfo "complete the installation." 505 elog "complete the installation."
509 einfo 506 elog
510 einfo "To install ${PN}-${PVR} into a virtual host, run the following command:" 507 elog "To install ${PN}-${PVR} into a virtual host, run the following command:"
511 einfo 508 elog
512 einfo " webapp-config -I -h <host> -d ${PN} ${PN} ${PVR}" 509 elog " webapp-config -I -h <host> -d ${PN} ${PN} ${PVR}"
513 einfo 510 elog
514 einfo "For more details, see the webapp-config(8) man page" 511 elog "For more details, see the webapp-config(8) man page"
515 fi 512 fi
516 513
517 return 0 514 return 0
518} 515}
519 516

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.47

  ViewVC Help
Powered by ViewVC 1.1.20