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

Diff of /eclass/webapp.eclass

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

Revision 1.32 Revision 1.66
1# Copyright 1999-2004 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.32 2005/07/06 20:20:04 agriffis Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.66 2011/05/19 12:05:13 scarabeus Exp $
4# 4
5# eclass/webapp.eclass 5# @ECLASS: webapp.eclass
6# @MAINTAINER:
7# web-apps@gentoo.org
6# Eclass for installing applications to run under a web server 8# @BLURB: functions for installing applications to run under a web server
7# 9# @DESCRIPTION:
10# The webapp eclass contains functions to handle web applications with
8# Part of the implementation of GLEP #11 11# webapp-config. Part of the implementation of GLEP #11
9#
10# Author(s) Stuart Herbert <stuart@gentoo.org>
11#
12# ------------------------------------------------------------------------
13#
14# The master copy of this eclass is held in Stu's subversion repository.
15#
16# If you make changes to this file and don't tell Stu, chances are that
17# your changes will be overwritten the next time Stu releases a new version
18# of webapp-config.
19#
20# ------------------------------------------------------------------------
21 12
22INHERITED="$INHERITED $ECLASS" 13# @ECLASS-VARIABLE: WEBAPP_DEPEND
14# @DESCRIPTION:
15# An ebuild should use WEBAPP_DEPEND if a custom DEPEND needs to be built, most
16# notably in combination with WEBAPP_OPTIONAL.
17WEBAPP_DEPEND=">=app-admin/webapp-config-1.50.15"
18
19# @ECLASS-VARIABLE: WEBAPP_NO_AUTO_INSTALL
20# @DESCRIPTION:
21# An ebuild sets this to `yes' if an automatic installation and/or upgrade is
22# not possible. The ebuild should overwrite pkg_postinst() and explain the
23# reason for this BEFORE calling webapp_pkg_postinst().
24
25# @ECLASS-VARIABLE: WEBAPP_OPTIONAL
26# @DESCRIPTION:
27# An ebuild sets this to `yes' to make webapp support optional, in which case
28# you also need to take care of USE-flags and dependencies.
29
30if [[ "${WEBAPP_OPTIONAL}" != "yes" ]]; then
31 [[ "${WEBAPP_NO_AUTO_INSTALL}" == "yes" ]] || IUSE="vhosts"
23SLOT="${PVR}" 32 SLOT="${PVR}"
24IUSE="$IUSE vhosts" 33 DEPEND="${WEBAPP_DEPEND}"
25DEPEND="$DEPEND net-www/webapp-config app-portage/gentoolkit" 34 RDEPEND="${DEPEND}"
35fi
26 36
27EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm 37EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm
28 38
29INSTALL_DIR="/$PN" 39INSTALL_DIR="/${PN}"
30IS_UPGRADE=0 40IS_UPGRADE=0
31IS_REPLACE=0 41IS_REPLACE=0
32 42
33INSTALL_CHECK_FILE="installed_by_webapp_eclass" 43INSTALL_CHECK_FILE="installed_by_webapp_eclass"
44SETUP_CHECK_FILE="setup_by_webapp_eclass"
34 45
35ETC_CONFIG="/etc/vhosts/webapp-config" 46ETC_CONFIG="${ROOT}etc/vhosts/webapp-config"
47WEBAPP_CONFIG="${ROOT}usr/sbin/webapp-config"
48WEBAPP_CLEANER="${ROOT}usr/sbin/webapp-cleaner"
36 49
37# ------------------------------------------------------------------------ 50# ==============================================================================
38# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 51# INTERNAL FUNCTIONS
39# 52# ==============================================================================
53
54# Load the config file /etc/vhosts/webapp-config
55# Supports both the old bash version, and the new python version
56webapp_read_config() {
57 debug-print-function $FUNCNAME $*
58
59 if has_version '>=app-admin/webapp-config-1.50'; then
60 ENVVAR=$(${WEBAPP_CONFIG} --query ${PN} ${PVR}) || die "Could not read settings from webapp-config!"
61 eval ${ENVVAR}
62 else
63 . ${ETC_CONFIG} || die "Unable to read ${ETC_CONFIG}"
64 fi
65}
66
40# Check whether a specified file exists within the image/ directory 67# Check whether a specified file exists in the given directory (`.' by default)
41# or not.
42#
43# @param $1 - file to look for
44# @param $2 - prefix directory to use
45# @return 0 on success, never returns on an error
46# ------------------------------------------------------------------------
47
48function webapp_checkfileexists () 68webapp_checkfileexists() {
49{ 69 debug-print-function $FUNCNAME $*
50 local my_prefix
51 70
52 [ -n "$2" ] && my_prefix="$2/" || my_prefix= 71 local my_prefix=${2:+${2}/}
53 72
54 if [ ! -e "${my_prefix}$1" ]; then 73 if [[ ! -e "${my_prefix}${1}" ]]; then
55 msg="ebuild fault: file '$1' not found" 74 msg="ebuild fault: file '${1}' not found"
56 eerror "$msg" 75 eerror "$msg"
57 eerror "Please report this as a bug at http://bugs.gentoo.org/" 76 eerror "Please report this as a bug at http://bugs.gentoo.org/"
58 die "$msg" 77 die "$msg"
59 fi 78 fi
60} 79}
61 80
62# ------------------------------------------------------------------------
63# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
64# ------------------------------------------------------------------------
65
66function webapp_check_installedat 81webapp_check_installedat() {
67{ 82 debug-print-function $FUNCNAME $*
83 ${WEBAPP_CONFIG} --show-installed -h localhost -d "${INSTALL_DIR}" 2> /dev/null
84}
85
86webapp_strip_appdir() {
87 debug-print-function $FUNCNAME $*
88 echo "${1#${MY_APPDIR}/}"
89}
90
91webapp_strip_d() {
92 debug-print-function $FUNCNAME $*
93 echo "${1#${D}}"
94}
95
96webapp_strip_cwd() {
97 debug-print-function $FUNCNAME $*
98 echo "${1/#.\///}"
99}
100
101webapp_getinstalltype() {
102 debug-print-function $FUNCNAME $*
103
104 if ! has vhosts ${IUSE} || use vhosts; then
105 return
106 fi
107
68 local my_output 108 local my_output
109 my_output="$(webapp_check_installedat)"
69 110
70 /usr/sbin/webapp-config --show-installed -h localhost -d "$INSTALL_DIR" 2> /dev/null 111 if [[ $? -eq 0 ]]; then
71} 112 # something is already installed there
113 # make sure it isn't the same version
72 114
73# ------------------------------------------------------------------------ 115 local my_pn="$(echo ${my_output} | awk '{ print $1 }')"
74# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 116 local my_pvr="$(echo ${my_output} | awk '{ print $2 }')"
75# ------------------------------------------------------------------------
76 117
77function webapp_import_config () 118 REMOVE_PKG="${my_pn}-${my_pvr}"
78{ 119
79 if [ -z "${MY_HTDOCSDIR}" ]; then 120 if [[ "${my_pn}" == "${PN}" ]]; then
80 . /etc/conf.d/webapp-config 121 if [[ "${my_pvr}" != "${PVR}" ]]; then
122 elog "This is an upgrade"
123 IS_UPGRADE=1
124 else
125 elog "This is a re-installation"
126 IS_REPLACE=1
127 fi
128 else
129 elog "${my_output} is installed there"
81 fi 130 fi
82 131 else
83 if [ -z "${MY_HTDOCSDIR}" ]; then 132 elog "This is an installation"
84 libsh_edie "/etc/conf.d/webapp-config not imported"
85 fi 133 fi
86} 134}
87 135
88# ------------------------------------------------------------------------ 136# ==============================================================================
89# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 137# PUBLIC FUNCTIONS
90# 138# ==============================================================================
91# ------------------------------------------------------------------------
92 139
93function webapp_strip_appdir () 140# @FUNCTION: need_httpd
94{ 141# @DESCRIPTION:
95 local my_stripped="$1" 142# Call this function AFTER your ebuilds DEPEND line if any of the available
96 echo "$1" | sed -e "s|${MY_APPDIR}/||g;" 143# webservers are able to run this application.
144need_httpd() {
145 DEPEND="${DEPEND}
146 || ( virtual/httpd-basic virtual/httpd-cgi virtual/httpd-fastcgi )"
97} 147}
98 148
99function webapp_strip_d () 149# @FUNCTION: need_httpd_cgi
100{ 150# @DESCRIPTION:
101 echo "$1" | sed -e "s|${D}||g;" 151# Call this function AFTER your ebuilds DEPEND line if any of the available
152# CGI-capable webservers are able to run this application.
153need_httpd_cgi() {
154 DEPEND="${DEPEND}
155 || ( virtual/httpd-cgi virtual/httpd-fastcgi )"
102} 156}
103 157
104function webapp_strip_cwd () 158# @FUNCTION: need_httpd_fastcgi
105{ 159# @DESCRIPTION:
106 local my_stripped="$1" 160# Call this function AFTER your ebuilds DEPEND line if any of the available
107 echo "$1" | sed -e 's|/./|/|g;' 161# FastCGI-capabale webservers are able to run this application.
162need_httpd_fastcgi() {
163 DEPEND="${DEPEND}
164 virtual/httpd-fastcgi"
108} 165}
109 166
110# ------------------------------------------------------------------------ 167# @FUNCTION: webapp_configfile
111# EXPORTED FUNCTION - FOR USE IN EBUILDS 168# @USAGE: <file> [more files ...]
112# 169# @DESCRIPTION:
113# Identify a config file for a web-based application. 170# Mark a file config-protected for a web-based application.
114#
115# @param $1 - config file
116# ------------------------------------------------------------------------
117
118function webapp_configfile () 171webapp_configfile() {
119{ 172 debug-print-function $FUNCNAME $*
173
174 local m
175 for m in "$@"; do
120 webapp_checkfileexists "$1" "$D" 176 webapp_checkfileexists "${m}" "${D}"
121 177
122 local MY_FILE="`webapp_strip_appdir \"$1\"`" 178 local my_file="$(webapp_strip_appdir "${m}")"
123 MY_FILE="`webapp_strip_cwd \"$MY_FILE\"`" 179 my_file="$(webapp_strip_cwd "${my_file}")"
124 180
125 einfo "(config) $MY_FILE" 181 elog "(config) ${my_file}"
126 echo "$MY_FILE" >> ${D}${WA_CONFIGLIST} 182 echo "${my_file}" >> ${D}/${WA_CONFIGLIST}
183 done
127} 184}
128 185
129# ------------------------------------------------------------------------ 186# @FUNCTION: webapp_hook_script
130# EXPORTED FUNCTION - FOR USE IN EBUILDS 187# @USAGE: <file>
131# 188# @DESCRIPTION:
132# Install a script that will run after a virtual copy is created, and 189# Install a script that will run after a virtual copy is created, and
133# before a virtual copy has been removed 190# before a virtual copy has been removed.
134#
135# @param $1 - the script to run
136# ------------------------------------------------------------------------
137
138function webapp_hook_script () 191webapp_hook_script() {
139{ 192 debug-print-function $FUNCNAME $*
193
140 webapp_checkfileexists "$1" 194 webapp_checkfileexists "${1}"
141 195
142 einfo "(hook) $1" 196 elog "(hook) ${1}"
143 cp "$1" "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`" || die "Unable to install $1 into ${D}${MY_HOOKSCRIPTSDIR}/" 197 cp "${1}" "${D}/${MY_HOOKSCRIPTSDIR}/$(basename "${1}")" || die "Unable to install ${1} into ${D}/${MY_HOOKSCRIPTSDIR}/"
144 chmod 555 "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`" 198 chmod 555 "${D}/${MY_HOOKSCRIPTSDIR}/$(basename "${1}")"
145} 199}
146 200
147# ------------------------------------------------------------------------ 201# @FUNCTION: webapp_postinst_txt
148# EXPORTED FUNCTION - FOR USE IN EBUILDS 202# @USAGE: <lang> <file>
149# 203# @DESCRIPTION:
150# Install a text file containing post-installation instructions. 204# Install a text file containing post-installation instructions.
151#
152# @param $1 - language code (use 'en' for now)
153# @param $2 - the file to install
154# ------------------------------------------------------------------------
155
156function webapp_postinst_txt () 205webapp_postinst_txt() {
157{ 206 debug-print-function $FUNCNAME $*
207
158 webapp_checkfileexists "$2" 208 webapp_checkfileexists "${2}"
159 209
160 einfo "(rtfm) $2 (lang: $1)" 210 elog "(info) ${2} (lang: ${1})"
161 cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt" 211 cp "${2}" "${D}/${MY_APPDIR}/postinst-${1}.txt"
162} 212}
163 213
164# ------------------------------------------------------------------------ 214# @FUNCTION: webapp_postupgrade_txt
165# EXPORTED FUNCTION - FOR USE IN EBUILDS 215# @USAGE: <lang> <file>
166# 216# @DESCRIPTION:
167# Install a text file containing post-upgrade instructions. 217# Install a text file containing post-upgrade instructions.
168#
169# @param $1 - language code (use 'en' for now)
170# @param $2 - the file to install
171# ------------------------------------------------------------------------
172
173function webapp_postupgrade_txt () 218webapp_postupgrade_txt() {
174{ 219 debug-print-function $FUNCNAME $*
220
175 webapp_checkfileexists "$2" 221 webapp_checkfileexists "${2}"
176 222
177 einfo "(rtfm) $2 (lang: $1)" 223 elog "(info) ${2} (lang: ${1})"
178 cp "$2" "${D}${MY_APPDIR}/postupgrade-$1.txt" 224 cp "${2}" "${D}/${MY_APPDIR}/postupgrade-${1}.txt"
179} 225}
180 226
181# ------------------------------------------------------------------------ 227# helper for webapp_serverowned()
182# DEPRECATED FUNCTION 228_webapp_serverowned() {
183# 229 debug-print-function $FUNCNAME $*
184# It never worked anyway
185 230
186function webapp_runbycgibin () 231 webapp_checkfileexists "${1}" "${D}"
187{ 232 local my_file="$(webapp_strip_appdir "${1}")"
188 if [ -n "$WARN_RUNBYCGIBIN" ] ; then 233 my_file="$(webapp_strip_cwd "${my_file}")"
189 return
190 fi
191 234
192 ewarn "This ebuild uses webapp.eclass's webapp_runbycgibin, which is now" 235 elog "(server owned) ${my_file}"
193 ewarn "deprecated. Please file a bug about this in Bugzilla." 236 echo "${my_file}" >> "${D}/${WA_SOLIST}"
194 WARN_RUNBYCGIBIN=1
195} 237}
196 238
197# ------------------------------------------------------------------------ 239# @FUNCTION: webapp_serverowned
198# EXPORTED FUNCTION - FOR USE IN EBUILDS 240# @USAGE: [-R] <file> [more files ...]
199# 241# @DESCRIPTION:
200# Identify a file which must be owned by the webserver's user:group 242# Identify a file which must be owned by the webserver's user:group settings.
201# settings.
202#
203# The ownership of the file is NOT set until the application is installed 243# The ownership of the file is NOT set until the application is installed using
204# using the webapp-config tool. 244# the webapp-config tool. If -R is given directories are handled recursively.
205#
206# @param $1 - file to be owned by the webserver user:group combo
207#
208# ------------------------------------------------------------------------
209
210function webapp_serverowned () 245webapp_serverowned() {
211{ 246 debug-print-function $FUNCNAME $*
212 webapp_checkfileexists "$1" "$D"
213 local MY_FILE="`webapp_strip_appdir \"$1\"`"
214 MY_FILE="`webapp_strip_cwd \"$MY_FILE\"`"
215
216 einfo "(server owned) $MY_FILE"
217 echo "$MY_FILE" >> "${D}${WA_SOLIST}"
218}
219 247
220# ------------------------------------------------------------------------ 248 local a m
221# EXPORTED FUNCTION - FOR USE IN EBUILDS 249 if [[ "${1}" == "-R" ]]; then
222# 250 shift
223# @param $1 - the webserver to install the config file for 251 for m in "$@"; do
224# (one of apache1, apache2, cherokee) 252 find "${D}${m}" | while read a; do
225# @param $2 - the config file to install 253 a=$(webapp_strip_d "${a}")
226# @param $3 - new name for the config file (default is `basename $2`) 254 _webapp_serverowned "${a}"
227# this is an optional parameter 255 done
228# 256 done
229# NOTE:
230# this function will automagically prepend $1 to the front of your
231# config file's name
232# ------------------------------------------------------------------------
233
234function webapp_server_configfile ()
235{
236 webapp_checkfileexists "$2"
237
238 # sort out what the name will be of the config file
239
240 local my_file
241
242 if [ -z "$3" ]; then
243 my_file="$1-`basename $2`"
244 else 257 else
245 my_file="$1-$3" 258 for m in "$@"; do
259 _webapp_serverowned "${m}"
260 done
246 fi 261 fi
262}
247 263
248 # warning: 264# @FUNCTION: webapp_server_configfile
265# @USAGE: <server> <file> [new name]
266# @DESCRIPTION:
267# Install a configuration file for the webserver. You need to specify a
268# webapp-config supported <server>. if no new name is given `basename $2' is
269# used by default. Note: this function will automagically prepend $1 to the
270# front of your config file's name.
271webapp_server_configfile() {
272 debug-print-function $FUNCNAME $*
273
274 webapp_checkfileexists "${2}"
275
276 # WARNING:
249 # 277 #
250 # do NOT change the naming convention used here without changing all 278 # do NOT change the naming convention used here without changing all
251 # the other scripts that also rely upon these names 279 # the other scripts that also rely upon these names
252 280
281 local my_file="${1}-${3:-$(basename "${2}")}"
282
253 einfo "($1) config file '$my_file'" 283 elog "(${1}) config file '${my_file}'"
254 cp "$2" "${D}${MY_SERVERCONFIGDIR}/${my_file}" 284 cp "${2}" "${D}/${MY_SERVERCONFIGDIR}/${my_file}"
255} 285}
256 286
257# ------------------------------------------------------------------------ 287# @FUNCTION: webapp_sqlscript
258# EXPORTED FUNCTION - FOR USE IN EBUILDS 288# @USAGE: <db> <file> [version]
259# 289# @DESCRIPTION:
260# @param $1 - the db engine that the script is for 290# Install a SQL script that creates/upgrades a database schema for the web
261# (one of: mysql|postgres) 291# application. Currently supported database engines are mysql and postgres.
262# @param $2 - the sql script to be installed 292# If a version is given the script should upgrade the database schema from
263# @param $3 - the older version of the app that this db script 293# the given version to $PVR.
264# will upgrade from
265# (do not pass this option if your SQL script only creates
266# a new db from scratch)
267# ------------------------------------------------------------------------
268
269function webapp_sqlscript () 294webapp_sqlscript() {
270{ 295 debug-print-function $FUNCNAME $*
296
271 webapp_checkfileexists "$2" 297 webapp_checkfileexists "${2}"
272 298
273 # create the directory where this script will go 299 dodir "${MY_SQLSCRIPTSDIR}/${1}"
274 #
275 # scripts for specific database engines go into their own subdirectory
276 # just to keep things readable on the filesystem
277 300
278 if [ ! -d "${D}${MY_SQLSCRIPTSDIR}/$1" ]; then 301 # WARNING:
279 mkdir -p "${D}${MY_SQLSCRIPTSDIR}/$1" || libsh_die "unable to create directory ${D}${MY_SQLSCRIPTSDIR}/$1"
280 fi
281
282 # warning:
283 # 302 #
284 # do NOT change the naming convention used here without changing all 303 # do NOT change the naming convention used here without changing all
285 # the other scripts that also rely upon these names 304 # the other scripts that also rely upon these names
286 305
287 # are we dealing with an 'upgrade'-type script?
288 if [ -n "$3" ]; then 306 if [[ -n "${3}" ]]; then
289 # yes we are
290 einfo "($1) upgrade script from ${PN}-${PVR} to $3" 307 elog "(${1}) upgrade script for ${PN}-${3} to ${PVR}"
291 cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql" 308 cp "${2}" "${D}${MY_SQLSCRIPTSDIR}/${1}/${3}_to_${PVR}.sql"
292 chmod 600 "${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql" 309 chmod 600 "${D}${MY_SQLSCRIPTSDIR}/${1}/${3}_to_${PVR}.sql"
293 else 310 else
294 # no, we are not
295 einfo "($1) create script for ${PN}-${PVR}" 311 elog "(${1}) create script for ${PN}-${PVR}"
296 cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql" 312 cp "${2}" "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql"
297 chmod 600 "${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql" 313 chmod 600 "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql"
298 fi
299}
300
301# ------------------------------------------------------------------------
302# EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
303# everything else has run
304#
305# For now, we just make sure that root owns everything, and that there
306# are no setuid files. I'm sure this will change significantly before
307# the final version!
308# ------------------------------------------------------------------------
309
310function webapp_src_install ()
311{
312 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/"
313 chmod -R u-s "${D}/"
314 chmod -R g-s "${D}/"
315
316 keepdir "${MY_PERSISTDIR}"
317 fowners "root:root" "${MY_PERSISTDIR}"
318 fperms 755 "${MY_PERSISTDIR}"
319
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}"
328}
329
330# ------------------------------------------------------------------------
331# EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
332# everything else has run
333#
334# If 'vhosts' USE flag is not set, auto-install this app
335#
336# ------------------------------------------------------------------------
337
338function webapp_pkg_setup ()
339{
340 # add sanity checks here
341
342 if [ "$SLOT+" != "${PVR}+" ]; then
343 die "ebuild sets SLOT, overrides webapp.eclass"
344 fi
345
346 # pull in the shared configuration file
347
348 G_HOSTNAME="localhost"
349 . "${ETC_CONFIG}" || die "Unable to open file ${ETC_CONFIG}"
350
351 # are we installing a webapp-config solution over the top of a
352 # non-webapp-config solution?
353
354 if ! use vhosts ; then
355 local my_dir="$VHOST_ROOT/$MY_HTDOCSBASE/$PN"
356 local my_output
357
358 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`"
363
364 if [ "$?" != "0" ]; then
365
366 # okay, whatever is there, it isn't webapp-config-compatible
367 ewarn
368 ewarn "Whatever is in $my_dir, it's not"
369 ewarn "compatible with webapp-config."
370 ewarn
371 ewarn "This ebuild may be overwriting important files."
372 ewarn
373 elif [ "`echo $my_output | awk '{ print $1 }'`" != "$PN" ]; then
374 eerror "$my_dir contains $my_output"
375 eerror "I cannot upgrade that"
376 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
382 fi 314 fi
383 fi
384} 315}
385 316
386function webapp_someunusedfunction () 317# @FUNCTION: webapp_src_preinst
387{ 318# @DESCRIPTION:
388 # are we emerging something that is already installed? 319# You need to call this function in src_install() BEFORE anything else has run.
320# For now we just create required webapp-config directories.
321webapp_src_preinst() {
322 debug-print-function $FUNCNAME $*
389 323
390 if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then 324 # sanity checks, to catch bugs in the ebuild
391 # yes we are 325 if [[ ! -f "${T}/${SETUP_CHECK_FILE}" ]]; then
392 ewarn "Removing existing copy of ${PN}-${PVR}" 326 eerror
393 rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}" 327 eerror "This ebuild did not call webapp_pkg_setup() at the beginning"
394 fi 328 eerror "of the pkg_setup() function"
395} 329 eerror
396 330 eerror "Please log a bug on http://bugs.gentoo.org"
397function webapp_getinstalltype () 331 eerror
398{ 332 eerror "You should use emerge -C to remove this package, as the"
399 # or are we upgrading? 333 eerror "installation is incomplete"
400 334 eerror
401 if ! use vhosts ; then 335 die "Ebuild did not call webapp_pkg_setup() - report to http://bugs.gentoo.org"
402 # we only run webapp-config if vhosts USE flag is not set
403
404 local my_output
405
406 my_output="`webapp_check_installedat`"
407
408 if [ "$?" = "0" ] ; then
409 # something is already installed there
410 #
411 # make sure it isn't the same version
412
413 local my_pn="`echo $my_output | awk '{ print $1 }'`"
414 local my_pvr="`echo $my_output | awk '{ print $2 }'`"
415
416 REMOVE_PKG="${my_pn}-${my_pvr}"
417
418 if [ "$my_pn" == "$PN" ]; then
419 if [ "$my_pvr" != "$PVR" ]; then
420 einfo "This is an upgrade"
421 IS_UPGRADE=1
422 else
423 einfo "This is a re-installation"
424 IS_REPLACE=1
425 fi
426 else
427 einfo "$my_ouptut is installed there"
428 fi
429 else
430 einfo "This is an installation"
431 fi 336 fi
432 fi
433}
434 337
435function webapp_src_preinst () 338 # Hint, see the webapp_read_config() function to find where these are
436{ 339 # defined.
437 # create the directories that we need
438
439 dodir "${MY_HTDOCSDIR}" 340 dodir "${MY_HTDOCSDIR}"
440 dodir "${MY_HOSTROOTDIR}" 341 dodir "${MY_HOSTROOTDIR}"
441 dodir "${MY_CGIBINDIR}" 342 dodir "${MY_CGIBINDIR}"
442 dodir "${MY_ICONSDIR}" 343 dodir "${MY_ICONSDIR}"
443 dodir "${MY_ERRORSDIR}" 344 dodir "${MY_ERRORSDIR}"
444 dodir "${MY_SQLSCRIPTSDIR}" 345 dodir "${MY_SQLSCRIPTSDIR}"
445 dodir "${MY_HOOKSCRIPTSDIR}" 346 dodir "${MY_HOOKSCRIPTSDIR}"
446 dodir "${MY_SERVERCONFIGDIR}" 347 dodir "${MY_SERVERCONFIGDIR}"
447} 348}
448 349
350# ==============================================================================
351# EXPORTED FUNCTIONS
352# ==============================================================================
353
354# @FUNCTION: webapp_pkg_setup
355# @DESCRIPTION:
356# The default pkg_setup() for this eclass. This will gather required variables
357# from webapp-config and check if there is an application installed to
358# `${ROOT}/var/www/localhost/htdocs/${PN}/' if USE=vhosts is not set.
359#
360# You need to call this function BEFORE anything else has run in your custom
361# pkg_setup().
362webapp_pkg_setup() {
363 debug-print-function $FUNCNAME $*
364
365 # to test whether or not the ebuild has correctly called this function
366 # we add an empty file to the filesystem
367 #
368 # we used to just set a variable in the shell script, but we can
369 # no longer rely on Portage calling both webapp_pkg_setup() and
370 # webapp_src_install() within the same shell process
371 touch "${T}/${SETUP_CHECK_FILE}"
372
373 # special case - some ebuilds *do* need to overwride the SLOT
374 if [[ "${SLOT}+" != "${PVR}+" && "${WEBAPP_MANUAL_SLOT}" != "yes" ]]; then
375 die "Set WEBAPP_MANUAL_SLOT=\"yes\" if you need to SLOT manually"
376 fi
377
378 # pull in the shared configuration file
379 G_HOSTNAME="localhost"
380 webapp_read_config
381
382 local my_dir="${ROOT}${VHOST_ROOT}/${MY_HTDOCSBASE}/${PN}"
383
384 # if USE=vhosts is enabled OR no application is installed we're done here
385 if ! has vhosts ${IUSE} || use vhosts || [[ ! -d "${my_dir}" ]]; then
386 return
387 fi
388
389 local my_output
390 my_output="$(webapp_check_installedat)"
391
392 if [[ $? -ne 0 ]]; then
393 # okay, whatever is there, it isn't webapp-config-compatible
394 echo
395 ewarn
396 ewarn "You already have something installed in ${my_dir}"
397 ewarn
398 ewarn "Whatever is in ${my_dir}, it's not"
399 ewarn "compatible with webapp-config."
400 ewarn
401 ewarn "This ebuild may be overwriting important files."
402 ewarn
403 echo
404 ebeep 10
405 elif [[ "$(echo ${my_output} | awk '{ print $1 }')" != "${PN}" ]]; then
406 echo
407 eerror "You already have ${my_output} installed in ${my_dir}"
408 eerror
409 eerror "I cannot upgrade a different application"
410 eerror
411 echo
412 die "Cannot upgrade contents of ${my_dir}"
413 fi
414
415}
416
417# @FUNCTION: webapp_src_install
418# @DESCRIPTION:
419# This is the default src_install(). For now, we just make sure that root owns
420# everything, and that there are no setuid files.
421#
422# You need to call this function AFTER everything else has run in your custom
423# src_install().
424webapp_src_install() {
425 debug-print-function $FUNCNAME $*
426
427 # to test whether or not the ebuild has correctly called this function
428 # we add an empty file to the filesystem
429 #
430 # we used to just set a variable in the shell script, but we can
431 # no longer rely on Portage calling both webapp_src_install() and
432 # webapp_pkg_postinst() within the same shell process
433 touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}"
434
435 chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/"
436 chmod -R u-s "${D}/"
437 chmod -R g-s "${D}/"
438
439 keepdir "${MY_PERSISTDIR}"
440 fowners "root:0" "${MY_PERSISTDIR}"
441 fperms 755 "${MY_PERSISTDIR}"
442}
443
444# @FUNCTION: webapp_pkg_postinst
445# @DESCRIPTION:
446# The default pkg_postinst() for this eclass. This installs the web application to
447# `${ROOT}/var/www/localhost/htdocs/${PN}/' if USE=vhosts is not set. Otherwise
448# display a short notice how to install this application with webapp-config.
449#
450# You need to call this function AFTER everything else has run in your custom
451# pkg_postinst().
449function webapp_pkg_postinst () 452webapp_pkg_postinst() {
450{ 453 debug-print-function $FUNCNAME $*
451 . "${ETC_CONFIG}" 454
455 webapp_read_config
452 456
453 # sanity checks, to catch bugs in the ebuild 457 # sanity checks, to catch bugs in the ebuild
454
455 if [ ! -f "${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]; then 458 if [[ ! -f "${ROOT}${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]]; then
456 eerror 459 eerror
457 eerror "This ebuild did not call webapp_src_install() at the end" 460 eerror "This ebuild did not call webapp_src_install() at the end"
458 eerror "of the src_install() function" 461 eerror "of the src_install() function"
459 eerror 462 eerror
460 eerror "Please log a bug on http://bugs.gentoo.org" 463 eerror "Please log a bug on http://bugs.gentoo.org"
463 eerror "installation is incomplete" 466 eerror "installation is incomplete"
464 eerror 467 eerror
465 die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org" 468 die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org"
466 fi 469 fi
467 470
468 # if 'vhosts' is not set in your USE flags, we install a copy of 471 if has vhosts ${IUSE}; then
469 # this application in /var/www/localhost/htdocs/${PN}/ for you
470
471 if ! use vhosts ; then 472 if ! use vhosts; then
472 echo 473 echo
473 einfo "vhosts USE flag not set - auto-installing using webapp-config" 474 elog "vhosts USE flag not set - auto-installing using webapp-config"
474 475
475 webapp_getinstalltype
476
477 G_HOSTNAME="localhost" 476 G_HOSTNAME="localhost"
478 . "${ETC_CONFIG}" 477 webapp_read_config
479 478
480 local my_mode=-I 479 local my_mode=-I
480 webapp_getinstalltype
481 481
482 if [ "$IS_REPLACE" = "1" ]; then 482 if [[ "${IS_REPLACE}" == "1" ]]; then
483 einfo "${PN}-${PVR} is already installed - replacing" 483 elog "${PN}-${PVR} is already installed - replacing"
484 my_mode=-I 484 my_mode=-I
485 elif [ "$IS_UPGRADE" = "1" ]; then 485 elif [[ "${IS_UPGRADE}" == "1" ]]; then
486 einfo "$REMOVE_PKG is already installed - upgrading" 486 elog "${REMOVE_PKG} is already installed - upgrading"
487 my_mode=-U 487 my_mode=-U
488 else
489 elog "${PN}-${PVR} is not installed - using install mode"
490 fi
491
492 my_cmd="${WEBAPP_CONFIG} ${my_mode} -h localhost -u root -d ${INSTALL_DIR} ${PN} ${PVR}"
493 elog "Running ${my_cmd}"
494 ${my_cmd}
495
496 echo
497 local cleaner="${WEBAPP_CLEANER} -p -C ${PN}"
498 einfo "Running ${cleaner}"
499 ${cleaner}
488 else 500 else
489 einfo "${PN}-${PVR} is not installed - using install mode" 501 elog
490 fi 502 elog "The 'vhosts' USE flag is switched ON"
491 503 elog "This means that Portage will not automatically run webapp-config to"
492 my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $INSTALL_DIR ${PN} ${PVR}" 504 elog "complete the installation."
493 einfo "Running $my_cmd" 505 elog
494 $my_cmd 506 elog "To install ${PN}-${PVR} into a virtual host, run the following command:"
495 507 elog
496 # remove the old version 508 elog " webapp-config -I -h <host> -d ${PN} ${PN} ${PVR}"
497 # 509 elog
498 # why do we do this? well ... 510 elog "For more details, see the webapp-config(8) man page"
499 #
500 # normally, emerge -u installs a new version and then removes the
501 # old version. however, if the new version goes into a different
502 # slot to the old version, then the old version gets left behind
503 #
504 # if USE=-vhosts, then we want to remove the old version, because
505 # the user is relying on portage to do the magical thing for it
506
507 if [ "$IS_UPGRADE" = "1" ] ; then
508 einfo "Removing old version $REMOVE_PKG"
509
510 emerge -C "$REMOVE_PKG"
511 fi 511 fi
512 else 512 else
513 # vhosts flag is on 513 elog
514 # 514 elog "This ebuild does not support the 'vhosts' USE flag."
515 # let's tell the administrator what to do next
516
517 einfo
518 einfo "The 'vhosts' USE flag is switched ON"
519 einfo "This means that Portage will not automatically run webapp-config to" 515 elog "This means that Portage will not automatically run webapp-config to"
520 einfo "complete the installation." 516 elog "complete the installation."
521 einfo 517 elog
522 einfo "To install $PN-$PVR into a virtual host, run the following command:" 518 elog "To install ${PN}-${PVR} into a virtual host, run the following command:"
523 einfo 519 elog
524 einfo " webapp-config -I -h <host> -d $PN $PN $PVR" 520 elog " webapp-config -I -h <host> -d ${PN} ${PN} ${PVR}"
525 einfo 521 elog
526 einfo "For more details, see the webapp-config(8) man page" 522 elog "For more details, see the webapp-config(8) man page"
527 fi 523 fi
528
529 return 0
530} 524}
531 525
526# @FUNCTION: webapp_pkg_prerm
527# @DESCRIPTION:
528# This is the default pkg_prerm() for this eclass. If USE=vhosts is not set
529# remove all installed copies of this web application. Otherwise instruct the
530# user to manually remove those copies. See bug #136959.
532function webapp_pkg_prerm () 531webapp_pkg_prerm() {
533{ 532 debug-print-function $FUNCNAME $*
534 # remove any virtual installs that there are
535 533
536 local my_output 534 local my_output=
535 my_output="$(${WEBAPP_CONFIG} --list-installs ${PN} ${PVR})"
536 [[ $? -ne 0 ]] && return
537
537 local x 538 local x
538 539 if has vhosts ${IUSE} && ! use vhosts; then
539 my_output="`webapp-config --list-installs $PN $PVR`" 540 echo "${my_output}" | while read x; do
540 541 if [[ -f "${x}"/.webapp ]]; then
541 if [ "$?" != "0" ]; then 542 . "${x}"/.webapp
542 return
543 fi
544
545 # the changes to IFS here are necessary to ensure that we can cope
546 # with directories that contain spaces in the file names
547
548 # OLD_IFS="$IFS"
549 # IFS=" "
550
551 for x in $my_output ; do
552 # IFS="$OLD_IFS"
553
554 [ -f $x/.webapp ] && . $x/.webapp || ewarn "Cannot find file $x/.webapp"
555
556 if [ -z "WEB_HOSTNAME" -o -z "WEB_INSTALLDIR" ]; then 543 if [[ -n "${WEB_HOSTNAME}" && -n "${WEB_INSTALLDIR}" ]]; then
544 ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR}
545 fi
546 else
547 ewarn "Cannot find file ${x}/.webapp"
548 fi
549 done
550 elif [[ "${my_output}" != "" ]]; then
551 echo
552 ewarn
557 ewarn "Don't forget to use webapp-config to remove the copy of" 553 ewarn "Don't forget to use webapp-config to remove any copies of"
558 ewarn "${PN}-${PVR} installed in" 554 ewarn "${PN}-${PVR} installed in"
559 ewarn 555 ewarn
556
557 echo "${my_output}" | while read x; do
558 if [[ -f "${x}"/.webapp ]]; then
560 ewarn " $x" 559 ewarn " ${x}"
560 else
561 ewarn "Cannot find file ${x}/.webapp"
562 fi
563 done
564
561 ewarn 565 ewarn
562 else 566 echo
563 # we have enough information to remove the virtual copy ourself
564
565 webapp-config -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR}
566
567 # if the removal fails - we carry on anyway!
568 fi 567 fi
569 # IFS=" "
570 done
571
572 # IFS="$OLD_IFS"
573} 568}

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

  ViewVC Help
Powered by ViewVC 1.1.20