| 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.3 2004/03/02 23:57:39 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 |
| … | |
… | |
| 11 | # |
11 | # |
| 12 | # ------------------------------------------------------------------------ |
12 | # ------------------------------------------------------------------------ |
| 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 | # |
|
|
| 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 | # |
16 | # |
| 22 | # ------------------------------------------------------------------------ |
17 | # ------------------------------------------------------------------------ |
| 23 | |
18 | |
| 24 | ECLASS=webapp |
19 | ECLASS=webapp |
| 25 | INHERITED="$INHERITED $ECLASS" |
20 | INHERITED="$INHERITED $ECLASS" |
| 26 | SLOT="${PVR}" |
21 | SLOT="${PVR}" |
| 27 | IUSE="$IUSE vhosts" |
22 | IUSE="$IUSE vhosts" |
|
|
23 | DEPEND="$DEPEND >=net-www/webapp-config-1.6" |
| 28 | |
24 | |
| 29 | if [ -f /etc/conf.d/webapp-config ] ; then |
|
|
| 30 | . /etc/conf.d/webapp-config |
|
|
| 31 | else |
|
|
| 32 | die "Unable to open /etc/conf.d/webapp-config files" |
|
|
| 33 | fi |
|
|
| 34 | |
|
|
| 35 | EXPORT_FUNCTIONS pkg_config pkg_setup src_install |
25 | EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install |
| 36 | |
26 | |
| 37 | # ------------------------------------------------------------------------ |
27 | # ------------------------------------------------------------------------ |
| 38 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
28 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
| 39 | # |
29 | # |
| 40 | # Check whether a specified file exists within the image/ directory |
30 | # Check whether a specified file exists within the image/ directory |
| … | |
… | |
| 45 | # @return 0 on success, never returns on an error |
35 | # @return 0 on success, never returns on an error |
| 46 | # ------------------------------------------------------------------------ |
36 | # ------------------------------------------------------------------------ |
| 47 | |
37 | |
| 48 | function webapp_checkfileexists () |
38 | function webapp_checkfileexists () |
| 49 | { |
39 | { |
|
|
40 | local my_prefix |
|
|
41 | |
|
|
42 | [ -n "$2" ] && my_prefix="$2/" || my_prefix= |
|
|
43 | |
| 50 | if [ ! -e $1 ]; then |
44 | if [ ! -e ${my_prefix}$1 ]; then |
| 51 | msg="ebuild fault: file $1 not found" |
45 | msg="ebuild fault: file $1 not found" |
| 52 | eerror "$msg" |
46 | eerror "$msg" |
| 53 | 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/" |
| 54 | die "$msg" |
48 | die "$msg" |
| 55 | fi |
49 | fi |
| … | |
… | |
| 99 | # ------------------------------------------------------------------------ |
93 | # ------------------------------------------------------------------------ |
| 100 | |
94 | |
| 101 | function webapp_configfile () |
95 | function webapp_configfile () |
| 102 | { |
96 | { |
| 103 | webapp_checkfileexists "$1" "$D" |
97 | webapp_checkfileexists "$1" "$D" |
|
|
98 | echo $1 |
| 104 | local MY_FILE="`webapp_strip_appdir $1`" |
99 | local MY_FILE="`webapp_strip_appdir $1`" |
|
|
100 | echo $MY_FILE |
| 105 | |
101 | |
| 106 | einfo "(config) $MY_FILE" |
102 | einfo "(config) $MY_FILE" |
| 107 | echo "$MY_FILE" >> $WA_CONFIGLIST |
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" |
| 108 | } |
121 | } |
| 109 | |
122 | |
| 110 | # ------------------------------------------------------------------------ |
123 | # ------------------------------------------------------------------------ |
| 111 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
124 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 112 | # |
125 | # |
| … | |
… | |
| 125 | webapp_checkfileexists "$2" "$D" |
138 | webapp_checkfileexists "$2" "$D" |
| 126 | local MY_FILE="`webapp_strip_appdir $2`" |
139 | local MY_FILE="`webapp_strip_appdir $2`" |
| 127 | MY_FILE="`webapp_strip_cwd $MY_FILE`" |
140 | MY_FILE="`webapp_strip_cwd $MY_FILE`" |
| 128 | |
141 | |
| 129 | einfo "(cgi-bin) $1 - $MY_FILE" |
142 | einfo "(cgi-bin) $1 - $MY_FILE" |
| 130 | echo "$1 $MY_FILE" >> $WA_RUNBYCGIBINLIST |
143 | echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST} |
| 131 | } |
144 | } |
| 132 | |
145 | |
| 133 | # ------------------------------------------------------------------------ |
146 | # ------------------------------------------------------------------------ |
| 134 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
147 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 135 | # |
148 | # |
| … | |
… | |
| 147 | { |
160 | { |
| 148 | webapp_checkfileexists "$1" "$D" |
161 | webapp_checkfileexists "$1" "$D" |
| 149 | local MY_FILE="`webapp_strip_appdir $1`" |
162 | local MY_FILE="`webapp_strip_appdir $1`" |
| 150 | |
163 | |
| 151 | einfo "(server owned) $MY_FILE" |
164 | einfo "(server owned) $MY_FILE" |
| 152 | echo "$MY_FILE" >> $WA_SOLIST |
165 | echo "$MY_FILE" >> ${D}${WA_SOLIST} |
| 153 | } |
166 | } |
| 154 | |
167 | |
| 155 | # ------------------------------------------------------------------------ |
168 | # ------------------------------------------------------------------------ |
| 156 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
169 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 157 | # |
170 | # |
| … | |
… | |
| 172 | # create the directory where this script will go |
185 | # create the directory where this script will go |
| 173 | # |
186 | # |
| 174 | # scripts for specific database engines go into their own subdirectory |
187 | # scripts for specific database engines go into their own subdirectory |
| 175 | # just to keep things readable on the filesystem |
188 | # just to keep things readable on the filesystem |
| 176 | |
189 | |
| 177 | if [ ! -d "${MY_SQLSCRIPTSDIR}/$1" ]; then |
190 | if [ ! -d "${D}${MY_SQLSCRIPTSDIR}/$1" ]; then |
| 178 | mkdir -p "${MY_SQLSCRIPTSDIR}/$1" || libsh_die "unable to create directory ${MY_SQLSCRIPTSDIR}/$1" |
191 | mkdir -p "${D}${MY_SQLSCRIPTSDIR}/$1" || libsh_die "unable to create directory ${D}${MY_SQLSCRIPTSDIR}/$1" |
| 179 | fi |
192 | fi |
| 180 | |
193 | |
| 181 | # warning: |
194 | # warning: |
| 182 | # |
195 | # |
| 183 | # do NOT change the naming convention used here without changing all |
196 | # do NOT change the naming convention used here without changing all |
| … | |
… | |
| 185 | |
198 | |
| 186 | # are we dealing with an 'upgrade'-type script? |
199 | # are we dealing with an 'upgrade'-type script? |
| 187 | if [ -n "$3" ]; then |
200 | if [ -n "$3" ]; then |
| 188 | # yes we are |
201 | # yes we are |
| 189 | einfo "($1) upgrade script from ${PN}-${PVR} to $3" |
202 | einfo "($1) upgrade script from ${PN}-${PVR} to $3" |
| 190 | cp $2 ${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql |
203 | cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql |
| 191 | else |
204 | else |
| 192 | # no, we are not |
205 | # no, we are not |
| 193 | einfo "($1) create script for ${PN}-${PVR}" |
206 | einfo "($1) create script for ${PN}-${PVR}" |
| 194 | cp $2 ${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql |
207 | cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql |
| 195 | fi |
208 | fi |
| 196 | } |
209 | } |
| 197 | |
210 | |
| 198 | # ------------------------------------------------------------------------ |
211 | # ------------------------------------------------------------------------ |
| 199 | # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER |
212 | # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER |
| … | |
… | |
| 207 | function webapp_src_install () |
220 | function webapp_src_install () |
| 208 | { |
221 | { |
| 209 | chown -R root:root ${D}/ |
222 | chown -R root:root ${D}/ |
| 210 | chmod -R u-s ${D}/ |
223 | chmod -R u-s ${D}/ |
| 211 | chmod -R g-s ${D}/ |
224 | chmod -R g-s ${D}/ |
|
|
225 | |
|
|
226 | keepdir ${MY_PERSISTDIR} |
|
|
227 | fowners root:root ${MY_PERSISTDIR} |
|
|
228 | fperms 755 ${MY_PERSISTDIR} |
| 212 | } |
229 | } |
| 213 | |
230 | |
| 214 | # ------------------------------------------------------------------------ |
231 | # ------------------------------------------------------------------------ |
| 215 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER |
232 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER |
| 216 | # everything else has run |
233 | # everything else has run |
| … | |
… | |
| 219 | # |
236 | # |
| 220 | # ------------------------------------------------------------------------ |
237 | # ------------------------------------------------------------------------ |
| 221 | |
238 | |
| 222 | function webapp_pkg_setup () |
239 | function webapp_pkg_setup () |
| 223 | { |
240 | { |
|
|
241 | # pull in the shared configuration file |
|
|
242 | |
|
|
243 | . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file" |
|
|
244 | |
| 224 | # are we emerging something that is already installed? |
245 | # are we emerging something that is already installed? |
| 225 | |
246 | |
| 226 | if [ -d "${MY_APPROOT}/${MY_APPSUFFIX}" ]; then |
247 | if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then |
| 227 | # yes we are |
248 | # yes we are |
| 228 | ewarn "Removing existing copy of ${PN}-${PVR}" |
249 | ewarn "Removing existing copy of ${PN}-${PVR}" |
| 229 | rm -rf "${MY_APPROOT}/${MY_APPSUFFIX}" |
250 | rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}" |
| 230 | fi |
251 | fi |
|
|
252 | } |
| 231 | |
253 | |
|
|
254 | function webapp_src_preinst () |
|
|
255 | { |
| 232 | # create the directories that we need |
256 | # create the directories that we need |
| 233 | |
257 | |
| 234 | mkdir -p ${MY_HTDOCSDIR} |
258 | dodir ${MY_HTDOCSDIR} |
| 235 | mkdir -p ${MY_HOSTROOTDIR} |
259 | dodir ${MY_HOSTROOTDIR} |
| 236 | mkdir -p ${MY_CGIBINDIR} |
260 | dodir ${MY_CGIBINDIR} |
| 237 | mkdir -p ${MY_ICONSDIR} |
261 | dodir ${MY_ICONSDIR} |
| 238 | mkdir -p ${MY_ERRORSDIR} |
262 | dodir ${MY_ERRORSDIR} |
| 239 | mkdir -p ${MY_SQLSCRIPTSDIR} |
263 | dodir ${MY_SQLSCRIPTSDIR} |
| 240 | } |
264 | } |
| 241 | |
265 | |
| 242 | function webapp_pkg_config () |
266 | function webapp_pkg_postinst () |
| 243 | { |
267 | { |
| 244 | use vhosts || webapp-config -u root -d /var/www/localhost/htdocs/${PN}/ ${PN} |
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 |
| 245 | } |
337 | } |