| 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.20 2004/05/22 18:56:58 stuart Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.25 2004/06/27 00:30:56 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 |
| … | |
… | |
| 31 | IS_UPGRADE=0 |
31 | IS_UPGRADE=0 |
| 32 | IS_REPLACE=0 |
32 | IS_REPLACE=0 |
| 33 | |
33 | |
| 34 | INSTALL_CHECK_FILE="installed_by_webapp_eclass" |
34 | INSTALL_CHECK_FILE="installed_by_webapp_eclass" |
| 35 | |
35 | |
|
|
36 | ETC_CONFIG="/etc/vhosts/webapp-config" |
|
|
37 | |
| 36 | # ------------------------------------------------------------------------ |
38 | # ------------------------------------------------------------------------ |
| 37 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
39 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
| 38 | # |
40 | # |
| 39 | # Check whether a specified file exists within the image/ directory |
41 | # Check whether a specified file exists within the image/ directory |
| 40 | # or not. |
42 | # or not. |
| … | |
… | |
| 48 | { |
50 | { |
| 49 | local my_prefix |
51 | local my_prefix |
| 50 | |
52 | |
| 51 | [ -n "$2" ] && my_prefix="$2/" || my_prefix= |
53 | [ -n "$2" ] && my_prefix="$2/" || my_prefix= |
| 52 | |
54 | |
| 53 | if [ ! -e ${my_prefix}$1 ]; then |
55 | if [ ! -e "${my_prefix}$1" ]; then |
| 54 | msg="ebuild fault: file $1 not found" |
56 | msg="ebuild fault: file '$1' not found" |
| 55 | eerror "$msg" |
57 | eerror "$msg" |
| 56 | 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/" |
| 57 | die "$msg" |
59 | die "$msg" |
| 58 | fi |
60 | fi |
| 59 | } |
61 | } |
| … | |
… | |
| 64 | |
66 | |
| 65 | function webapp_check_installedat |
67 | function webapp_check_installedat |
| 66 | { |
68 | { |
| 67 | local my_output |
69 | local my_output |
| 68 | |
70 | |
| 69 | /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 |
| 70 | } |
72 | } |
| 71 | |
73 | |
| 72 | # ------------------------------------------------------------------------ |
74 | # ------------------------------------------------------------------------ |
| 73 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
75 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
| 74 | # ------------------------------------------------------------------------ |
76 | # ------------------------------------------------------------------------ |
| … | |
… | |
| 116 | |
118 | |
| 117 | function webapp_configfile () |
119 | function webapp_configfile () |
| 118 | { |
120 | { |
| 119 | webapp_checkfileexists "$1" "$D" |
121 | webapp_checkfileexists "$1" "$D" |
| 120 | echo $1 |
122 | echo $1 |
| 121 | local MY_FILE="`webapp_strip_appdir $1`" |
123 | local MY_FILE="`webapp_strip_appdir \"$1\"`" |
| 122 | echo $MY_FILE |
124 | echo $MY_FILE |
| 123 | |
125 | |
| 124 | einfo "(config) $MY_FILE" |
126 | einfo "(config) $MY_FILE" |
| 125 | echo "$MY_FILE" >> ${D}${WA_CONFIGLIST} |
127 | echo "$MY_FILE" >> ${D}${WA_CONFIGLIST} |
| 126 | } |
128 | } |
| … | |
… | |
| 134 | # @param $1 - the script to run |
136 | # @param $1 - the script to run |
| 135 | # ------------------------------------------------------------------------ |
137 | # ------------------------------------------------------------------------ |
| 136 | |
138 | |
| 137 | function webapp_hook_script () |
139 | function webapp_hook_script () |
| 138 | { |
140 | { |
| 139 | webapp_checkfileexists "$2" |
141 | webapp_checkfileexists "$1" |
| 140 | |
142 | |
| 141 | einfo "(hook) $1" |
143 | einfo "(hook) $1" |
| 142 | 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}/" |
| 143 | chmod 555 "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`" |
145 | chmod 555 "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`" |
| 144 | } |
146 | } |
| … | |
… | |
| 174 | # ------------------------------------------------------------------------ |
176 | # ------------------------------------------------------------------------ |
| 175 | |
177 | |
| 176 | function webapp_runbycgibin () |
178 | function webapp_runbycgibin () |
| 177 | { |
179 | { |
| 178 | webapp_checkfileexists "$2" "$D" |
180 | webapp_checkfileexists "$2" "$D" |
| 179 | local MY_FILE="`webapp_strip_appdir $2`" |
181 | local MY_FILE="`webapp_strip_appdir \"$2\"`" |
| 180 | MY_FILE="`webapp_strip_cwd $MY_FILE`" |
182 | MY_FILE="`webapp_strip_cwd \"$MY_FILE\"`" |
| 181 | |
183 | |
| 182 | einfo "(cgi-bin) $1 - $MY_FILE" |
184 | einfo "(cgi-bin) $1 - $MY_FILE" |
| 183 | echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST} |
185 | echo "\"$1\" \"$MY_FILE\"" >> "${D}${WA_RUNBYCGIBINLIST}" |
| 184 | } |
186 | } |
| 185 | |
187 | |
| 186 | # ------------------------------------------------------------------------ |
188 | # ------------------------------------------------------------------------ |
| 187 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
189 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 188 | # |
190 | # |
| … | |
… | |
| 197 | # ------------------------------------------------------------------------ |
199 | # ------------------------------------------------------------------------ |
| 198 | |
200 | |
| 199 | function webapp_serverowned () |
201 | function webapp_serverowned () |
| 200 | { |
202 | { |
| 201 | webapp_checkfileexists "$1" "$D" |
203 | webapp_checkfileexists "$1" "$D" |
| 202 | local MY_FILE="`webapp_strip_appdir $1`" |
204 | local MY_FILE="`webapp_strip_appdir \"$1\"`" |
| 203 | |
205 | |
| 204 | einfo "(server owned) $MY_FILE" |
206 | einfo "(server owned) $MY_FILE" |
| 205 | echo "$MY_FILE" >> ${D}${WA_SOLIST} |
207 | echo "$MY_FILE" >> "${D}${WA_SOLIST}" |
| 206 | } |
208 | } |
| 207 | |
209 | |
| 208 | # ------------------------------------------------------------------------ |
210 | # ------------------------------------------------------------------------ |
| 209 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
211 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 210 | # |
212 | # |
| … | |
… | |
| 226 | # sort out what the name will be of the config file |
228 | # sort out what the name will be of the config file |
| 227 | |
229 | |
| 228 | local my_file |
230 | local my_file |
| 229 | |
231 | |
| 230 | if [ -z "$3" ]; then |
232 | if [ -z "$3" ]; then |
| 231 | $my_file="$1-`basename $2`" |
233 | my_file="$1-`basename $2`" |
| 232 | else |
234 | else |
| 233 | $my_file="$1-$3" |
235 | my_file="$1-$3" |
| 234 | fi |
236 | fi |
| 235 | |
237 | |
| 236 | # warning: |
238 | # warning: |
| 237 | # |
239 | # |
| 238 | # do NOT change the naming convention used here without changing all |
240 | # do NOT change the naming convention used here without changing all |
| … | |
… | |
| 274 | |
276 | |
| 275 | # are we dealing with an 'upgrade'-type script? |
277 | # are we dealing with an 'upgrade'-type script? |
| 276 | if [ -n "$3" ]; then |
278 | if [ -n "$3" ]; then |
| 277 | # yes we are |
279 | # yes we are |
| 278 | einfo "($1) upgrade script from ${PN}-${PVR} to $3" |
280 | einfo "($1) upgrade script from ${PN}-${PVR} to $3" |
| 279 | cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql |
281 | cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql" |
| 280 | else |
282 | else |
| 281 | # no, we are not |
283 | # no, we are not |
| 282 | einfo "($1) create script for ${PN}-${PVR}" |
284 | einfo "($1) create script for ${PN}-${PVR}" |
| 283 | cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql |
285 | cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql" |
| 284 | fi |
286 | fi |
| 285 | } |
287 | } |
| 286 | |
288 | |
| 287 | # ------------------------------------------------------------------------ |
289 | # ------------------------------------------------------------------------ |
| 288 | # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER |
290 | # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER |
| … | |
… | |
| 293 | # the final version! |
295 | # the final version! |
| 294 | # ------------------------------------------------------------------------ |
296 | # ------------------------------------------------------------------------ |
| 295 | |
297 | |
| 296 | function webapp_src_install () |
298 | function webapp_src_install () |
| 297 | { |
299 | { |
| 298 | chown -R ${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID} ${D}/ |
300 | chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/" |
| 299 | chmod -R u-s ${D}/ |
301 | chmod -R u-s "${D}/" |
| 300 | chmod -R g-s ${D}/ |
302 | chmod -R g-s "${D}/" |
| 301 | |
303 | |
| 302 | keepdir ${MY_PERSISTDIR} |
304 | keepdir "${MY_PERSISTDIR}" |
| 303 | fowners root:root ${MY_PERSISTDIR} |
305 | fowners "root:root" "${MY_PERSISTDIR}" |
| 304 | fperms 755 ${MY_PERSISTDIR} |
306 | fperms 755 "${MY_PERSISTDIR}" |
| 305 | |
307 | |
| 306 | # to test whether or not the ebuild has correctly called this function |
308 | # to test whether or not the ebuild has correctly called this function |
| 307 | # we add an empty file to the filesystem |
309 | # we add an empty file to the filesystem |
| 308 | # |
310 | # |
| 309 | # we used to just set a variable in the shell script, but we can |
311 | # we used to just set a variable in the shell script, but we can |
| 310 | # no longer rely on Portage calling both webapp_src_install() and |
312 | # no longer rely on Portage calling both webapp_src_install() and |
| 311 | # webapp_pkg_postinst() within the same shell process |
313 | # webapp_pkg_postinst() within the same shell process |
| 312 | |
314 | |
| 313 | touch ${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE} |
315 | touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}" |
| 314 | } |
316 | } |
| 315 | |
317 | |
| 316 | # ------------------------------------------------------------------------ |
318 | # ------------------------------------------------------------------------ |
| 317 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER |
319 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER |
| 318 | # everything else has run |
320 | # everything else has run |
| … | |
… | |
| 330 | fi |
332 | fi |
| 331 | |
333 | |
| 332 | # pull in the shared configuration file |
334 | # pull in the shared configuration file |
| 333 | |
335 | |
| 334 | G_HOSTNAME="localhost" |
336 | G_HOSTNAME="localhost" |
| 335 | . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file" |
337 | . "${ETC_CONFIG}" || die "Unable to open file ${ETC_CONFIG}" |
| 336 | |
338 | |
| 337 | # are we installing a webapp-config solution over the top of a |
339 | # are we installing a webapp-config solution over the top of a |
| 338 | # non-webapp-config solution? |
340 | # non-webapp-config solution? |
| 339 | |
341 | |
| 340 | if ! use vhosts ; then |
342 | if ! use vhosts ; then |
| … | |
… | |
| 420 | |
422 | |
| 421 | function webapp_src_preinst () |
423 | function webapp_src_preinst () |
| 422 | { |
424 | { |
| 423 | # create the directories that we need |
425 | # create the directories that we need |
| 424 | |
426 | |
| 425 | dodir ${MY_HTDOCSDIR} |
427 | dodir "${MY_HTDOCSDIR}" |
| 426 | dodir ${MY_HOSTROOTDIR} |
428 | dodir "${MY_HOSTROOTDIR}" |
| 427 | dodir ${MY_CGIBINDIR} |
429 | dodir "${MY_CGIBINDIR}" |
| 428 | dodir ${MY_ICONSDIR} |
430 | dodir "${MY_ICONSDIR}" |
| 429 | dodir ${MY_ERRORSDIR} |
431 | dodir "${MY_ERRORSDIR}" |
| 430 | dodir ${MY_SQLSCRIPTSDIR} |
432 | dodir "${MY_SQLSCRIPTSDIR}" |
|
|
433 | dodir "${MY_HOOKSCRIPTSDIR}" |
| 431 | } |
434 | } |
| 432 | |
435 | |
| 433 | function webapp_pkg_postinst () |
436 | function webapp_pkg_postinst () |
| 434 | { |
437 | { |
|
|
438 | . "${ETC_CONFIG}" |
|
|
439 | |
| 435 | # sanity checks, to catch bugs in the ebuild |
440 | # sanity checks, to catch bugs in the ebuild |
| 436 | |
441 | |
| 437 | if [ ! -f ${MY_APPDIR}/${INSTALL_CHECK_FILE} ]; then |
442 | if [ ! -f "${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]; then |
| 438 | eerror |
443 | eerror |
| 439 | eerror "This ebuild did not call webapp_src_install() at the end" |
444 | eerror "This ebuild did not call webapp_src_install() at the end" |
| 440 | eerror "of the src_install() function" |
445 | eerror "of the src_install() function" |
| 441 | eerror |
446 | eerror |
| 442 | eerror "Please log a bug on http://bugs.gentoo.org" |
447 | eerror "Please log a bug on http://bugs.gentoo.org" |
| … | |
… | |
| 455 | einfo "vhosts USE flag not set - auto-installing using webapp-config" |
460 | einfo "vhosts USE flag not set - auto-installing using webapp-config" |
| 456 | |
461 | |
| 457 | webapp_getinstalltype |
462 | webapp_getinstalltype |
| 458 | |
463 | |
| 459 | G_HOSTNAME="localhost" |
464 | G_HOSTNAME="localhost" |
| 460 | . /etc/vhosts/webapp-config |
465 | . "${ETC_CONFIG}" |
| 461 | |
466 | |
| 462 | local my_mode=-I |
467 | local my_mode=-I |
| 463 | |
468 | |
| 464 | if [ "$IS_REPLACE" = "1" ]; then |
469 | if [ "$IS_REPLACE" = "1" ]; then |
| 465 | einfo "${PN}-${PVR} is already installed - replacing" |
470 | einfo "${PN}-${PVR} is already installed - replacing" |
| … | |
… | |
| 487 | # the user is relying on portage to do the magical thing for it |
492 | # the user is relying on portage to do the magical thing for it |
| 488 | |
493 | |
| 489 | if [ "$IS_UPGRADE" = "1" ] ; then |
494 | if [ "$IS_UPGRADE" = "1" ] ; then |
| 490 | einfo "Removing old version $REMOVE_PKG" |
495 | einfo "Removing old version $REMOVE_PKG" |
| 491 | |
496 | |
| 492 | emerge -C $CATEGORY/$REMOVE_PKG |
497 | emerge -C "$CATEGORY/$REMOVE_PKG" |
| 493 | fi |
498 | fi |
| 494 | else |
499 | else |
| 495 | # vhosts flag is on |
500 | # vhosts flag is on |
| 496 | # |
501 | # |
| 497 | # let's tell the administrator what to do next |
502 | # let's tell the administrator what to do next |