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

Contents of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide annotations) (download)
Thu Apr 29 13:53:24 2004 UTC (10 years, 5 months ago) by stuart
Branch: MAIN
Changes since 1.11: +1 -1 lines
Fix for the missing -h localhost switch (again - grrr)

1 stuart 1.10 # Copyright 1999-2004 Gentoo Technologies, Inc.
2 stuart 1.1 # Distributed under the terms of the GNU General Public License v2
3 stuart 1.9 # $Header: /home/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.8 2004/04/23 14:19:35 stuart Exp $
4 stuart 1.1 #
5     # eclass/webapp.eclass
6     # Eclass for installing applications to run under a web server
7     #
8     # Part of the implementation of GLEP #11
9     #
10     # Author(s) Stuart Herbert <stuart@gentoo.org>
11     #
12     # ------------------------------------------------------------------------
13     #
14     # Please do not make modifications to this file without checking with a
15     # member of the web-apps herd first!
16     #
17     # ------------------------------------------------------------------------
18    
19     ECLASS=webapp
20     INHERITED="$INHERITED $ECLASS"
21     SLOT="${PVR}"
22     IUSE="$IUSE vhosts"
23 stuart 1.10 DEPEND="$DEPEND >=net-www/webapp-config-1.5"
24 stuart 1.1
25 stuart 1.5 EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install
26 stuart 1.1
27     # ------------------------------------------------------------------------
28     # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
29     #
30     # Check whether a specified file exists within the image/ directory
31     # or not.
32     #
33     # @param $1 - file to look for
34 stuart 1.3 # @param $2 - prefix directory to use
35 stuart 1.1 # @return 0 on success, never returns on an error
36     # ------------------------------------------------------------------------
37    
38     function webapp_checkfileexists ()
39     {
40 stuart 1.9 local my_prefix
41    
42     [ -n "$2" ] && my_prefix="$2/" || my_prefix=
43    
44     if [ ! -e ${my_prefix}$1 ]; then
45 stuart 1.3 msg="ebuild fault: file $1 not found"
46 stuart 1.1 eerror "$msg"
47     eerror "Please report this as a bug at http://bugs.gentoo.org/"
48     die "$msg"
49     fi
50     }
51    
52     # ------------------------------------------------------------------------
53 stuart 1.3 # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
54     # ------------------------------------------------------------------------
55    
56     function webapp_import_config ()
57     {
58     if [ -z "${MY_HTDOCSDIR}" ]; then
59     . /etc/conf.d/webapp-config
60     fi
61    
62     if [ -z "${MY_HTDOCSDIR}" ]; then
63     libsh_edie "/etc/conf.d/webapp-config not imported"
64     fi
65     }
66    
67     # ------------------------------------------------------------------------
68     # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
69 stuart 1.1 #
70     # ------------------------------------------------------------------------
71    
72 stuart 1.3 function webapp_strip_appdir ()
73     {
74 stuart 1.11 echo "$1" | sed -e "s|${MY_APPDIR}/||g;"
75 stuart 1.3 }
76    
77     function webapp_strip_d ()
78     {
79     echo "$1" | sed -e "s|${D}||g;"
80     }
81    
82     function webapp_strip_cwd ()
83 stuart 1.1 {
84 stuart 1.3 echo "$1" | sed -e 's|/./|/|g;'
85 stuart 1.1 }
86    
87     # ------------------------------------------------------------------------
88     # EXPORTED FUNCTION - FOR USE IN EBUILDS
89     #
90     # Identify a config file for a web-based application.
91     #
92     # @param $1 - config file
93     # ------------------------------------------------------------------------
94    
95     function webapp_configfile ()
96     {
97 stuart 1.3 webapp_checkfileexists "$1" "$D"
98 stuart 1.11 echo $1
99 stuart 1.3 local MY_FILE="`webapp_strip_appdir $1`"
100 stuart 1.11 echo $MY_FILE
101 stuart 1.3
102     einfo "(config) $MY_FILE"
103 stuart 1.8 echo "$MY_FILE" >> ${D}${WA_CONFIGLIST}
104 stuart 1.1 }
105    
106     # ------------------------------------------------------------------------
107     # EXPORTED FUNCTION - FOR USE IN EBUILDS
108     #
109 stuart 1.5 # Install a text file containing post-installation instructions.
110     #
111     # @param $1 - language code (use 'en' for now)
112     # @param $2 - the file to install
113     # ------------------------------------------------------------------------
114    
115     function webapp_postinst_txt
116     {
117     webapp_checkfileexists "$2"
118    
119     einfo "(rtfm) $2 (lang: $1)"
120 stuart 1.8 cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt"
121 stuart 1.5 }
122    
123     # ------------------------------------------------------------------------
124     # EXPORTED FUNCTION - FOR USE IN EBUILDS
125     #
126 stuart 1.1 # Identify a script file (usually, but not always PHP or Perl) which is
127     #
128     # Files in this list may be modified to #! the required CGI engine when
129     # installed by webapp-config tool in the future.
130     #
131     # @param $1 - the cgi engine to use
132     # @param $2 - the script file that could run under a cgi-bin
133     #
134     # ------------------------------------------------------------------------
135    
136     function webapp_runbycgibin ()
137     {
138 stuart 1.3 webapp_checkfileexists "$2" "$D"
139     local MY_FILE="`webapp_strip_appdir $2`"
140     MY_FILE="`webapp_strip_cwd $MY_FILE`"
141    
142     einfo "(cgi-bin) $1 - $MY_FILE"
143 stuart 1.8 echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST}
144 stuart 1.3 }
145    
146     # ------------------------------------------------------------------------
147     # EXPORTED FUNCTION - FOR USE IN EBUILDS
148     #
149     # Identify a file which must be owned by the webserver's user:group
150     # settings.
151     #
152     # The ownership of the file is NOT set until the application is installed
153     # using the webapp-config tool.
154     #
155     # @param $1 - file to be owned by the webserver user:group combo
156     #
157     # ------------------------------------------------------------------------
158    
159     function webapp_serverowned ()
160     {
161     webapp_checkfileexists "$1" "$D"
162     local MY_FILE="`webapp_strip_appdir $1`"
163    
164     einfo "(server owned) $MY_FILE"
165 stuart 1.8 echo "$MY_FILE" >> ${D}${WA_SOLIST}
166 stuart 1.3 }
167    
168     # ------------------------------------------------------------------------
169     # EXPORTED FUNCTION - FOR USE IN EBUILDS
170     #
171     #
172     # @param $1 - the db engine that the script is for
173     # (one of: mysql|postgres)
174     # @param $2 - the sql script to be installed
175     # @param $3 - the older version of the app that this db script
176     # will upgrade from
177     # (do not pass this option if your SQL script only creates
178     # a new db from scratch)
179     # ------------------------------------------------------------------------
180    
181     function webapp_sqlscript ()
182     {
183     webapp_checkfileexists "$2"
184    
185     # create the directory where this script will go
186     #
187     # scripts for specific database engines go into their own subdirectory
188     # just to keep things readable on the filesystem
189    
190 stuart 1.8 if [ ! -d "${D}${MY_SQLSCRIPTSDIR}/$1" ]; then
191     mkdir -p "${D}${MY_SQLSCRIPTSDIR}/$1" || libsh_die "unable to create directory ${D}${MY_SQLSCRIPTSDIR}/$1"
192 stuart 1.3 fi
193    
194     # warning:
195     #
196     # do NOT change the naming convention used here without changing all
197     # the other scripts that also rely upon these names
198    
199     # are we dealing with an 'upgrade'-type script?
200     if [ -n "$3" ]; then
201     # yes we are
202     einfo "($1) upgrade script from ${PN}-${PVR} to $3"
203 stuart 1.8 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql
204 stuart 1.3 else
205     # no, we are not
206     einfo "($1) create script for ${PN}-${PVR}"
207 stuart 1.8 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql
208 stuart 1.3 fi
209 stuart 1.1 }
210    
211     # ------------------------------------------------------------------------
212     # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
213     # everything else has run
214     #
215     # For now, we just make sure that root owns everything, and that there
216     # are no setuid files. I'm sure this will change significantly before
217     # the final version!
218     # ------------------------------------------------------------------------
219    
220     function webapp_src_install ()
221     {
222     chown -R root:root ${D}/
223     chmod -R u-s ${D}/
224     chmod -R g-s ${D}/
225 stuart 1.5
226     keepdir ${MY_PERSISTDIR}
227     fowners root:root ${MY_PERSISTDIR}
228     fperms 755 ${MY_PERSISTDIR}
229 stuart 1.1 }
230    
231     # ------------------------------------------------------------------------
232 stuart 1.3 # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
233 stuart 1.1 # everything else has run
234     #
235     # If 'vhosts' USE flag is not set, auto-install this app
236     #
237     # ------------------------------------------------------------------------
238    
239     function webapp_pkg_setup ()
240     {
241 stuart 1.8 # pull in the shared configuration file
242    
243     . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file"
244 stuart 1.6
245 stuart 1.3 # are we emerging something that is already installed?
246    
247 stuart 1.8 if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then
248 stuart 1.3 # yes we are
249     ewarn "Removing existing copy of ${PN}-${PVR}"
250 stuart 1.8 rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}"
251 stuart 1.3 fi
252 stuart 1.9 }
253 stuart 1.3
254 stuart 1.9 function webapp_src_preinst ()
255     {
256 stuart 1.3 # create the directories that we need
257    
258 stuart 1.9 dodir ${MY_HTDOCSDIR}
259     dodir ${MY_HOSTROOTDIR}
260     dodir ${MY_CGIBINDIR}
261     dodir ${MY_ICONSDIR}
262     dodir ${MY_ERRORSDIR}
263     dodir ${MY_SQLSCRIPTSDIR}
264 stuart 1.3 }
265    
266 stuart 1.5 function webapp_pkg_postinst ()
267 stuart 1.3 {
268 stuart 1.10 # if 'vhosts' is not set in your USE flags, we install a copy of
269     # this application in /var/www/localhost/htdocs/${PN}/ for you
270 stuart 1.8
271 stuart 1.11
272 stuart 1.10 if ! use vhosts ; then
273 stuart 1.11 einfo "vhosts USE flag not set - auto-installing using webapp-config"
274    
275 stuart 1.10 G_HOSTNAME="localhost"
276     . /etc/vhosts/webapp-config
277    
278     local my_mode=-I
279     local my_dir="${VHOST_ROOT}/htdocs/${PN}"
280    
281     # are we installing afresh - or are we upgrading?
282     # find out by looking to see what (if anything) is installed
283     # in there already
284    
285 stuart 1.11 my_cmd="/usr/sbin/webapp-config --show-installed -d $my_dir 2> /dev/null"
286     einfo "$my_cmd"
287    
288     my_output="`/usr/sbin/webapp-config --show-installed -d $my_dir 2> /dev/null`"
289    
290     # we can't use the exit status from webapp-config
291    
292     if [ "$?" = "0" ]; then
293 stuart 1.10
294     # something is in there - but the question has to be ... what?
295    
296 stuart 1.11 ewarn "$my_output already installed"
297    
298 stuart 1.10 if [ "`echo $my_output | awk '{ print $1 }'`" = "${PN}" ]; then
299 stuart 1.11 einfo "$my_output is a copy of ${PN}"
300     if [ "`echo $my_output | awk '{ print $2 }'`" = "${PVR}" ]; then
301     # this version is already installed
302     # we need to remove it first
303    
304     /usr/sbin/webapp-config -C -d $my_dir
305     else
306     # we have an older version of whatever it is our ebuild is
307     # trying to install ;-)
308     #
309     # this is the situation we can deal with
310    
311     einfo "selecting upgrade mode"
312     my_mode=-U
313     fi
314 stuart 1.10 else
315     # this should never happen - but just in case ...
316     #
317     # whatever is in that directory, it isn't the application
318     # that we are currently trying to install
319     #
320     # rather than overwrite the contents, we bail with an error
321     # instead
322    
323     die "$my_output is already installed in $my_dir"
324     fi
325 stuart 1.11 else
326     einfo "${PN}-${PVR} is not installed - using install mode"
327 stuart 1.10 fi
328    
329 stuart 1.12 my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $my_dir ${PN} ${PVR}"
330 stuart 1.11 einfo "Running $my_cmd"
331     $my_cmd
332 stuart 1.10 fi
333 stuart 1.11
334     return 0
335 stuart 1.2 }

  ViewVC Help
Powered by ViewVC 1.1.20