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

Contents of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (show annotations) (download)
Sat May 1 00:45:45 2004 UTC (9 years, 11 months ago) by stuart
Branch: MAIN
Changes since 1.13: +79 -50 lines
Improved USE=-vhosts support

1 # Copyright 1999-2004 Gentoo Technologies, Inc.
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /home/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.8 2004/04/23 14:19:35 stuart Exp $
4 #
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 DEPEND="$DEPEND >=net-www/webapp-config-1.7"
24
25 EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install
26
27 INSTALL_DIR="/$PN"
28 IS_UPGRADE=0
29 IS_REPLACE=0
30
31 # ------------------------------------------------------------------------
32 # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
33 #
34 # Check whether a specified file exists within the image/ directory
35 # or not.
36 #
37 # @param $1 - file to look for
38 # @param $2 - prefix directory to use
39 # @return 0 on success, never returns on an error
40 # ------------------------------------------------------------------------
41
42 function webapp_checkfileexists ()
43 {
44 local my_prefix
45
46 [ -n "$2" ] && my_prefix="$2/" || my_prefix=
47
48 if [ ! -e ${my_prefix}$1 ]; then
49 msg="ebuild fault: file $1 not found"
50 eerror "$msg"
51 eerror "Please report this as a bug at http://bugs.gentoo.org/"
52 die "$msg"
53 fi
54 }
55
56 # ------------------------------------------------------------------------
57 # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
58 # ------------------------------------------------------------------------
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
71 function 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
87 function webapp_strip_appdir ()
88 {
89 local my_stripped="$1"
90 echo "$1" | sed -e "s|${MY_APPDIR}/||g;"
91 }
92
93 function webapp_strip_d ()
94 {
95 echo "$1" | sed -e "s|${D}||g;"
96 }
97
98 function 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
112 function 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
132 function 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
153 function 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}
161 }
162
163 # ------------------------------------------------------------------------
164 # EXPORTED FUNCTION - FOR USE IN EBUILDS
165 #
166 # Identify a file which must be owned by the webserver's user:group
167 # settings.
168 #
169 # The ownership of the file is NOT set until the application is installed
170 # using the webapp-config tool.
171 #
172 # @param $1 - file to be owned by the webserver user:group combo
173 #
174 # ------------------------------------------------------------------------
175
176 function webapp_serverowned ()
177 {
178 webapp_checkfileexists "$1" "$D"
179 local MY_FILE="`webapp_strip_appdir $1`"
180
181 einfo "(server owned) $MY_FILE"
182 echo "$MY_FILE" >> ${D}${WA_SOLIST}
183 }
184
185 # ------------------------------------------------------------------------
186 # EXPORTED FUNCTION - FOR USE IN EBUILDS
187 #
188 #
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)
196 # ------------------------------------------------------------------------
197
198 function webapp_sqlscript ()
199 {
200 webapp_checkfileexists "$2"
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
226 }
227
228 # ------------------------------------------------------------------------
229 # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
230 # everything else has run
231 #
232 # For now, we just make sure that root owns everything, and that there
233 # are no setuid files. I'm sure this will change significantly before
234 # the final version!
235 # ------------------------------------------------------------------------
236
237 function webapp_src_install ()
238 {
239 chown -R root:root ${D}/
240 chmod -R u-s ${D}/
241 chmod -R g-s ${D}/
242
243 keepdir ${MY_PERSISTDIR}
244 fowners root:root ${MY_PERSISTDIR}
245 fperms 755 ${MY_PERSISTDIR}
246 }
247
248 # ------------------------------------------------------------------------
249 # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
250 # everything else has run
251 #
252 # If 'vhosts' USE flag is not set, auto-install this app
253 #
254 # ------------------------------------------------------------------------
255
256 function webapp_pkg_setup ()
257 {
258 # pull in the shared configuration file
259
260 . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file"
261 }
262
263 function 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
305 function 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
317 function 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 }

  ViewVC Help
Powered by ViewVC 1.1.20