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

Contents of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (show annotations) (download)
Thu Apr 29 10:18:14 2004 UTC (9 years, 11 months ago) by stuart
Branch: MAIN
Changes since 1.10: +38 -10 lines
Fix for symlinks problem

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.5"
24
25 EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install
26
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 # @param $2 - prefix directory to use
35 # @return 0 on success, never returns on an error
36 # ------------------------------------------------------------------------
37
38 function webapp_checkfileexists ()
39 {
40 local my_prefix
41
42 [ -n "$2" ] && my_prefix="$2/" || my_prefix=
43
44 if [ ! -e ${my_prefix}$1 ]; then
45 msg="ebuild fault: file $1 not found"
46 eerror "$msg"
47 eerror "Please report this as a bug at http://bugs.gentoo.org/"
48 die "$msg"
49 fi
50 }
51
52 # ------------------------------------------------------------------------
53 # 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 #
70 # ------------------------------------------------------------------------
71
72 function webapp_strip_appdir ()
73 {
74 echo "$1" | sed -e "s|${MY_APPDIR}/||g;"
75 }
76
77 function webapp_strip_d ()
78 {
79 echo "$1" | sed -e "s|${D}||g;"
80 }
81
82 function webapp_strip_cwd ()
83 {
84 echo "$1" | sed -e 's|/./|/|g;'
85 }
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 webapp_checkfileexists "$1" "$D"
98 echo $1
99 local MY_FILE="`webapp_strip_appdir $1`"
100 echo $MY_FILE
101
102 einfo "(config) $MY_FILE"
103 echo "$MY_FILE" >> ${D}${WA_CONFIGLIST}
104 }
105
106 # ------------------------------------------------------------------------
107 # EXPORTED FUNCTION - FOR USE IN EBUILDS
108 #
109 # 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 cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt"
121 }
122
123 # ------------------------------------------------------------------------
124 # EXPORTED FUNCTION - FOR USE IN EBUILDS
125 #
126 # 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 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 echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST}
144 }
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 echo "$MY_FILE" >> ${D}${WA_SOLIST}
166 }
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 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 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 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql
204 else
205 # no, we are not
206 einfo "($1) create script for ${PN}-${PVR}"
207 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql
208 fi
209 }
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
226 keepdir ${MY_PERSISTDIR}
227 fowners root:root ${MY_PERSISTDIR}
228 fperms 755 ${MY_PERSISTDIR}
229 }
230
231 # ------------------------------------------------------------------------
232 # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
233 # 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 # pull in the shared configuration file
242
243 . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file"
244
245 # are we emerging something that is already installed?
246
247 if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then
248 # yes we are
249 ewarn "Removing existing copy of ${PN}-${PVR}"
250 rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}"
251 fi
252 }
253
254 function webapp_src_preinst ()
255 {
256 # create the directories that we need
257
258 dodir ${MY_HTDOCSDIR}
259 dodir ${MY_HOSTROOTDIR}
260 dodir ${MY_CGIBINDIR}
261 dodir ${MY_ICONSDIR}
262 dodir ${MY_ERRORSDIR}
263 dodir ${MY_SQLSCRIPTSDIR}
264 }
265
266 function webapp_pkg_postinst ()
267 {
268 # 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
271
272 if ! use vhosts ; then
273 einfo "vhosts USE flag not set - auto-installing using webapp-config"
274
275 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 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
294 # something is in there - but the question has to be ... what?
295
296 ewarn "$my_output already installed"
297
298 if [ "`echo $my_output | awk '{ print $1 }'`" = "${PN}" ]; then
299 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 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 else
326 einfo "${PN}-${PVR} is not installed - using install mode"
327 fi
328
329 my_cmd="/usr/sbin/webapp-config $my_mode -u root -d $my_dir ${PN} ${PVR}"
330 einfo "Running $my_cmd"
331 $my_cmd
332 fi
333
334 return 0
335 }

  ViewVC Help
Powered by ViewVC 1.1.20