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

Contents of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Fri Apr 23 22:02:27 2004 UTC (9 years, 11 months ago) by stuart
Branch: MAIN
Changes since 1.8: +17 -10 lines
Important bug fix; portage removes ${D} at the start of src_install(); we now call webapp_srv_preinst() to recreate it

1 stuart 1.1 # Copyright 1999-2003 Gentoo Technologies, Inc.
2     # Distributed under the terms of the GNU General Public License v2
3 stuart 1.9 # $Header: /home/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.8 2004/04/23 14:19:35 stuart Exp $
4 stuart 1.1 #
5     # eclass/webapp.eclass
6     # Eclass for installing applications to run under a web server
7     #
8     # Part of the implementation of GLEP #11
9     #
10     # Author(s) Stuart Herbert <stuart@gentoo.org>
11     #
12     # ------------------------------------------------------------------------
13     #
14     # Please do not make modifications to this file without checking with a
15     # member of the web-apps herd first!
16     #
17     # ------------------------------------------------------------------------
18    
19     ECLASS=webapp
20     INHERITED="$INHERITED $ECLASS"
21     SLOT="${PVR}"
22     IUSE="$IUSE vhosts"
23 stuart 1.9 DEPEND="$DEPEND >=net-www/webapp-config-1.4"
24 stuart 1.1
25 stuart 1.5 EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install
26 stuart 1.1
27     # ------------------------------------------------------------------------
28     # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
29     #
30     # Check whether a specified file exists within the image/ directory
31     # or not.
32     #
33     # @param $1 - file to look for
34 stuart 1.3 # @param $2 - prefix directory to use
35 stuart 1.1 # @return 0 on success, never returns on an error
36     # ------------------------------------------------------------------------
37    
38     function webapp_checkfileexists ()
39     {
40 stuart 1.9 local my_prefix
41    
42     [ -n "$2" ] && my_prefix="$2/" || my_prefix=
43    
44     if [ ! -e ${my_prefix}$1 ]; then
45 stuart 1.3 msg="ebuild fault: file $1 not found"
46 stuart 1.1 eerror "$msg"
47     eerror "Please report this as a bug at http://bugs.gentoo.org/"
48     die "$msg"
49     fi
50     }
51    
52     # ------------------------------------------------------------------------
53 stuart 1.3 # 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 stuart 1.1 #
70     # ------------------------------------------------------------------------
71    
72 stuart 1.3 function webapp_strip_appdir ()
73     {
74 stuart 1.8 echo "$1" | sed -e "s|${D}${MY_APPDIR}/||g;"
75 stuart 1.3 }
76    
77     function webapp_strip_d ()
78     {
79     echo "$1" | sed -e "s|${D}||g;"
80     }
81    
82     function webapp_strip_cwd ()
83 stuart 1.1 {
84 stuart 1.3 echo "$1" | sed -e 's|/./|/|g;'
85 stuart 1.1 }
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 stuart 1.3 webapp_checkfileexists "$1" "$D"
98     local MY_FILE="`webapp_strip_appdir $1`"
99    
100     einfo "(config) $MY_FILE"
101 stuart 1.8 echo "$MY_FILE" >> ${D}${WA_CONFIGLIST}
102 stuart 1.1 }
103    
104     # ------------------------------------------------------------------------
105     # EXPORTED FUNCTION - FOR USE IN EBUILDS
106     #
107 stuart 1.5 # Install a text file containing post-installation instructions.
108     #
109     # @param $1 - language code (use 'en' for now)
110     # @param $2 - the file to install
111     # ------------------------------------------------------------------------
112    
113     function webapp_postinst_txt
114     {
115     webapp_checkfileexists "$2"
116    
117     einfo "(rtfm) $2 (lang: $1)"
118 stuart 1.8 cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt"
119 stuart 1.5 }
120    
121     # ------------------------------------------------------------------------
122     # EXPORTED FUNCTION - FOR USE IN EBUILDS
123     #
124 stuart 1.1 # Identify a script file (usually, but not always PHP or Perl) which is
125     #
126     # Files in this list may be modified to #! the required CGI engine when
127     # installed by webapp-config tool in the future.
128     #
129     # @param $1 - the cgi engine to use
130     # @param $2 - the script file that could run under a cgi-bin
131     #
132     # ------------------------------------------------------------------------
133    
134     function webapp_runbycgibin ()
135     {
136 stuart 1.3 webapp_checkfileexists "$2" "$D"
137     local MY_FILE="`webapp_strip_appdir $2`"
138     MY_FILE="`webapp_strip_cwd $MY_FILE`"
139    
140     einfo "(cgi-bin) $1 - $MY_FILE"
141 stuart 1.8 echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST}
142 stuart 1.3 }
143    
144     # ------------------------------------------------------------------------
145     # EXPORTED FUNCTION - FOR USE IN EBUILDS
146     #
147     # Identify a file which must be owned by the webserver's user:group
148     # settings.
149     #
150     # The ownership of the file is NOT set until the application is installed
151     # using the webapp-config tool.
152     #
153     # @param $1 - file to be owned by the webserver user:group combo
154     #
155     # ------------------------------------------------------------------------
156    
157     function webapp_serverowned ()
158     {
159     webapp_checkfileexists "$1" "$D"
160     local MY_FILE="`webapp_strip_appdir $1`"
161    
162     einfo "(server owned) $MY_FILE"
163 stuart 1.8 echo "$MY_FILE" >> ${D}${WA_SOLIST}
164 stuart 1.3 }
165    
166     # ------------------------------------------------------------------------
167     # EXPORTED FUNCTION - FOR USE IN EBUILDS
168     #
169     #
170     # @param $1 - the db engine that the script is for
171     # (one of: mysql|postgres)
172     # @param $2 - the sql script to be installed
173     # @param $3 - the older version of the app that this db script
174     # will upgrade from
175     # (do not pass this option if your SQL script only creates
176     # a new db from scratch)
177     # ------------------------------------------------------------------------
178    
179     function webapp_sqlscript ()
180     {
181     webapp_checkfileexists "$2"
182    
183     # create the directory where this script will go
184     #
185     # scripts for specific database engines go into their own subdirectory
186     # just to keep things readable on the filesystem
187    
188 stuart 1.8 if [ ! -d "${D}${MY_SQLSCRIPTSDIR}/$1" ]; then
189     mkdir -p "${D}${MY_SQLSCRIPTSDIR}/$1" || libsh_die "unable to create directory ${D}${MY_SQLSCRIPTSDIR}/$1"
190 stuart 1.3 fi
191    
192     # warning:
193     #
194     # do NOT change the naming convention used here without changing all
195     # the other scripts that also rely upon these names
196    
197     # are we dealing with an 'upgrade'-type script?
198     if [ -n "$3" ]; then
199     # yes we are
200     einfo "($1) upgrade script from ${PN}-${PVR} to $3"
201 stuart 1.8 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql
202 stuart 1.3 else
203     # no, we are not
204     einfo "($1) create script for ${PN}-${PVR}"
205 stuart 1.8 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql
206 stuart 1.3 fi
207 stuart 1.1 }
208    
209     # ------------------------------------------------------------------------
210     # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
211     # everything else has run
212     #
213     # For now, we just make sure that root owns everything, and that there
214     # are no setuid files. I'm sure this will change significantly before
215     # the final version!
216     # ------------------------------------------------------------------------
217    
218     function webapp_src_install ()
219     {
220     chown -R root:root ${D}/
221     chmod -R u-s ${D}/
222     chmod -R g-s ${D}/
223 stuart 1.5
224     keepdir ${MY_PERSISTDIR}
225     fowners root:root ${MY_PERSISTDIR}
226     fperms 755 ${MY_PERSISTDIR}
227 stuart 1.1 }
228    
229     # ------------------------------------------------------------------------
230 stuart 1.3 # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
231 stuart 1.1 # everything else has run
232     #
233     # If 'vhosts' USE flag is not set, auto-install this app
234     #
235     # ------------------------------------------------------------------------
236    
237     function webapp_pkg_setup ()
238     {
239 stuart 1.8 # pull in the shared configuration file
240    
241     . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file"
242 stuart 1.6
243 stuart 1.3 # are we emerging something that is already installed?
244    
245 stuart 1.8 if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then
246 stuart 1.3 # yes we are
247     ewarn "Removing existing copy of ${PN}-${PVR}"
248 stuart 1.8 rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}"
249 stuart 1.3 fi
250 stuart 1.9 }
251 stuart 1.3
252 stuart 1.9 function webapp_src_preinst ()
253     {
254 stuart 1.3 # create the directories that we need
255    
256 stuart 1.9 dodir ${MY_HTDOCSDIR}
257     dodir ${MY_HOSTROOTDIR}
258     dodir ${MY_CGIBINDIR}
259     dodir ${MY_ICONSDIR}
260     dodir ${MY_ERRORSDIR}
261     dodir ${MY_SQLSCRIPTSDIR}
262 stuart 1.3 }
263    
264 stuart 1.5 function webapp_pkg_postinst ()
265 stuart 1.3 {
266 stuart 1.8 G_HOSTNAME="localhost"
267     . /etc/vhosts/webapp-config
268    
269 stuart 1.9 use vhosts || /usr/sbin/webapp-config -I -u root -h localhost -d "${VHOST_ROOT}/htdocs/${PN}/" ${PN} ${PVR}
270 stuart 1.2 }

  ViewVC Help
Powered by ViewVC 1.1.20