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

Diff of /eclass/webapp.eclass

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

Revision 1.6 Revision 1.14
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.14 2004/05/01 00:45:45 stuart Exp $
3# 4#
4# eclass/webapp.eclass 5# eclass/webapp.eclass
5# Eclass for installing applications to run under a web server 6# Eclass for installing applications to run under a web server
6# 7#
7# Part of the implementation of GLEP #11 8# Part of the implementation of GLEP #11
17 18
18ECLASS=webapp 19ECLASS=webapp
19INHERITED="$INHERITED $ECLASS" 20INHERITED="$INHERITED $ECLASS"
20SLOT="${PVR}" 21SLOT="${PVR}"
21IUSE="$IUSE vhosts" 22IUSE="$IUSE vhosts"
22 23DEPEND="$DEPEND >=net-www/webapp-config-1.7"
23 24
24EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install 25EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install
26
27INSTALL_DIR="/$PN"
28IS_UPGRADE=0
29IS_REPLACE=0
25 30
26# ------------------------------------------------------------------------ 31# ------------------------------------------------------------------------
27# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 32# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
28# 33#
29# Check whether a specified file exists within the image/ directory 34# Check whether a specified file exists within the image/ directory
34# @return 0 on success, never returns on an error 39# @return 0 on success, never returns on an error
35# ------------------------------------------------------------------------ 40# ------------------------------------------------------------------------
36 41
37function webapp_checkfileexists () 42function webapp_checkfileexists ()
38{ 43{
44 local my_prefix
45
46 [ -n "$2" ] && my_prefix="$2/" || my_prefix=
47
39 if [ ! -e $1 ]; then 48 if [ ! -e ${my_prefix}$1 ]; then
40 msg="ebuild fault: file $1 not found" 49 msg="ebuild fault: file $1 not found"
41 eerror "$msg" 50 eerror "$msg"
42 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/"
43 die "$msg" 52 die "$msg"
44 fi 53 fi
46 55
47# ------------------------------------------------------------------------ 56# ------------------------------------------------------------------------
48# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY 57# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
49# ------------------------------------------------------------------------ 58# ------------------------------------------------------------------------
50 59
60function 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
51function webapp_import_config () 71function webapp_import_config ()
52{ 72{
53 if [ -z "${MY_HTDOCSDIR}" ]; then 73 if [ -z "${MY_HTDOCSDIR}" ]; then
54 . /etc/conf.d/webapp-config 74 . /etc/conf.d/webapp-config
55 fi 75 fi
64# 84#
65# ------------------------------------------------------------------------ 85# ------------------------------------------------------------------------
66 86
67function webapp_strip_appdir () 87function webapp_strip_appdir ()
68{ 88{
89 local my_stripped="$1"
69 echo "$1" | sed -e "s|${MY_APPDIR}/||g;" 90 echo "$1" | sed -e "s|${MY_APPDIR}/||g;"
70} 91}
71 92
72function webapp_strip_d () 93function webapp_strip_d ()
73{ 94{
74 echo "$1" | sed -e "s|${D}||g;" 95 echo "$1" | sed -e "s|${D}||g;"
75} 96}
76 97
77function webapp_strip_cwd () 98function webapp_strip_cwd ()
78{ 99{
100 local my_stripped="$1"
79 echo "$1" | sed -e 's|/./|/|g;' 101 echo "$1" | sed -e 's|/./|/|g;'
80} 102}
81 103
82# ------------------------------------------------------------------------ 104# ------------------------------------------------------------------------
83# EXPORTED FUNCTION - FOR USE IN EBUILDS 105# EXPORTED FUNCTION - FOR USE IN EBUILDS
88# ------------------------------------------------------------------------ 110# ------------------------------------------------------------------------
89 111
90function webapp_configfile () 112function webapp_configfile ()
91{ 113{
92 webapp_checkfileexists "$1" "$D" 114 webapp_checkfileexists "$1" "$D"
115 echo $1
93 local MY_FILE="`webapp_strip_appdir $1`" 116 local MY_FILE="`webapp_strip_appdir $1`"
117 echo $MY_FILE
94 118
95 einfo "(config) $MY_FILE" 119 einfo "(config) $MY_FILE"
96 echo "$MY_FILE" >> $WA_CONFIGLIST 120 echo "$MY_FILE" >> ${D}${WA_CONFIGLIST}
97} 121}
98 122
99# ------------------------------------------------------------------------ 123# ------------------------------------------------------------------------
100# EXPORTED FUNCTION - FOR USE IN EBUILDS 124# EXPORTED FUNCTION - FOR USE IN EBUILDS
101# 125#
108function webapp_postinst_txt 132function webapp_postinst_txt
109{ 133{
110 webapp_checkfileexists "$2" 134 webapp_checkfileexists "$2"
111 135
112 einfo "(rtfm) $2 (lang: $1)" 136 einfo "(rtfm) $2 (lang: $1)"
113 cp "$2" "${MY_APPDIR}/postinst-$1.txt" 137 cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt"
114} 138}
115 139
116# ------------------------------------------------------------------------ 140# ------------------------------------------------------------------------
117# EXPORTED FUNCTION - FOR USE IN EBUILDS 141# EXPORTED FUNCTION - FOR USE IN EBUILDS
118# 142#
131 webapp_checkfileexists "$2" "$D" 155 webapp_checkfileexists "$2" "$D"
132 local MY_FILE="`webapp_strip_appdir $2`" 156 local MY_FILE="`webapp_strip_appdir $2`"
133 MY_FILE="`webapp_strip_cwd $MY_FILE`" 157 MY_FILE="`webapp_strip_cwd $MY_FILE`"
134 158
135 einfo "(cgi-bin) $1 - $MY_FILE" 159 einfo "(cgi-bin) $1 - $MY_FILE"
136 echo "$1 $MY_FILE" >> $WA_RUNBYCGIBINLIST 160 echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST}
137} 161}
138 162
139# ------------------------------------------------------------------------ 163# ------------------------------------------------------------------------
140# EXPORTED FUNCTION - FOR USE IN EBUILDS 164# EXPORTED FUNCTION - FOR USE IN EBUILDS
141# 165#
153{ 177{
154 webapp_checkfileexists "$1" "$D" 178 webapp_checkfileexists "$1" "$D"
155 local MY_FILE="`webapp_strip_appdir $1`" 179 local MY_FILE="`webapp_strip_appdir $1`"
156 180
157 einfo "(server owned) $MY_FILE" 181 einfo "(server owned) $MY_FILE"
158 echo "$MY_FILE" >> $WA_SOLIST 182 echo "$MY_FILE" >> ${D}${WA_SOLIST}
159} 183}
160 184
161# ------------------------------------------------------------------------ 185# ------------------------------------------------------------------------
162# EXPORTED FUNCTION - FOR USE IN EBUILDS 186# EXPORTED FUNCTION - FOR USE IN EBUILDS
163# 187#
178 # create the directory where this script will go 202 # create the directory where this script will go
179 # 203 #
180 # scripts for specific database engines go into their own subdirectory 204 # scripts for specific database engines go into their own subdirectory
181 # just to keep things readable on the filesystem 205 # just to keep things readable on the filesystem
182 206
183 if [ ! -d "${MY_SQLSCRIPTSDIR}/$1" ]; then 207 if [ ! -d "${D}${MY_SQLSCRIPTSDIR}/$1" ]; then
184 mkdir -p "${MY_SQLSCRIPTSDIR}/$1" || libsh_die "unable to create directory ${MY_SQLSCRIPTSDIR}/$1" 208 mkdir -p "${D}${MY_SQLSCRIPTSDIR}/$1" || libsh_die "unable to create directory ${D}${MY_SQLSCRIPTSDIR}/$1"
185 fi 209 fi
186 210
187 # warning: 211 # warning:
188 # 212 #
189 # do NOT change the naming convention used here without changing all 213 # do NOT change the naming convention used here without changing all
191 215
192 # are we dealing with an 'upgrade'-type script? 216 # are we dealing with an 'upgrade'-type script?
193 if [ -n "$3" ]; then 217 if [ -n "$3" ]; then
194 # yes we are 218 # yes we are
195 einfo "($1) upgrade script from ${PN}-${PVR} to $3" 219 einfo "($1) upgrade script from ${PN}-${PVR} to $3"
196 cp $2 ${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql 220 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql
197 else 221 else
198 # no, we are not 222 # no, we are not
199 einfo "($1) create script for ${PN}-${PVR}" 223 einfo "($1) create script for ${PN}-${PVR}"
200 cp $2 ${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql 224 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql
201 fi 225 fi
202} 226}
203 227
204# ------------------------------------------------------------------------ 228# ------------------------------------------------------------------------
205# EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER 229# EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
229# 253#
230# ------------------------------------------------------------------------ 254# ------------------------------------------------------------------------
231 255
232function webapp_pkg_setup () 256function webapp_pkg_setup ()
233{ 257{
234 if [ -f /etc/vhosts/webapp-config ] ; then 258 # pull in the shared configuration file
235 . /etc/vhosts/webapp-config
236 else
237 die "Unable to find /etc/vhosts/webapp-config"
238 fi
239 259
260 . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file"
261}
262
263function webapp_getinstalltype ()
264{
240 # are we emerging something that is already installed? 265 # are we emerging something that is already installed?
241 266
242 if [ -d "${MY_APPROOT}/${MY_APPSUFFIX}" ]; then 267 if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then
243 # yes we are 268 # yes we are
244 ewarn "Removing existing copy of ${PN}-${PVR}" 269 ewarn "Removing existing copy of ${PN}-${PVR}"
245 rm -rf "${MY_APPROOT}/${MY_APPSUFFIX}" 270 rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}"
271 fi
272
273 # or are we upgrading?
274
275 if ! use vhosts ; then
276 # we only run webapp-config if vhosts USE flag is not set
277
278 local my_output
279
280 my_output="`webapp_check_installedat`"
281
282 if [ "$?" = "0" ] ; then
283 # something is already installed there
284 #
285 # make sure it isn't the same version
286
287 local my_pn="`echo $my_output | awk '{ print $1 }'`"
288 local my_pvr="`echo $my_output | awk '{ print $2 }'`"
289
290 REMOVE_PKG="${my_pn}-${my_pvr}"
291
292 if [ "$my_pn" == "$PN" ]; then
293 if [ "$my_pvr" != "$PVR" ]; then
294 einfo "This is an upgrade"
295 IS_UPGRADE=1
296 else
297 einfo "This is a re-installation"
298 IS_REPLACE=1
299 fi
300 fi
246 fi 301 fi
302 fi
303}
247 304
305function webapp_src_preinst ()
306{
248 # create the directories that we need 307 # create the directories that we need
249 308
250 mkdir -p ${MY_HTDOCSDIR} 309 dodir ${MY_HTDOCSDIR}
251 mkdir -p ${MY_HOSTROOTDIR} 310 dodir ${MY_HOSTROOTDIR}
252 mkdir -p ${MY_CGIBINDIR} 311 dodir ${MY_CGIBINDIR}
253 mkdir -p ${MY_ICONSDIR} 312 dodir ${MY_ICONSDIR}
254 mkdir -p ${MY_ERRORSDIR} 313 dodir ${MY_ERRORSDIR}
255 mkdir -p ${MY_SQLSCRIPTSDIR} 314 dodir ${MY_SQLSCRIPTSDIR}
256} 315}
257 316
258function webapp_pkg_postinst () 317function webapp_pkg_postinst ()
259{ 318{
260 G_HOSTNAME="${VHOST_HOSTNAME}" 319 # if 'vhosts' is not set in your USE flags, we install a copy of
261 use vhosts || /usr/sbin/webapp-config -I -u root -d "${VHOST_ROOT}/htdocs/${PN}/" ${PN} ${PVR} 320 # this application in /var/www/localhost/htdocs/${PN}/ for you
321
322 if ! use vhosts ; then
323 echo
324 einfo "vhosts USE flag not set - auto-installing using webapp-config"
325
326 webapp_getinstalltype
327
328 G_HOSTNAME="localhost"
329 . /etc/vhosts/webapp-config
330
331 local my_mode=-I
332
333 if [ "$IS_REPLACE" = "1" ]; then
334 einfo "${PN}-${PVR} is already installed - replacing"
335 /usr/sbin/webapp-config -C -d "$INSTALL_DIR"
336 elif [ "$IS_UPGRADE" = "1" ]; then
337 einfo "$REMOVE_PKG is already installed - upgrading"
338 my_mode=-U
339 else
340 einfo "${PN}-${PVR} is not installed - using install mode"
341 fi
342
343 my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $INSTALL_DIR ${PN} ${PVR}"
344 einfo "Running $my_cmd"
345 $my_cmd
346
347 # remove the old version
348 #
349 # why do we do this? well ...
350 #
351 # normally, emerge -u installs a new version and then removes the
352 # old version. however, if the new version goes into a different
353 # slot to the old version, then the old version gets left behind
354 #
355 # if USE=-vhosts, then we want to remove the old version, because
356 # the user is relying on portage to do the magical thing for it
357
358 if [ "$IS_UPGRADE" = "1" ] ; then
359 einfo "Removing old version $REMOVE_PKG"
360
361 echo emerge -C $CATEGORY/$REMOVE_PKG
362 fi
363 fi
364
365 return 0
262} 366}

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.20