| 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.1 2003/10/07 21:54:46 stuart Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.10 2004/04/28 22:18:27 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 |
| … | |
… | |
| 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 | # |
16 | # |
| 17 | # ------------------------------------------------------------------------ |
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 | |
18 | |
| 24 | ECLASS=webapp |
19 | ECLASS=webapp |
| 25 | INHERITED="$INHERITED $ECLASS" |
20 | INHERITED="$INHERITED $ECLASS" |
| 26 | #DEPEND="${DEPEND} net-www/apache" |
|
|
| 27 | SLOT="${PVR}" |
21 | SLOT="${PVR}" |
| 28 | IUSE="$IUSE vhosts" |
22 | IUSE="$IUSE vhosts" |
|
|
23 | DEPEND="$DEPEND >=net-www/webapp-config-1.5" |
| 29 | |
24 | |
| 30 | if [ -f /usr/share/webapp-config/settings.sh ] ; then |
|
|
| 31 | . /usr/share/webapp-config/settings.sh |
|
|
| 32 | fi |
|
|
| 33 | |
|
|
| 34 | EXPORT_FUNCTIONS pkg_setup src_install |
25 | EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install |
| 35 | |
26 | |
| 36 | # ------------------------------------------------------------------------ |
27 | # ------------------------------------------------------------------------ |
| 37 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
28 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
| 38 | # |
29 | # |
| 39 | # Check whether a specified file exists within the image/ directory |
30 | # Check whether a specified file exists within the image/ directory |
| 40 | # or not. |
31 | # or not. |
| 41 | # |
32 | # |
| 42 | # @param $1 - file to look for |
33 | # @param $1 - file to look for |
|
|
34 | # @param $2 - prefix directory to use |
| 43 | # @return 0 on success, never returns on an error |
35 | # @return 0 on success, never returns on an error |
| 44 | # ------------------------------------------------------------------------ |
36 | # ------------------------------------------------------------------------ |
| 45 | |
37 | |
| 46 | function webapp_checkfileexists () |
38 | function webapp_checkfileexists () |
| 47 | { |
39 | { |
|
|
40 | local my_prefix |
|
|
41 | |
|
|
42 | [ -n "$2" ] && my_prefix="$2/" || my_prefix= |
|
|
43 | |
| 48 | if [ ! -e ${D}/$1 ]; then |
44 | if [ ! -e ${my_prefix}$1 ]; then |
| 49 | msg="ebuild fault: file $1 not found in ${D}" |
45 | msg="ebuild fault: file $1 not found" |
| 50 | eerror "$msg" |
46 | eerror "$msg" |
| 51 | 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/" |
| 52 | die "$msg" |
48 | die "$msg" |
| 53 | fi |
49 | fi |
|
|
50 | } |
|
|
51 | |
|
|
52 | # ------------------------------------------------------------------------ |
|
|
53 | # 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 | # |
|
|
70 | # ------------------------------------------------------------------------ |
|
|
71 | |
|
|
72 | function webapp_strip_appdir () |
|
|
73 | { |
|
|
74 | echo "$1" | sed -e "s|${D}${MY_APPDIR}/||g;" |
|
|
75 | } |
|
|
76 | |
|
|
77 | function webapp_strip_d () |
|
|
78 | { |
|
|
79 | echo "$1" | sed -e "s|${D}||g;" |
|
|
80 | } |
|
|
81 | |
|
|
82 | function webapp_strip_cwd () |
|
|
83 | { |
|
|
84 | echo "$1" | sed -e 's|/./|/|g;' |
|
|
85 | } |
|
|
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 | webapp_checkfileexists "$1" "$D" |
|
|
98 | local MY_FILE="`webapp_strip_appdir $1`" |
|
|
99 | |
|
|
100 | einfo "(config) $MY_FILE" |
|
|
101 | echo "$MY_FILE" >> ${D}${WA_CONFIGLIST} |
|
|
102 | } |
|
|
103 | |
|
|
104 | # ------------------------------------------------------------------------ |
|
|
105 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
|
|
106 | # |
|
|
107 | # 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 | cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt" |
|
|
119 | } |
|
|
120 | |
|
|
121 | # ------------------------------------------------------------------------ |
|
|
122 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
|
|
123 | # |
|
|
124 | # 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 | 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 | echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST} |
| 54 | } |
142 | } |
| 55 | |
143 | |
| 56 | # ------------------------------------------------------------------------ |
144 | # ------------------------------------------------------------------------ |
| 57 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
145 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 58 | # |
146 | # |
| … | |
… | |
| 66 | # |
154 | # |
| 67 | # ------------------------------------------------------------------------ |
155 | # ------------------------------------------------------------------------ |
| 68 | |
156 | |
| 69 | function webapp_serverowned () |
157 | function webapp_serverowned () |
| 70 | { |
158 | { |
| 71 | webapp_checkfileexists $1 |
159 | webapp_checkfileexists "$1" "$D" |
|
|
160 | local MY_FILE="`webapp_strip_appdir $1`" |
|
|
161 | |
|
|
162 | einfo "(server owned) $MY_FILE" |
| 72 | echo "$1" >> $WA_SOLIST |
163 | echo "$MY_FILE" >> ${D}${WA_SOLIST} |
| 73 | } |
164 | } |
| 74 | |
165 | |
| 75 | # ------------------------------------------------------------------------ |
166 | # ------------------------------------------------------------------------ |
| 76 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
167 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 77 | # |
168 | # |
| 78 | # Identify a config file for a web-based application. |
|
|
| 79 | # |
169 | # |
| 80 | # @param $1 - config file |
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) |
| 81 | # ------------------------------------------------------------------------ |
177 | # ------------------------------------------------------------------------ |
| 82 | |
178 | |
| 83 | function webapp_configfile () |
179 | function webapp_sqlscript () |
| 84 | { |
180 | { |
| 85 | webapp_checkfileexists $1 |
|
|
| 86 | echo "$1" >> $WA_CONFIGLIST |
|
|
| 87 | } |
|
|
| 88 | |
|
|
| 89 | # ------------------------------------------------------------------------ |
|
|
| 90 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
|
|
| 91 | # |
|
|
| 92 | # Identify a script file (usually, but not always PHP or Perl) which is |
|
|
| 93 | # |
|
|
| 94 | # Files in this list may be modified to #! the required CGI engine when |
|
|
| 95 | # installed by webapp-config tool in the future. |
|
|
| 96 | # |
|
|
| 97 | # @param $1 - the cgi engine to use |
|
|
| 98 | # @param $2 - the script file that could run under a cgi-bin |
|
|
| 99 | # |
|
|
| 100 | # ------------------------------------------------------------------------ |
|
|
| 101 | |
|
|
| 102 | function webapp_runbycgibin () |
|
|
| 103 | { |
|
|
| 104 | webapp_checkfileexists $2 |
181 | webapp_checkfileexists "$2" |
| 105 | echo "$1 $2" >> $WA_RUNBYCGIBINLIST |
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 | 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 | 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 | cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql |
|
|
202 | else |
|
|
203 | # no, we are not |
|
|
204 | einfo "($1) create script for ${PN}-${PVR}" |
|
|
205 | cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql |
|
|
206 | fi |
| 106 | } |
207 | } |
| 107 | |
208 | |
| 108 | # ------------------------------------------------------------------------ |
209 | # ------------------------------------------------------------------------ |
| 109 | # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER |
210 | # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER |
| 110 | # everything else has run |
211 | # everything else has run |
| … | |
… | |
| 117 | function webapp_src_install () |
218 | function webapp_src_install () |
| 118 | { |
219 | { |
| 119 | chown -R root:root ${D}/ |
220 | chown -R root:root ${D}/ |
| 120 | chmod -R u-s ${D}/ |
221 | chmod -R u-s ${D}/ |
| 121 | chmod -R g-s ${D}/ |
222 | chmod -R g-s ${D}/ |
| 122 | } |
|
|
| 123 | |
223 | |
|
|
224 | keepdir ${MY_PERSISTDIR} |
|
|
225 | fowners root:root ${MY_PERSISTDIR} |
|
|
226 | fperms 755 ${MY_PERSISTDIR} |
|
|
227 | } |
|
|
228 | |
| 124 | # ------------------------------------------------------------------------ |
229 | # ------------------------------------------------------------------------ |
| 125 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_setup AFTER |
230 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER |
| 126 | # everything else has run |
231 | # everything else has run |
| 127 | # |
232 | # |
| 128 | # If 'vhosts' USE flag is not set, auto-install this app |
233 | # If 'vhosts' USE flag is not set, auto-install this app |
| 129 | # |
234 | # |
| 130 | # ------------------------------------------------------------------------ |
235 | # ------------------------------------------------------------------------ |
| 131 | |
236 | |
| 132 | function webapp_pkg_setup () |
237 | function webapp_pkg_setup () |
| 133 | { |
238 | { |
| 134 | use vhosts || webapp-config -u root -d /var/www/localhost/htdocs/${PN}/ ${PN} |
239 | # pull in the shared configuration file |
|
|
240 | |
|
|
241 | . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file" |
|
|
242 | |
|
|
243 | # are we emerging something that is already installed? |
|
|
244 | |
|
|
245 | if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then |
|
|
246 | # yes we are |
|
|
247 | ewarn "Removing existing copy of ${PN}-${PVR}" |
|
|
248 | rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}" |
|
|
249 | fi |
|
|
250 | } |
|
|
251 | |
|
|
252 | function webapp_src_preinst () |
|
|
253 | { |
|
|
254 | # create the directories that we need |
|
|
255 | |
|
|
256 | dodir ${MY_HTDOCSDIR} |
|
|
257 | dodir ${MY_HOSTROOTDIR} |
|
|
258 | dodir ${MY_CGIBINDIR} |
|
|
259 | dodir ${MY_ICONSDIR} |
|
|
260 | dodir ${MY_ERRORSDIR} |
|
|
261 | dodir ${MY_SQLSCRIPTSDIR} |
|
|
262 | } |
|
|
263 | |
|
|
264 | function webapp_pkg_postinst () |
|
|
265 | { |
|
|
266 | # if 'vhosts' is not set in your USE flags, we install a copy of |
|
|
267 | # this application in /var/www/localhost/htdocs/${PN}/ for you |
|
|
268 | |
|
|
269 | if ! use vhosts ; then |
|
|
270 | G_HOSTNAME="localhost" |
|
|
271 | . /etc/vhosts/webapp-config |
|
|
272 | |
|
|
273 | local my_mode=-I |
|
|
274 | local my_dir="${VHOST_ROOT}/htdocs/${PN}" |
|
|
275 | |
|
|
276 | # are we installing afresh - or are we upgrading? |
|
|
277 | # find out by looking to see what (if anything) is installed |
|
|
278 | # in there already |
|
|
279 | |
|
|
280 | local my_output="`/usr/sbin/webapp-config --show-installed -d $my_dir 2> /dev/null`" |
|
|
281 | if [ "$?" = 0 ]; then |
|
|
282 | |
|
|
283 | # something is in there - but the question has to be ... what? |
|
|
284 | |
|
|
285 | if [ "`echo $my_output | awk '{ print $1 }'`" = "${PN}" ]; then |
|
|
286 | # we have an older version of whatever it is our ebuild is |
|
|
287 | # trying to install ;-) |
|
|
288 | # |
|
|
289 | # this is the situation we can deal with |
|
|
290 | |
|
|
291 | my_mode=-U |
|
|
292 | else |
|
|
293 | # this should never happen - but just in case ... |
|
|
294 | # |
|
|
295 | # whatever is in that directory, it isn't the application |
|
|
296 | # that we are currently trying to install |
|
|
297 | # |
|
|
298 | # rather than overwrite the contents, we bail with an error |
|
|
299 | # instead |
|
|
300 | |
|
|
301 | die "$my_output is already installed in $my_dir" |
|
|
302 | fi |
|
|
303 | fi |
|
|
304 | |
|
|
305 | /usr/sbin/webapp-config $my_mode -u root -d "$my_dir" ${PN} ${PVR} |
|
|
306 | fi |
|
|
307 | } |