| 1 | # Copyright 1999-2004 Gentoo Technologies, Inc. |
1 | # Copyright 1999-2004 Gentoo Technologies, Inc. |
| 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.13 2004/04/30 08:25:38 stuart Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.16 2004/05/10 17:46:42 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 |
| … | |
… | |
| 18 | |
18 | |
| 19 | ECLASS=webapp |
19 | ECLASS=webapp |
| 20 | INHERITED="$INHERITED $ECLASS" |
20 | INHERITED="$INHERITED $ECLASS" |
| 21 | SLOT="${PVR}" |
21 | SLOT="${PVR}" |
| 22 | IUSE="$IUSE vhosts" |
22 | IUSE="$IUSE vhosts" |
| 23 | DEPEND="$DEPEND >=net-www/webapp-config-1.6" |
23 | DEPEND="$DEPEND >=net-www/webapp-config-1.7" |
| 24 | |
24 | |
| 25 | EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install |
25 | EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install |
|
|
26 | |
|
|
27 | INSTALL_DIR="/$PN" |
|
|
28 | IS_UPGRADE=0 |
|
|
29 | IS_REPLACE=0 |
| 26 | |
30 | |
| 27 | # ------------------------------------------------------------------------ |
31 | # ------------------------------------------------------------------------ |
| 28 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
32 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
| 29 | # |
33 | # |
| 30 | # Check whether a specified file exists within the image/ directory |
34 | # Check whether a specified file exists within the image/ directory |
| … | |
… | |
| 51 | |
55 | |
| 52 | # ------------------------------------------------------------------------ |
56 | # ------------------------------------------------------------------------ |
| 53 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
57 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
| 54 | # ------------------------------------------------------------------------ |
58 | # ------------------------------------------------------------------------ |
| 55 | |
59 | |
|
|
60 | function webapp_check_installedat |
|
|
61 | { |
|
|
62 | local my_output |
|
|
63 | |
|
|
64 | /usr/sbin/webapp-config --show-installed -h localhost -d $INSTALL_DIR 2> /dev/null |
|
|
65 | } |
|
|
66 | |
|
|
67 | # ------------------------------------------------------------------------ |
|
|
68 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
|
|
69 | # ------------------------------------------------------------------------ |
|
|
70 | |
| 56 | function webapp_import_config () |
71 | function webapp_import_config () |
| 57 | { |
72 | { |
| 58 | if [ -z "${MY_HTDOCSDIR}" ]; then |
73 | if [ -z "${MY_HTDOCSDIR}" ]; then |
| 59 | . /etc/conf.d/webapp-config |
74 | . /etc/conf.d/webapp-config |
| 60 | fi |
75 | fi |
| … | |
… | |
| 69 | # |
84 | # |
| 70 | # ------------------------------------------------------------------------ |
85 | # ------------------------------------------------------------------------ |
| 71 | |
86 | |
| 72 | function webapp_strip_appdir () |
87 | function webapp_strip_appdir () |
| 73 | { |
88 | { |
|
|
89 | local my_stripped="$1" |
| 74 | echo "$1" | sed -e "s|${MY_APPDIR}/||g;" |
90 | echo "$1" | sed -e "s|${MY_APPDIR}/||g;" |
| 75 | } |
91 | } |
| 76 | |
92 | |
| 77 | function webapp_strip_d () |
93 | function webapp_strip_d () |
| 78 | { |
94 | { |
| 79 | echo "$1" | sed -e "s|${D}||g;" |
95 | echo "$1" | sed -e "s|${D}||g;" |
| 80 | } |
96 | } |
| 81 | |
97 | |
| 82 | function webapp_strip_cwd () |
98 | function webapp_strip_cwd () |
| 83 | { |
99 | { |
|
|
100 | local my_stripped="$1" |
| 84 | echo "$1" | sed -e 's|/./|/|g;' |
101 | echo "$1" | sed -e 's|/./|/|g;' |
| 85 | } |
102 | } |
| 86 | |
103 | |
| 87 | # ------------------------------------------------------------------------ |
104 | # ------------------------------------------------------------------------ |
| 88 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
105 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| … | |
… | |
| 224 | chmod -R g-s ${D}/ |
241 | chmod -R g-s ${D}/ |
| 225 | |
242 | |
| 226 | keepdir ${MY_PERSISTDIR} |
243 | keepdir ${MY_PERSISTDIR} |
| 227 | fowners root:root ${MY_PERSISTDIR} |
244 | fowners root:root ${MY_PERSISTDIR} |
| 228 | fperms 755 ${MY_PERSISTDIR} |
245 | fperms 755 ${MY_PERSISTDIR} |
|
|
246 | |
|
|
247 | HAS_webapp_src_install=1 |
| 229 | } |
248 | } |
| 230 | |
249 | |
| 231 | # ------------------------------------------------------------------------ |
250 | # ------------------------------------------------------------------------ |
| 232 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER |
251 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER |
| 233 | # everything else has run |
252 | # everything else has run |
| … | |
… | |
| 236 | # |
255 | # |
| 237 | # ------------------------------------------------------------------------ |
256 | # ------------------------------------------------------------------------ |
| 238 | |
257 | |
| 239 | function webapp_pkg_setup () |
258 | function webapp_pkg_setup () |
| 240 | { |
259 | { |
|
|
260 | # add sanity checks here |
|
|
261 | |
|
|
262 | if [ "$SLOT+" != "${PVR}+" ]; then |
|
|
263 | die "ebuild sets SLOT, overrides webapp.eclass" |
|
|
264 | fi |
|
|
265 | |
| 241 | # pull in the shared configuration file |
266 | # pull in the shared configuration file |
| 242 | |
267 | |
| 243 | . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file" |
268 | . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file" |
|
|
269 | } |
| 244 | |
270 | |
|
|
271 | function webapp_getinstalltype () |
|
|
272 | { |
| 245 | # are we emerging something that is already installed? |
273 | # are we emerging something that is already installed? |
| 246 | |
274 | |
| 247 | if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then |
275 | if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then |
| 248 | # yes we are |
276 | # yes we are |
| 249 | ewarn "Removing existing copy of ${PN}-${PVR}" |
277 | ewarn "Removing existing copy of ${PN}-${PVR}" |
| 250 | rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}" |
278 | rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}" |
|
|
279 | fi |
|
|
280 | |
|
|
281 | # or are we upgrading? |
|
|
282 | |
|
|
283 | if ! use vhosts ; then |
|
|
284 | # we only run webapp-config if vhosts USE flag is not set |
|
|
285 | |
|
|
286 | local my_output |
|
|
287 | |
|
|
288 | my_output="`webapp_check_installedat`" |
|
|
289 | |
|
|
290 | if [ "$?" = "0" ] ; then |
|
|
291 | # something is already installed there |
|
|
292 | # |
|
|
293 | # make sure it isn't the same version |
|
|
294 | |
|
|
295 | local my_pn="`echo $my_output | awk '{ print $1 }'`" |
|
|
296 | local my_pvr="`echo $my_output | awk '{ print $2 }'`" |
|
|
297 | |
|
|
298 | REMOVE_PKG="${my_pn}-${my_pvr}" |
|
|
299 | |
|
|
300 | if [ "$my_pn" == "$PN" ]; then |
|
|
301 | if [ "$my_pvr" != "$PVR" ]; then |
|
|
302 | einfo "This is an upgrade" |
|
|
303 | IS_UPGRADE=1 |
|
|
304 | else |
|
|
305 | einfo "This is a re-installation" |
|
|
306 | IS_REPLACE=1 |
|
|
307 | fi |
|
|
308 | fi |
|
|
309 | fi |
| 251 | fi |
310 | fi |
| 252 | } |
311 | } |
| 253 | |
312 | |
| 254 | function webapp_src_preinst () |
313 | function webapp_src_preinst () |
| 255 | { |
314 | { |
| … | |
… | |
| 263 | dodir ${MY_SQLSCRIPTSDIR} |
322 | dodir ${MY_SQLSCRIPTSDIR} |
| 264 | } |
323 | } |
| 265 | |
324 | |
| 266 | function webapp_pkg_postinst () |
325 | function webapp_pkg_postinst () |
| 267 | { |
326 | { |
| 268 | einfo "webapp_pkg_postinst() called" |
327 | # sanity checks, to catch bugs in the ebuild |
|
|
328 | |
|
|
329 | if [ "$HAS_webapp_src_install+" == "+" ]; then |
|
|
330 | eerror |
|
|
331 | eerror "This ebuild did not call webapp_src_install() at the end" |
|
|
332 | eerror "of the src_install() function" |
|
|
333 | eerror |
|
|
334 | eerror "Please log a bug on http://bugs.gentoo.org" |
|
|
335 | eerror |
|
|
336 | eerror "You should use emerge -C to remove this package, as the" |
|
|
337 | eerror "installation is incomplete" |
|
|
338 | eerror |
|
|
339 | die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org" |
|
|
340 | fi |
| 269 | |
341 | |
| 270 | # if 'vhosts' is not set in your USE flags, we install a copy of |
342 | # if 'vhosts' is not set in your USE flags, we install a copy of |
| 271 | # this application in /var/www/localhost/htdocs/${PN}/ for you |
343 | # this application in /var/www/localhost/htdocs/${PN}/ for you |
| 272 | |
|
|
| 273 | |
344 | |
| 274 | if ! use vhosts ; then |
345 | if ! use vhosts ; then |
|
|
346 | echo |
| 275 | einfo "vhosts USE flag not set - auto-installing using webapp-config" |
347 | einfo "vhosts USE flag not set - auto-installing using webapp-config" |
|
|
348 | |
|
|
349 | webapp_getinstalltype |
| 276 | |
350 | |
| 277 | G_HOSTNAME="localhost" |
351 | G_HOSTNAME="localhost" |
| 278 | . /etc/vhosts/webapp-config |
352 | . /etc/vhosts/webapp-config |
| 279 | |
353 | |
| 280 | local my_mode=-I |
354 | local my_mode=-I |
| 281 | local my_dir="/${PN}" |
|
|
| 282 | |
355 | |
| 283 | # are we installing afresh - or are we upgrading? |
|
|
| 284 | # find out by looking to see what (if anything) is installed |
|
|
| 285 | # in there already |
|
|
| 286 | |
|
|
| 287 | my_cmd="/usr/sbin/webapp-config --show-installed -d $my_dir 2> /dev/null" |
|
|
| 288 | einfo "$my_cmd" |
|
|
| 289 | |
|
|
| 290 | my_output="`/usr/sbin/webapp-config --show-installed -d $my_dir 2> /dev/null`" |
|
|
| 291 | |
|
|
| 292 | # we can't use the exit status from webapp-config |
|
|
| 293 | |
|
|
| 294 | if [ "$?" = "0" ]; then |
356 | if [ "$IS_REPLACE" = "1" ]; then |
| 295 | |
357 | einfo "${PN}-${PVR} is already installed - replacing" |
| 296 | # something is in there - but the question has to be ... what? |
|
|
| 297 | |
|
|
| 298 | ewarn "$my_output already installed" |
|
|
| 299 | |
|
|
| 300 | if [ "`echo $my_output | awk '{ print $1 }'`" = "${PN}" ]; then |
|
|
| 301 | einfo "$my_output is a copy of ${PN}" |
|
|
| 302 | if [ "`echo $my_output | awk '{ print $2 }'`" = "${PVR}" ]; then |
|
|
| 303 | # this version is already installed |
|
|
| 304 | # we need to remove it first |
|
|
| 305 | |
|
|
| 306 | /usr/sbin/webapp-config -C -d $my_dir |
358 | /usr/sbin/webapp-config -C -d "$INSTALL_DIR" |
| 307 | else |
359 | elif [ "$IS_UPGRADE" = "1" ]; then |
| 308 | # we have an older version of whatever it is our ebuild is |
360 | einfo "$REMOVE_PKG is already installed - upgrading" |
| 309 | # trying to install ;-) |
|
|
| 310 | # |
|
|
| 311 | # this is the situation we can deal with |
|
|
| 312 | |
|
|
| 313 | einfo "selecting upgrade mode" |
|
|
| 314 | my_mode=-U |
361 | my_mode=-U |
| 315 | fi |
|
|
| 316 | else |
|
|
| 317 | # this should never happen - but just in case ... |
|
|
| 318 | # |
|
|
| 319 | # whatever is in that directory, it isn't the application |
|
|
| 320 | # that we are currently trying to install |
|
|
| 321 | # |
|
|
| 322 | # rather than overwrite the contents, we bail with an error |
|
|
| 323 | # instead |
|
|
| 324 | |
|
|
| 325 | die "$my_output is already installed in $my_dir" |
|
|
| 326 | fi |
|
|
| 327 | else |
362 | else |
| 328 | einfo "${PN}-${PVR} is not installed - using install mode" |
363 | einfo "${PN}-${PVR} is not installed - using install mode" |
| 329 | fi |
364 | fi |
| 330 | |
365 | |
| 331 | my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $my_dir ${PN} ${PVR}" |
366 | my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $INSTALL_DIR ${PN} ${PVR}" |
| 332 | einfo "Running $my_cmd" |
367 | einfo "Running $my_cmd" |
| 333 | $my_cmd |
368 | $my_cmd |
|
|
369 | |
|
|
370 | # remove the old version |
|
|
371 | # |
|
|
372 | # why do we do this? well ... |
|
|
373 | # |
|
|
374 | # normally, emerge -u installs a new version and then removes the |
|
|
375 | # old version. however, if the new version goes into a different |
|
|
376 | # slot to the old version, then the old version gets left behind |
|
|
377 | # |
|
|
378 | # if USE=-vhosts, then we want to remove the old version, because |
|
|
379 | # the user is relying on portage to do the magical thing for it |
|
|
380 | |
|
|
381 | if [ "$IS_UPGRADE" = "1" ] ; then |
|
|
382 | einfo "Removing old version $REMOVE_PKG" |
|
|
383 | |
|
|
384 | echo emerge -C $CATEGORY/$REMOVE_PKG |
|
|
385 | fi |
| 334 | fi |
386 | fi |
| 335 | |
387 | |
| 336 | return 0 |
388 | return 0 |
| 337 | } |
389 | } |