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

Diff of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.13

  ViewVC Help
Powered by ViewVC 1.1.20