| 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.17 2004/05/11 19:31:29 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 | |
| 24 | ECLASS=webapp |
19 | ECLASS=webapp |
| 25 | INHERITED="$INHERITED $ECLASS" |
20 | INHERITED="$INHERITED $ECLASS" |
| 26 | #DEPEND="${DEPEND} net-www/apache" |
|
|
| 27 | SLOT="${PVR}" |
21 | SLOT="${PVR}" |
| 28 | IUSE="$IUSE vhosts" |
22 | IUSE="$IUSE vhosts" |
|
|
23 | DEPEND="$DEPEND >=net-www/webapp-config-1.8" |
| 29 | |
24 | |
| 30 | if [ -f /usr/share/webapp-config/settings.sh ] ; then |
|
|
| 31 | . /usr/share/webapp-config/settings.sh |
|
|
| 32 | fi |
|
|
| 33 | |
|
|
| 34 | EXPORT_FUNCTIONS 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 |
| 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 | |
| 46 | function webapp_checkfileexists () |
42 | function 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 | |
|
|
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} |
| 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 | |
| 69 | function webapp_serverowned () |
176 | function 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 | |
| 83 | function webapp_configfile () |
198 | function 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 | |
|
|
| 102 | function 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 |
| … | |
… | |
| 117 | function webapp_src_install () |
237 | function 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 | HAS_webapp_src_install=1 |
|
|
248 | } |
|
|
249 | |
| 124 | # ------------------------------------------------------------------------ |
250 | # ------------------------------------------------------------------------ |
| 125 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_setup AFTER |
251 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER |
| 126 | # everything else has run |
252 | # everything else has run |
| 127 | # |
253 | # |
| 128 | # If 'vhosts' USE flag is not set, auto-install this app |
254 | # If 'vhosts' USE flag is not set, auto-install this app |
| 129 | # |
255 | # |
| 130 | # ------------------------------------------------------------------------ |
256 | # ------------------------------------------------------------------------ |
| 131 | |
257 | |
| 132 | function webapp_pkg_setup () |
258 | function webapp_pkg_setup () |
| 133 | { |
259 | { |
| 134 | use vhosts || webapp-config -u root -d /var/www/localhost/htdocs/${PN}/ ${PN} |
260 | # add sanity checks here |
|
|
261 | |
|
|
262 | if [ "$SLOT+" != "${PVR}+" ]; then |
|
|
263 | die "ebuild sets SLOT, overrides webapp.eclass" |
|
|
264 | fi |
|
|
265 | |
|
|
266 | # pull in the shared configuration file |
|
|
267 | |
|
|
268 | . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file" |
|
|
269 | } |
|
|
270 | |
|
|
271 | function webapp_getinstalltype () |
|
|
272 | { |
|
|
273 | # are we emerging something that is already installed? |
|
|
274 | |
|
|
275 | if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then |
|
|
276 | # yes we are |
|
|
277 | ewarn "Removing existing copy of ${PN}-${PVR}" |
|
|
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 |
|
|
310 | fi |
|
|
311 | } |
|
|
312 | |
|
|
313 | function webapp_src_preinst () |
|
|
314 | { |
|
|
315 | # create the directories that we need |
|
|
316 | |
|
|
317 | dodir ${MY_HTDOCSDIR} |
|
|
318 | dodir ${MY_HOSTROOTDIR} |
|
|
319 | dodir ${MY_CGIBINDIR} |
|
|
320 | dodir ${MY_ICONSDIR} |
|
|
321 | dodir ${MY_ERRORSDIR} |
|
|
322 | dodir ${MY_SQLSCRIPTSDIR} |
|
|
323 | } |
|
|
324 | |
|
|
325 | function webapp_pkg_postinst () |
|
|
326 | { |
|
|
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 |
|
|
341 | |
|
|
342 | # if 'vhosts' is not set in your USE flags, we install a copy of |
|
|
343 | # this application in /var/www/localhost/htdocs/${PN}/ for you |
|
|
344 | |
|
|
345 | if ! use vhosts ; then |
|
|
346 | echo |
|
|
347 | einfo "vhosts USE flag not set - auto-installing using webapp-config" |
|
|
348 | |
|
|
349 | webapp_getinstalltype |
|
|
350 | |
|
|
351 | G_HOSTNAME="localhost" |
|
|
352 | . /etc/vhosts/webapp-config |
|
|
353 | |
|
|
354 | local my_mode=-I |
|
|
355 | |
|
|
356 | if [ "$IS_REPLACE" = "1" ]; then |
|
|
357 | einfo "${PN}-${PVR} is already installed - replacing" |
|
|
358 | /usr/sbin/webapp-config -C -d "$INSTALL_DIR" |
|
|
359 | elif [ "$IS_UPGRADE" = "1" ]; then |
|
|
360 | einfo "$REMOVE_PKG is already installed - upgrading" |
|
|
361 | my_mode=-U |
|
|
362 | else |
|
|
363 | einfo "${PN}-${PVR} is not installed - using install mode" |
|
|
364 | fi |
|
|
365 | |
|
|
366 | my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $INSTALL_DIR ${PN} ${PVR}" |
|
|
367 | einfo "Running $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 |
|
|
386 | fi |
|
|
387 | |
|
|
388 | return 0 |
|
|
389 | } |