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

Contents of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Tue Mar 2 23:57:39 2004 UTC (10 years, 7 months ago) by stuart
Branch: MAIN
Changes since 1.2: +132 -22 lines
Updated to sync with webapp-config release

1 # Copyright 1999-2003 Gentoo Technologies, Inc.
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /home/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.2 2003/12/22 23:15:46 stuart Exp $
4 #
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 # 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
24 ECLASS=webapp
25 INHERITED="$INHERITED $ECLASS"
26 SLOT="${PVR}"
27 IUSE="$IUSE vhosts"
28
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
36
37 # ------------------------------------------------------------------------
38 # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
39 #
40 # Check whether a specified file exists within the image/ directory
41 # or not.
42 #
43 # @param $1 - file to look for
44 # @param $2 - prefix directory to use
45 # @return 0 on success, never returns on an error
46 # ------------------------------------------------------------------------
47
48 function webapp_checkfileexists ()
49 {
50 if [ ! -e $1 ]; then
51 msg="ebuild fault: file $1 not found"
52 eerror "$msg"
53 eerror "Please report this as a bug at http://bugs.gentoo.org/"
54 die "$msg"
55 fi
56 }
57
58 # ------------------------------------------------------------------------
59 # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
60 # ------------------------------------------------------------------------
61
62 function webapp_import_config ()
63 {
64 if [ -z "${MY_HTDOCSDIR}" ]; then
65 . /etc/conf.d/webapp-config
66 fi
67
68 if [ -z "${MY_HTDOCSDIR}" ]; then
69 libsh_edie "/etc/conf.d/webapp-config not imported"
70 fi
71 }
72
73 # ------------------------------------------------------------------------
74 # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
75 #
76 # ------------------------------------------------------------------------
77
78 function webapp_strip_appdir ()
79 {
80 echo "$1" | sed -e "s|${MY_APPDIR}/||g;"
81 }
82
83 function webapp_strip_d ()
84 {
85 echo "$1" | sed -e "s|${D}||g;"
86 }
87
88 function webapp_strip_cwd ()
89 {
90 echo "$1" | sed -e 's|/./|/|g;'
91 }
92
93 # ------------------------------------------------------------------------
94 # EXPORTED FUNCTION - FOR USE IN EBUILDS
95 #
96 # Identify a config file for a web-based application.
97 #
98 # @param $1 - config file
99 # ------------------------------------------------------------------------
100
101 function webapp_configfile ()
102 {
103 webapp_checkfileexists "$1" "$D"
104 local MY_FILE="`webapp_strip_appdir $1`"
105
106 einfo "(config) $MY_FILE"
107 echo "$MY_FILE" >> $WA_CONFIGLIST
108 }
109
110 # ------------------------------------------------------------------------
111 # EXPORTED FUNCTION - FOR USE IN EBUILDS
112 #
113 # Identify a script file (usually, but not always PHP or Perl) which is
114 #
115 # Files in this list may be modified to #! the required CGI engine when
116 # installed by webapp-config tool in the future.
117 #
118 # @param $1 - the cgi engine to use
119 # @param $2 - the script file that could run under a cgi-bin
120 #
121 # ------------------------------------------------------------------------
122
123 function webapp_runbycgibin ()
124 {
125 webapp_checkfileexists "$2" "$D"
126 local MY_FILE="`webapp_strip_appdir $2`"
127 MY_FILE="`webapp_strip_cwd $MY_FILE`"
128
129 einfo "(cgi-bin) $1 - $MY_FILE"
130 echo "$1 $MY_FILE" >> $WA_RUNBYCGIBINLIST
131 }
132
133 # ------------------------------------------------------------------------
134 # EXPORTED FUNCTION - FOR USE IN EBUILDS
135 #
136 # Identify a file which must be owned by the webserver's user:group
137 # settings.
138 #
139 # The ownership of the file is NOT set until the application is installed
140 # using the webapp-config tool.
141 #
142 # @param $1 - file to be owned by the webserver user:group combo
143 #
144 # ------------------------------------------------------------------------
145
146 function webapp_serverowned ()
147 {
148 webapp_checkfileexists "$1" "$D"
149 local MY_FILE="`webapp_strip_appdir $1`"
150
151 einfo "(server owned) $MY_FILE"
152 echo "$MY_FILE" >> $WA_SOLIST
153 }
154
155 # ------------------------------------------------------------------------
156 # EXPORTED FUNCTION - FOR USE IN EBUILDS
157 #
158 #
159 # @param $1 - the db engine that the script is for
160 # (one of: mysql|postgres)
161 # @param $2 - the sql script to be installed
162 # @param $3 - the older version of the app that this db script
163 # will upgrade from
164 # (do not pass this option if your SQL script only creates
165 # a new db from scratch)
166 # ------------------------------------------------------------------------
167
168 function webapp_sqlscript ()
169 {
170 webapp_checkfileexists "$2"
171
172 # create the directory where this script will go
173 #
174 # scripts for specific database engines go into their own subdirectory
175 # just to keep things readable on the filesystem
176
177 if [ ! -d "${MY_SQLSCRIPTSDIR}/$1" ]; then
178 mkdir -p "${MY_SQLSCRIPTSDIR}/$1" || libsh_die "unable to create directory ${MY_SQLSCRIPTSDIR}/$1"
179 fi
180
181 # warning:
182 #
183 # do NOT change the naming convention used here without changing all
184 # the other scripts that also rely upon these names
185
186 # are we dealing with an 'upgrade'-type script?
187 if [ -n "$3" ]; then
188 # yes we are
189 einfo "($1) upgrade script from ${PN}-${PVR} to $3"
190 cp $2 ${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql
191 else
192 # no, we are not
193 einfo "($1) create script for ${PN}-${PVR}"
194 cp $2 ${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql
195 fi
196 }
197
198 # ------------------------------------------------------------------------
199 # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
200 # everything else has run
201 #
202 # For now, we just make sure that root owns everything, and that there
203 # are no setuid files. I'm sure this will change significantly before
204 # the final version!
205 # ------------------------------------------------------------------------
206
207 function webapp_src_install ()
208 {
209 chown -R root:root ${D}/
210 chmod -R u-s ${D}/
211 chmod -R g-s ${D}/
212 }
213
214 # ------------------------------------------------------------------------
215 # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
216 # everything else has run
217 #
218 # If 'vhosts' USE flag is not set, auto-install this app
219 #
220 # ------------------------------------------------------------------------
221
222 function webapp_pkg_setup ()
223 {
224 # are we emerging something that is already installed?
225
226 if [ -d "${MY_APPROOT}/${MY_APPSUFFIX}" ]; then
227 # yes we are
228 ewarn "Removing existing copy of ${PN}-${PVR}"
229 rm -rf "${MY_APPROOT}/${MY_APPSUFFIX}"
230 fi
231
232 # create the directories that we need
233
234 mkdir -p ${MY_HTDOCSDIR}
235 mkdir -p ${MY_HOSTROOTDIR}
236 mkdir -p ${MY_CGIBINDIR}
237 mkdir -p ${MY_ICONSDIR}
238 mkdir -p ${MY_ERRORSDIR}
239 mkdir -p ${MY_SQLSCRIPTSDIR}
240 }
241
242 function webapp_pkg_config ()
243 {
244 use vhosts || webapp-config -u root -d /var/www/localhost/htdocs/${PN}/ ${PN}
245 }

  ViewVC Help
Powered by ViewVC 1.1.20