/[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 Revision 1.14
1# Copyright 1999-2003 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.1 2003/10/07 21:54:46 stuart Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.14 2004/05/01 00:45:45 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
13# 13#
14# Please do not make modifications to this file without checking with a 14# Please do not make modifications to this file without checking with a
15# member of the web-apps herd first! 15# member of the web-apps herd first!
16# 16#
17# ------------------------------------------------------------------------ 17# ------------------------------------------------------------------------
18#
19# THIS IS A BETA RELEASE ONLY. ALL DETAILS ARE SUBJECT TO CHANGE BEFORE
20# WE ARE READY TO START PORTING EVERYTHING TO THIS ECLASS
21#
22# ------------------------------------------------------------------------
23 18
24ECLASS=webapp 19ECLASS=webapp
25INHERITED="$INHERITED $ECLASS" 20INHERITED="$INHERITED $ECLASS"
26#DEPEND="${DEPEND} net-www/apache"
27SLOT="${PVR}" 21SLOT="${PVR}"
28IUSE="$IUSE vhosts" 22IUSE="$IUSE vhosts"
23DEPEND="$DEPEND >=net-www/webapp-config-1.7"
29 24
30if [ -f /usr/share/webapp-config/settings.sh ] ; then
31 . /usr/share/webapp-config/settings.sh
32fi
33
34EXPORT_FUNCTIONS pkg_setup src_install 25EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install
26
27INSTALL_DIR="/$PN"
28IS_UPGRADE=0
29IS_REPLACE=0
35 30
36# ------------------------------------------------------------------------ 31# ------------------------------------------------------------------------
37# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 32# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
38# 33#
39# Check whether a specified file exists within the image/ directory 34# Check whether a specified file exists within the image/ directory
40# or not. 35# or not.
41# 36#
42# @param $1 - file to look for 37# @param $1 - file to look for
38# @param $2 - prefix directory to use
43# @return 0 on success, never returns on an error 39# @return 0 on success, never returns on an error
44# ------------------------------------------------------------------------ 40# ------------------------------------------------------------------------
45 41
46function webapp_checkfileexists () 42function webapp_checkfileexists ()
47{ 43{
44 local my_prefix
45
46 [ -n "$2" ] && my_prefix="$2/" || my_prefix=
47
48 if [ ! -e ${D}/$1 ]; then 48 if [ ! -e ${my_prefix}$1 ]; then
49 msg="ebuild fault: file $1 not found in ${D}" 49 msg="ebuild fault: file $1 not found"
50 eerror "$msg" 50 eerror "$msg"
51 eerror "Please report this as a bug at http://bugs.gentoo.org/" 51 eerror "Please report this as a bug at http://bugs.gentoo.org/"
52 die "$msg" 52 die "$msg"
53 fi 53 fi
54}
55
56# ------------------------------------------------------------------------
57# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
58# ------------------------------------------------------------------------
59
60function 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
71function webapp_import_config ()
72{
73 if [ -z "${MY_HTDOCSDIR}" ]; then
74 . /etc/conf.d/webapp-config
75 fi
76
77 if [ -z "${MY_HTDOCSDIR}" ]; then
78 libsh_edie "/etc/conf.d/webapp-config not imported"
79 fi
80}
81
82# ------------------------------------------------------------------------
83# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
84#
85# ------------------------------------------------------------------------
86
87function webapp_strip_appdir ()
88{
89 local my_stripped="$1"
90 echo "$1" | sed -e "s|${MY_APPDIR}/||g;"
91}
92
93function webapp_strip_d ()
94{
95 echo "$1" | sed -e "s|${D}||g;"
96}
97
98function webapp_strip_cwd ()
99{
100 local my_stripped="$1"
101 echo "$1" | sed -e 's|/./|/|g;'
102}
103
104# ------------------------------------------------------------------------
105# EXPORTED FUNCTION - FOR USE IN EBUILDS
106#
107# Identify a config file for a web-based application.
108#
109# @param $1 - config file
110# ------------------------------------------------------------------------
111
112function webapp_configfile ()
113{
114 webapp_checkfileexists "$1" "$D"
115 echo $1
116 local MY_FILE="`webapp_strip_appdir $1`"
117 echo $MY_FILE
118
119 einfo "(config) $MY_FILE"
120 echo "$MY_FILE" >> ${D}${WA_CONFIGLIST}
121}
122
123# ------------------------------------------------------------------------
124# EXPORTED FUNCTION - FOR USE IN EBUILDS
125#
126# Install a text file containing post-installation instructions.
127#
128# @param $1 - language code (use 'en' for now)
129# @param $2 - the file to install
130# ------------------------------------------------------------------------
131
132function webapp_postinst_txt
133{
134 webapp_checkfileexists "$2"
135
136 einfo "(rtfm) $2 (lang: $1)"
137 cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt"
138}
139
140# ------------------------------------------------------------------------
141# EXPORTED FUNCTION - FOR USE IN EBUILDS
142#
143# Identify a script file (usually, but not always PHP or Perl) which is
144#
145# Files in this list may be modified to #! the required CGI engine when
146# installed by webapp-config tool in the future.
147#
148# @param $1 - the cgi engine to use
149# @param $2 - the script file that could run under a cgi-bin
150#
151# ------------------------------------------------------------------------
152
153function webapp_runbycgibin ()
154{
155 webapp_checkfileexists "$2" "$D"
156 local MY_FILE="`webapp_strip_appdir $2`"
157 MY_FILE="`webapp_strip_cwd $MY_FILE`"
158
159 einfo "(cgi-bin) $1 - $MY_FILE"
160 echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST}
54} 161}
55 162
56# ------------------------------------------------------------------------ 163# ------------------------------------------------------------------------
57# EXPORTED FUNCTION - FOR USE IN EBUILDS 164# EXPORTED FUNCTION - FOR USE IN EBUILDS
58# 165#
66# 173#
67# ------------------------------------------------------------------------ 174# ------------------------------------------------------------------------
68 175
69function webapp_serverowned () 176function webapp_serverowned ()
70{ 177{
71 webapp_checkfileexists $1 178 webapp_checkfileexists "$1" "$D"
179 local MY_FILE="`webapp_strip_appdir $1`"
180
181 einfo "(server owned) $MY_FILE"
72 echo "$1" >> $WA_SOLIST 182 echo "$MY_FILE" >> ${D}${WA_SOLIST}
73} 183}
74 184
75# ------------------------------------------------------------------------ 185# ------------------------------------------------------------------------
76# EXPORTED FUNCTION - FOR USE IN EBUILDS 186# EXPORTED FUNCTION - FOR USE IN EBUILDS
77# 187#
78# Identify a config file for a web-based application.
79# 188#
80# @param $1 - config file 189# @param $1 - the db engine that the script is for
190# (one of: mysql|postgres)
191# @param $2 - the sql script to be installed
192# @param $3 - the older version of the app that this db script
193# will upgrade from
194# (do not pass this option if your SQL script only creates
195# a new db from scratch)
81# ------------------------------------------------------------------------ 196# ------------------------------------------------------------------------
82 197
83function webapp_configfile () 198function webapp_sqlscript ()
84{ 199{
85 webapp_checkfileexists $1
86 echo "$1" >> $WA_CONFIGLIST
87}
88
89# ------------------------------------------------------------------------
90# EXPORTED FUNCTION - FOR USE IN EBUILDS
91#
92# Identify a script file (usually, but not always PHP or Perl) which is
93#
94# Files in this list may be modified to #! the required CGI engine when
95# installed by webapp-config tool in the future.
96#
97# @param $1 - the cgi engine to use
98# @param $2 - the script file that could run under a cgi-bin
99#
100# ------------------------------------------------------------------------
101
102function webapp_runbycgibin ()
103{
104 webapp_checkfileexists $2 200 webapp_checkfileexists "$2"
105 echo "$1 $2" >> $WA_RUNBYCGIBINLIST 201
202 # create the directory where this script will go
203 #
204 # scripts for specific database engines go into their own subdirectory
205 # just to keep things readable on the filesystem
206
207 if [ ! -d "${D}${MY_SQLSCRIPTSDIR}/$1" ]; then
208 mkdir -p "${D}${MY_SQLSCRIPTSDIR}/$1" || libsh_die "unable to create directory ${D}${MY_SQLSCRIPTSDIR}/$1"
209 fi
210
211 # warning:
212 #
213 # do NOT change the naming convention used here without changing all
214 # the other scripts that also rely upon these names
215
216 # are we dealing with an 'upgrade'-type script?
217 if [ -n "$3" ]; then
218 # yes we are
219 einfo "($1) upgrade script from ${PN}-${PVR} to $3"
220 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql
221 else
222 # no, we are not
223 einfo "($1) create script for ${PN}-${PVR}"
224 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql
225 fi
106} 226}
107 227
108# ------------------------------------------------------------------------ 228# ------------------------------------------------------------------------
109# EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER 229# EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
110# everything else has run 230# everything else has run
117function webapp_src_install () 237function webapp_src_install ()
118{ 238{
119 chown -R root:root ${D}/ 239 chown -R root:root ${D}/
120 chmod -R u-s ${D}/ 240 chmod -R u-s ${D}/
121 chmod -R g-s ${D}/ 241 chmod -R g-s ${D}/
122}
123 242
243 keepdir ${MY_PERSISTDIR}
244 fowners root:root ${MY_PERSISTDIR}
245 fperms 755 ${MY_PERSISTDIR}
246}
247
124# ------------------------------------------------------------------------ 248# ------------------------------------------------------------------------
125# EXPORTED FUNCTION - call from inside your ebuild's pkg_setup AFTER 249# EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
126# everything else has run 250# everything else has run
127# 251#
128# If 'vhosts' USE flag is not set, auto-install this app 252# If 'vhosts' USE flag is not set, auto-install this app
129# 253#
130# ------------------------------------------------------------------------ 254# ------------------------------------------------------------------------
131 255
132function webapp_pkg_setup () 256function webapp_pkg_setup ()
133{ 257{
134 use vhosts || webapp-config -u root -d /var/www/localhost/htdocs/${PN}/ ${PN} 258 # pull in the shared configuration file
259
260 . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file"
261}
262
263function webapp_getinstalltype ()
264{
265 # are we emerging something that is already installed?
266
267 if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then
268 # yes we are
269 ewarn "Removing existing copy of ${PN}-${PVR}"
270 rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}"
271 fi
272
273 # or are we upgrading?
274
275 if ! use vhosts ; then
276 # we only run webapp-config if vhosts USE flag is not set
277
278 local my_output
279
280 my_output="`webapp_check_installedat`"
281
282 if [ "$?" = "0" ] ; then
283 # something is already installed there
284 #
285 # make sure it isn't the same version
286
287 local my_pn="`echo $my_output | awk '{ print $1 }'`"
288 local my_pvr="`echo $my_output | awk '{ print $2 }'`"
289
290 REMOVE_PKG="${my_pn}-${my_pvr}"
291
292 if [ "$my_pn" == "$PN" ]; then
293 if [ "$my_pvr" != "$PVR" ]; then
294 einfo "This is an upgrade"
295 IS_UPGRADE=1
296 else
297 einfo "This is a re-installation"
298 IS_REPLACE=1
299 fi
300 fi
301 fi
302 fi
303}
304
305function webapp_src_preinst ()
306{
307 # create the directories that we need
308
309 dodir ${MY_HTDOCSDIR}
310 dodir ${MY_HOSTROOTDIR}
311 dodir ${MY_CGIBINDIR}
312 dodir ${MY_ICONSDIR}
313 dodir ${MY_ERRORSDIR}
314 dodir ${MY_SQLSCRIPTSDIR}
315}
316
317function webapp_pkg_postinst ()
318{
319 # if 'vhosts' is not set in your USE flags, we install a copy of
320 # this application in /var/www/localhost/htdocs/${PN}/ for you
321
322 if ! use vhosts ; then
323 echo
324 einfo "vhosts USE flag not set - auto-installing using webapp-config"
325
326 webapp_getinstalltype
327
328 G_HOSTNAME="localhost"
329 . /etc/vhosts/webapp-config
330
331 local my_mode=-I
332
333 if [ "$IS_REPLACE" = "1" ]; then
334 einfo "${PN}-${PVR} is already installed - replacing"
335 /usr/sbin/webapp-config -C -d "$INSTALL_DIR"
336 elif [ "$IS_UPGRADE" = "1" ]; then
337 einfo "$REMOVE_PKG is already installed - upgrading"
338 my_mode=-U
339 else
340 einfo "${PN}-${PVR} is not installed - using install mode"
341 fi
342
343 my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $INSTALL_DIR ${PN} ${PVR}"
344 einfo "Running $my_cmd"
345 $my_cmd
346
347 # remove the old version
348 #
349 # why do we do this? well ...
350 #
351 # normally, emerge -u installs a new version and then removes the
352 # old version. however, if the new version goes into a different
353 # slot to the old version, then the old version gets left behind
354 #
355 # if USE=-vhosts, then we want to remove the old version, because
356 # the user is relying on portage to do the magical thing for it
357
358 if [ "$IS_UPGRADE" = "1" ] ; then
359 einfo "Removing old version $REMOVE_PKG"
360
361 echo emerge -C $CATEGORY/$REMOVE_PKG
362 fi
363 fi
364
365 return 0
366}

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.20