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.13 2004/04/30 08:25:38 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.6" |
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 |
35 | |
26 | |
36 | # ------------------------------------------------------------------------ |
27 | # ------------------------------------------------------------------------ |
37 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
28 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
38 | # |
29 | # |
39 | # Check whether a specified file exists within the image/ directory |
30 | # Check whether a specified file exists within the image/ directory |
40 | # or not. |
31 | # or not. |
41 | # |
32 | # |
42 | # @param $1 - file to look for |
33 | # @param $1 - file to look for |
|
|
34 | # @param $2 - prefix directory to use |
43 | # @return 0 on success, never returns on an error |
35 | # @return 0 on success, never returns on an error |
44 | # ------------------------------------------------------------------------ |
36 | # ------------------------------------------------------------------------ |
45 | |
37 | |
46 | function webapp_checkfileexists () |
38 | function webapp_checkfileexists () |
47 | { |
39 | { |
|
|
40 | local my_prefix |
|
|
41 | |
|
|
42 | [ -n "$2" ] && my_prefix="$2/" || my_prefix= |
|
|
43 | |
48 | if [ ! -e ${D}/$1 ]; then |
44 | if [ ! -e ${my_prefix}$1 ]; then |
49 | msg="ebuild fault: file $1 not found in ${D}" |
45 | msg="ebuild fault: file $1 not found" |
50 | eerror "$msg" |
46 | eerror "$msg" |
51 | eerror "Please report this as a bug at http://bugs.gentoo.org/" |
47 | eerror "Please report this as a bug at http://bugs.gentoo.org/" |
52 | die "$msg" |
48 | die "$msg" |
53 | fi |
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} |
54 | } |
144 | } |
55 | |
145 | |
56 | # ------------------------------------------------------------------------ |
146 | # ------------------------------------------------------------------------ |
57 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
147 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
58 | # |
148 | # |
… | |
… | |
66 | # |
156 | # |
67 | # ------------------------------------------------------------------------ |
157 | # ------------------------------------------------------------------------ |
68 | |
158 | |
69 | function webapp_serverowned () |
159 | function webapp_serverowned () |
70 | { |
160 | { |
71 | webapp_checkfileexists $1 |
161 | webapp_checkfileexists "$1" "$D" |
|
|
162 | local MY_FILE="`webapp_strip_appdir $1`" |
|
|
163 | |
|
|
164 | einfo "(server owned) $MY_FILE" |
72 | echo "$1" >> $WA_SOLIST |
165 | echo "$MY_FILE" >> ${D}${WA_SOLIST} |
73 | } |
166 | } |
74 | |
167 | |
75 | # ------------------------------------------------------------------------ |
168 | # ------------------------------------------------------------------------ |
76 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
169 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
77 | # |
170 | # |
78 | # Identify a config file for a web-based application. |
|
|
79 | # |
171 | # |
80 | # @param $1 - config file |
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) |
81 | # ------------------------------------------------------------------------ |
179 | # ------------------------------------------------------------------------ |
82 | |
180 | |
83 | function webapp_configfile () |
181 | function webapp_sqlscript () |
84 | { |
182 | { |
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 |
183 | webapp_checkfileexists "$2" |
105 | echo "$1 $2" >> $WA_RUNBYCGIBINLIST |
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 |
106 | } |
209 | } |
107 | |
210 | |
108 | # ------------------------------------------------------------------------ |
211 | # ------------------------------------------------------------------------ |
109 | # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER |
212 | # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER |
110 | # everything else has run |
213 | # everything else has run |
… | |
… | |
117 | function webapp_src_install () |
220 | function webapp_src_install () |
118 | { |
221 | { |
119 | chown -R root:root ${D}/ |
222 | chown -R root:root ${D}/ |
120 | chmod -R u-s ${D}/ |
223 | chmod -R u-s ${D}/ |
121 | chmod -R g-s ${D}/ |
224 | chmod -R g-s ${D}/ |
122 | } |
|
|
123 | |
225 | |
|
|
226 | keepdir ${MY_PERSISTDIR} |
|
|
227 | fowners root:root ${MY_PERSISTDIR} |
|
|
228 | fperms 755 ${MY_PERSISTDIR} |
|
|
229 | } |
|
|
230 | |
124 | # ------------------------------------------------------------------------ |
231 | # ------------------------------------------------------------------------ |
125 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_setup AFTER |
232 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER |
126 | # everything else has run |
233 | # everything else has run |
127 | # |
234 | # |
128 | # If 'vhosts' USE flag is not set, auto-install this app |
235 | # If 'vhosts' USE flag is not set, auto-install this app |
129 | # |
236 | # |
130 | # ------------------------------------------------------------------------ |
237 | # ------------------------------------------------------------------------ |
131 | |
238 | |
132 | function webapp_pkg_setup () |
239 | function webapp_pkg_setup () |
133 | { |
240 | { |
134 | use vhosts || webapp-config -u root -d /var/www/localhost/htdocs/${PN}/ ${PN} |
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 | einfo "webapp_pkg_postinst() called" |
|
|
269 | |
|
|
270 | # if 'vhosts' is not set in your USE flags, we install a copy of |
|
|
271 | # this application in /var/www/localhost/htdocs/${PN}/ for you |
|
|
272 | |
|
|
273 | |
|
|
274 | if ! use vhosts ; then |
|
|
275 | einfo "vhosts USE flag not set - auto-installing using webapp-config" |
|
|
276 | |
|
|
277 | G_HOSTNAME="localhost" |
|
|
278 | . /etc/vhosts/webapp-config |
|
|
279 | |
|
|
280 | local my_mode=-I |
|
|
281 | local my_dir="/${PN}" |
|
|
282 | |
|
|
283 | # are we installing afresh - or are we upgrading? |
|
|
284 | # find out by looking to see what (if anything) is installed |
|
|
285 | # in there already |
|
|
286 | |
|
|
287 | my_cmd="/usr/sbin/webapp-config --show-installed -d $my_dir 2> /dev/null" |
|
|
288 | einfo "$my_cmd" |
|
|
289 | |
|
|
290 | my_output="`/usr/sbin/webapp-config --show-installed -d $my_dir 2> /dev/null`" |
|
|
291 | |
|
|
292 | # we can't use the exit status from webapp-config |
|
|
293 | |
|
|
294 | if [ "$?" = "0" ]; then |
|
|
295 | |
|
|
296 | # something is in there - but the question has to be ... what? |
|
|
297 | |
|
|
298 | ewarn "$my_output already installed" |
|
|
299 | |
|
|
300 | if [ "`echo $my_output | awk '{ print $1 }'`" = "${PN}" ]; then |
|
|
301 | einfo "$my_output is a copy of ${PN}" |
|
|
302 | if [ "`echo $my_output | awk '{ print $2 }'`" = "${PVR}" ]; then |
|
|
303 | # this version is already installed |
|
|
304 | # we need to remove it first |
|
|
305 | |
|
|
306 | /usr/sbin/webapp-config -C -d $my_dir |
|
|
307 | else |
|
|
308 | # we have an older version of whatever it is our ebuild is |
|
|
309 | # trying to install ;-) |
|
|
310 | # |
|
|
311 | # this is the situation we can deal with |
|
|
312 | |
|
|
313 | einfo "selecting upgrade mode" |
|
|
314 | my_mode=-U |
|
|
315 | fi |
|
|
316 | else |
|
|
317 | # this should never happen - but just in case ... |
|
|
318 | # |
|
|
319 | # whatever is in that directory, it isn't the application |
|
|
320 | # that we are currently trying to install |
|
|
321 | # |
|
|
322 | # rather than overwrite the contents, we bail with an error |
|
|
323 | # instead |
|
|
324 | |
|
|
325 | die "$my_output is already installed in $my_dir" |
|
|
326 | fi |
|
|
327 | else |
|
|
328 | einfo "${PN}-${PVR} is not installed - using install mode" |
|
|
329 | fi |
|
|
330 | |
|
|
331 | my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $my_dir ${PN} ${PVR}" |
|
|
332 | einfo "Running $my_cmd" |
|
|
333 | $my_cmd |
|
|
334 | fi |
|
|
335 | |
|
|
336 | return 0 |
|
|
337 | } |