| 1 | # Copyright 1999-2004 Gentoo Technologies, Inc. |
1 | # Copyright 1999-2004 Gentoo Foundation |
| 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.13 2004/04/30 08:25:38 stuart Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.32 2005/07/06 20:20:04 agriffis 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 |
| 9 | # |
9 | # |
| 10 | # Author(s) Stuart Herbert <stuart@gentoo.org> |
10 | # Author(s) Stuart Herbert <stuart@gentoo.org> |
| 11 | # |
11 | # |
| 12 | # ------------------------------------------------------------------------ |
12 | # ------------------------------------------------------------------------ |
| 13 | # |
13 | # |
| 14 | # Please do not make modifications to this file without checking with a |
14 | # The master copy of this eclass is held in Stu's subversion repository. |
| 15 | # member of the web-apps herd first! |
|
|
| 16 | # |
15 | # |
|
|
16 | # If you make changes to this file and don't tell Stu, chances are that |
|
|
17 | # your changes will be overwritten the next time Stu releases a new version |
|
|
18 | # of webapp-config. |
|
|
19 | # |
| 17 | # ------------------------------------------------------------------------ |
20 | # ------------------------------------------------------------------------ |
| 18 | |
21 | |
| 19 | ECLASS=webapp |
|
|
| 20 | INHERITED="$INHERITED $ECLASS" |
22 | INHERITED="$INHERITED $ECLASS" |
| 21 | SLOT="${PVR}" |
23 | SLOT="${PVR}" |
| 22 | IUSE="$IUSE vhosts" |
24 | IUSE="$IUSE vhosts" |
| 23 | DEPEND="$DEPEND >=net-www/webapp-config-1.6" |
25 | DEPEND="$DEPEND net-www/webapp-config app-portage/gentoolkit" |
| 24 | |
26 | |
| 25 | EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install |
27 | EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install pkg_prerm |
|
|
28 | |
|
|
29 | INSTALL_DIR="/$PN" |
|
|
30 | IS_UPGRADE=0 |
|
|
31 | IS_REPLACE=0 |
|
|
32 | |
|
|
33 | INSTALL_CHECK_FILE="installed_by_webapp_eclass" |
|
|
34 | |
|
|
35 | ETC_CONFIG="/etc/vhosts/webapp-config" |
| 26 | |
36 | |
| 27 | # ------------------------------------------------------------------------ |
37 | # ------------------------------------------------------------------------ |
| 28 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
38 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
| 29 | # |
39 | # |
| 30 | # Check whether a specified file exists within the image/ directory |
40 | # Check whether a specified file exists within the image/ directory |
| … | |
… | |
| 39 | { |
49 | { |
| 40 | local my_prefix |
50 | local my_prefix |
| 41 | |
51 | |
| 42 | [ -n "$2" ] && my_prefix="$2/" || my_prefix= |
52 | [ -n "$2" ] && my_prefix="$2/" || my_prefix= |
| 43 | |
53 | |
| 44 | if [ ! -e ${my_prefix}$1 ]; then |
54 | if [ ! -e "${my_prefix}$1" ]; then |
| 45 | msg="ebuild fault: file $1 not found" |
55 | msg="ebuild fault: file '$1' not found" |
| 46 | eerror "$msg" |
56 | eerror "$msg" |
| 47 | eerror "Please report this as a bug at http://bugs.gentoo.org/" |
57 | eerror "Please report this as a bug at http://bugs.gentoo.org/" |
| 48 | die "$msg" |
58 | die "$msg" |
| 49 | fi |
59 | fi |
| 50 | } |
60 | } |
| 51 | |
61 | |
| 52 | # ------------------------------------------------------------------------ |
62 | # ------------------------------------------------------------------------ |
| 53 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
63 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
| 54 | # ------------------------------------------------------------------------ |
64 | # ------------------------------------------------------------------------ |
| 55 | |
65 | |
|
|
66 | function webapp_check_installedat |
|
|
67 | { |
|
|
68 | local my_output |
|
|
69 | |
|
|
70 | /usr/sbin/webapp-config --show-installed -h localhost -d "$INSTALL_DIR" 2> /dev/null |
|
|
71 | } |
|
|
72 | |
|
|
73 | # ------------------------------------------------------------------------ |
|
|
74 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
|
|
75 | # ------------------------------------------------------------------------ |
|
|
76 | |
| 56 | function webapp_import_config () |
77 | function webapp_import_config () |
| 57 | { |
78 | { |
| 58 | if [ -z "${MY_HTDOCSDIR}" ]; then |
79 | if [ -z "${MY_HTDOCSDIR}" ]; then |
| 59 | . /etc/conf.d/webapp-config |
80 | . /etc/conf.d/webapp-config |
| 60 | fi |
81 | fi |
| … | |
… | |
| 69 | # |
90 | # |
| 70 | # ------------------------------------------------------------------------ |
91 | # ------------------------------------------------------------------------ |
| 71 | |
92 | |
| 72 | function webapp_strip_appdir () |
93 | function webapp_strip_appdir () |
| 73 | { |
94 | { |
|
|
95 | local my_stripped="$1" |
| 74 | echo "$1" | sed -e "s|${MY_APPDIR}/||g;" |
96 | echo "$1" | sed -e "s|${MY_APPDIR}/||g;" |
| 75 | } |
97 | } |
| 76 | |
98 | |
| 77 | function webapp_strip_d () |
99 | function webapp_strip_d () |
| 78 | { |
100 | { |
| 79 | echo "$1" | sed -e "s|${D}||g;" |
101 | echo "$1" | sed -e "s|${D}||g;" |
| 80 | } |
102 | } |
| 81 | |
103 | |
| 82 | function webapp_strip_cwd () |
104 | function webapp_strip_cwd () |
| 83 | { |
105 | { |
|
|
106 | local my_stripped="$1" |
| 84 | echo "$1" | sed -e 's|/./|/|g;' |
107 | echo "$1" | sed -e 's|/./|/|g;' |
| 85 | } |
108 | } |
| 86 | |
109 | |
| 87 | # ------------------------------------------------------------------------ |
110 | # ------------------------------------------------------------------------ |
| 88 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
111 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| … | |
… | |
| 93 | # ------------------------------------------------------------------------ |
116 | # ------------------------------------------------------------------------ |
| 94 | |
117 | |
| 95 | function webapp_configfile () |
118 | function webapp_configfile () |
| 96 | { |
119 | { |
| 97 | webapp_checkfileexists "$1" "$D" |
120 | webapp_checkfileexists "$1" "$D" |
| 98 | echo $1 |
121 | |
| 99 | local MY_FILE="`webapp_strip_appdir $1`" |
122 | local MY_FILE="`webapp_strip_appdir \"$1\"`" |
| 100 | echo $MY_FILE |
123 | MY_FILE="`webapp_strip_cwd \"$MY_FILE\"`" |
| 101 | |
124 | |
| 102 | einfo "(config) $MY_FILE" |
125 | einfo "(config) $MY_FILE" |
| 103 | echo "$MY_FILE" >> ${D}${WA_CONFIGLIST} |
126 | echo "$MY_FILE" >> ${D}${WA_CONFIGLIST} |
| 104 | } |
127 | } |
| 105 | |
128 | |
| 106 | # ------------------------------------------------------------------------ |
129 | # ------------------------------------------------------------------------ |
| 107 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
130 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 108 | # |
131 | # |
|
|
132 | # Install a script that will run after a virtual copy is created, and |
|
|
133 | # before a virtual copy has been removed |
|
|
134 | # |
|
|
135 | # @param $1 - the script to run |
|
|
136 | # ------------------------------------------------------------------------ |
|
|
137 | |
|
|
138 | function webapp_hook_script () |
|
|
139 | { |
|
|
140 | webapp_checkfileexists "$1" |
|
|
141 | |
|
|
142 | einfo "(hook) $1" |
|
|
143 | cp "$1" "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`" || die "Unable to install $1 into ${D}${MY_HOOKSCRIPTSDIR}/" |
|
|
144 | chmod 555 "${D}${MY_HOOKSCRIPTSDIR}/`basename $1`" |
|
|
145 | } |
|
|
146 | |
|
|
147 | # ------------------------------------------------------------------------ |
|
|
148 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
|
|
149 | # |
| 109 | # Install a text file containing post-installation instructions. |
150 | # Install a text file containing post-installation instructions. |
| 110 | # |
151 | # |
| 111 | # @param $1 - language code (use 'en' for now) |
152 | # @param $1 - language code (use 'en' for now) |
| 112 | # @param $2 - the file to install |
153 | # @param $2 - the file to install |
| 113 | # ------------------------------------------------------------------------ |
154 | # ------------------------------------------------------------------------ |
| 114 | |
155 | |
| 115 | function webapp_postinst_txt |
156 | function webapp_postinst_txt () |
| 116 | { |
157 | { |
| 117 | webapp_checkfileexists "$2" |
158 | webapp_checkfileexists "$2" |
| 118 | |
159 | |
| 119 | einfo "(rtfm) $2 (lang: $1)" |
160 | einfo "(rtfm) $2 (lang: $1)" |
| 120 | cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt" |
161 | cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt" |
| 121 | } |
162 | } |
| 122 | |
163 | |
| 123 | # ------------------------------------------------------------------------ |
164 | # ------------------------------------------------------------------------ |
| 124 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
165 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 125 | # |
166 | # |
| 126 | # Identify a script file (usually, but not always PHP or Perl) which is |
167 | # Install a text file containing post-upgrade instructions. |
| 127 | # |
168 | # |
| 128 | # Files in this list may be modified to #! the required CGI engine when |
169 | # @param $1 - language code (use 'en' for now) |
| 129 | # installed by webapp-config tool in the future. |
170 | # @param $2 - the file to install |
| 130 | # |
|
|
| 131 | # @param $1 - the cgi engine to use |
|
|
| 132 | # @param $2 - the script file that could run under a cgi-bin |
|
|
| 133 | # |
|
|
| 134 | # ------------------------------------------------------------------------ |
171 | # ------------------------------------------------------------------------ |
|
|
172 | |
|
|
173 | function webapp_postupgrade_txt () |
|
|
174 | { |
|
|
175 | webapp_checkfileexists "$2" |
|
|
176 | |
|
|
177 | einfo "(rtfm) $2 (lang: $1)" |
|
|
178 | cp "$2" "${D}${MY_APPDIR}/postupgrade-$1.txt" |
|
|
179 | } |
|
|
180 | |
|
|
181 | # ------------------------------------------------------------------------ |
|
|
182 | # DEPRECATED FUNCTION |
|
|
183 | # |
|
|
184 | # It never worked anyway |
| 135 | |
185 | |
| 136 | function webapp_runbycgibin () |
186 | function webapp_runbycgibin () |
| 137 | { |
187 | { |
| 138 | webapp_checkfileexists "$2" "$D" |
188 | if [ -n "$WARN_RUNBYCGIBIN" ] ; then |
| 139 | local MY_FILE="`webapp_strip_appdir $2`" |
189 | return |
| 140 | MY_FILE="`webapp_strip_cwd $MY_FILE`" |
190 | fi |
| 141 | |
191 | |
| 142 | einfo "(cgi-bin) $1 - $MY_FILE" |
192 | ewarn "This ebuild uses webapp.eclass's webapp_runbycgibin, which is now" |
| 143 | echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST} |
193 | ewarn "deprecated. Please file a bug about this in Bugzilla." |
|
|
194 | WARN_RUNBYCGIBIN=1 |
| 144 | } |
195 | } |
| 145 | |
196 | |
| 146 | # ------------------------------------------------------------------------ |
197 | # ------------------------------------------------------------------------ |
| 147 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
198 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 148 | # |
199 | # |
| … | |
… | |
| 157 | # ------------------------------------------------------------------------ |
208 | # ------------------------------------------------------------------------ |
| 158 | |
209 | |
| 159 | function webapp_serverowned () |
210 | function webapp_serverowned () |
| 160 | { |
211 | { |
| 161 | webapp_checkfileexists "$1" "$D" |
212 | webapp_checkfileexists "$1" "$D" |
| 162 | local MY_FILE="`webapp_strip_appdir $1`" |
213 | local MY_FILE="`webapp_strip_appdir \"$1\"`" |
|
|
214 | MY_FILE="`webapp_strip_cwd \"$MY_FILE\"`" |
| 163 | |
215 | |
| 164 | einfo "(server owned) $MY_FILE" |
216 | einfo "(server owned) $MY_FILE" |
| 165 | echo "$MY_FILE" >> ${D}${WA_SOLIST} |
217 | echo "$MY_FILE" >> "${D}${WA_SOLIST}" |
| 166 | } |
218 | } |
| 167 | |
219 | |
| 168 | # ------------------------------------------------------------------------ |
220 | # ------------------------------------------------------------------------ |
| 169 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
221 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 170 | # |
222 | # |
|
|
223 | # @param $1 - the webserver to install the config file for |
|
|
224 | # (one of apache1, apache2, cherokee) |
|
|
225 | # @param $2 - the config file to install |
|
|
226 | # @param $3 - new name for the config file (default is `basename $2`) |
|
|
227 | # this is an optional parameter |
|
|
228 | # |
|
|
229 | # NOTE: |
|
|
230 | # this function will automagically prepend $1 to the front of your |
|
|
231 | # config file's name |
|
|
232 | # ------------------------------------------------------------------------ |
|
|
233 | |
|
|
234 | function webapp_server_configfile () |
|
|
235 | { |
|
|
236 | webapp_checkfileexists "$2" |
|
|
237 | |
|
|
238 | # sort out what the name will be of the config file |
|
|
239 | |
|
|
240 | local my_file |
|
|
241 | |
|
|
242 | if [ -z "$3" ]; then |
|
|
243 | my_file="$1-`basename $2`" |
|
|
244 | else |
|
|
245 | my_file="$1-$3" |
|
|
246 | fi |
|
|
247 | |
|
|
248 | # warning: |
|
|
249 | # |
|
|
250 | # do NOT change the naming convention used here without changing all |
|
|
251 | # the other scripts that also rely upon these names |
|
|
252 | |
|
|
253 | einfo "($1) config file '$my_file'" |
|
|
254 | cp "$2" "${D}${MY_SERVERCONFIGDIR}/${my_file}" |
|
|
255 | } |
|
|
256 | |
|
|
257 | # ------------------------------------------------------------------------ |
|
|
258 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 171 | # |
259 | # |
| 172 | # @param $1 - the db engine that the script is for |
260 | # @param $1 - the db engine that the script is for |
| 173 | # (one of: mysql|postgres) |
261 | # (one of: mysql|postgres) |
| 174 | # @param $2 - the sql script to be installed |
262 | # @param $2 - the sql script to be installed |
| 175 | # @param $3 - the older version of the app that this db script |
263 | # @param $3 - the older version of the app that this db script |
| … | |
… | |
| 198 | |
286 | |
| 199 | # are we dealing with an 'upgrade'-type script? |
287 | # are we dealing with an 'upgrade'-type script? |
| 200 | if [ -n "$3" ]; then |
288 | if [ -n "$3" ]; then |
| 201 | # yes we are |
289 | # yes we are |
| 202 | einfo "($1) upgrade script from ${PN}-${PVR} to $3" |
290 | einfo "($1) upgrade script from ${PN}-${PVR} to $3" |
| 203 | cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql |
291 | cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql" |
|
|
292 | chmod 600 "${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql" |
| 204 | else |
293 | else |
| 205 | # no, we are not |
294 | # no, we are not |
| 206 | einfo "($1) create script for ${PN}-${PVR}" |
295 | einfo "($1) create script for ${PN}-${PVR}" |
| 207 | cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql |
296 | cp "$2" "${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql" |
|
|
297 | chmod 600 "${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql" |
| 208 | fi |
298 | fi |
| 209 | } |
299 | } |
| 210 | |
300 | |
| 211 | # ------------------------------------------------------------------------ |
301 | # ------------------------------------------------------------------------ |
| 212 | # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER |
302 | # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER |
| … | |
… | |
| 217 | # the final version! |
307 | # the final version! |
| 218 | # ------------------------------------------------------------------------ |
308 | # ------------------------------------------------------------------------ |
| 219 | |
309 | |
| 220 | function webapp_src_install () |
310 | function webapp_src_install () |
| 221 | { |
311 | { |
| 222 | chown -R root:root ${D}/ |
312 | chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/" |
| 223 | chmod -R u-s ${D}/ |
313 | chmod -R u-s "${D}/" |
| 224 | chmod -R g-s ${D}/ |
314 | chmod -R g-s "${D}/" |
| 225 | |
315 | |
| 226 | keepdir ${MY_PERSISTDIR} |
316 | keepdir "${MY_PERSISTDIR}" |
| 227 | fowners root:root ${MY_PERSISTDIR} |
317 | fowners "root:root" "${MY_PERSISTDIR}" |
| 228 | fperms 755 ${MY_PERSISTDIR} |
318 | fperms 755 "${MY_PERSISTDIR}" |
|
|
319 | |
|
|
320 | # to test whether or not the ebuild has correctly called this function |
|
|
321 | # we add an empty file to the filesystem |
|
|
322 | # |
|
|
323 | # we used to just set a variable in the shell script, but we can |
|
|
324 | # no longer rely on Portage calling both webapp_src_install() and |
|
|
325 | # webapp_pkg_postinst() within the same shell process |
|
|
326 | |
|
|
327 | touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}" |
| 229 | } |
328 | } |
| 230 | |
329 | |
| 231 | # ------------------------------------------------------------------------ |
330 | # ------------------------------------------------------------------------ |
| 232 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER |
331 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER |
| 233 | # everything else has run |
332 | # everything else has run |
| … | |
… | |
| 236 | # |
335 | # |
| 237 | # ------------------------------------------------------------------------ |
336 | # ------------------------------------------------------------------------ |
| 238 | |
337 | |
| 239 | function webapp_pkg_setup () |
338 | function webapp_pkg_setup () |
| 240 | { |
339 | { |
|
|
340 | # add sanity checks here |
|
|
341 | |
|
|
342 | if [ "$SLOT+" != "${PVR}+" ]; then |
|
|
343 | die "ebuild sets SLOT, overrides webapp.eclass" |
|
|
344 | fi |
|
|
345 | |
| 241 | # pull in the shared configuration file |
346 | # pull in the shared configuration file |
| 242 | |
347 | |
| 243 | . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file" |
348 | G_HOSTNAME="localhost" |
|
|
349 | . "${ETC_CONFIG}" || die "Unable to open file ${ETC_CONFIG}" |
| 244 | |
350 | |
|
|
351 | # are we installing a webapp-config solution over the top of a |
|
|
352 | # non-webapp-config solution? |
|
|
353 | |
|
|
354 | if ! use vhosts ; then |
|
|
355 | local my_dir="$VHOST_ROOT/$MY_HTDOCSBASE/$PN" |
|
|
356 | local my_output |
|
|
357 | |
|
|
358 | if [ -d "$my_dir" ] ; then |
|
|
359 | einfo "You already have something installed in $my_dir" |
|
|
360 | einfo "Are you trying to install over the top of something I cannot upgrade?" |
|
|
361 | |
|
|
362 | my_output="`webapp_check_installedat`" |
|
|
363 | |
|
|
364 | if [ "$?" != "0" ]; then |
|
|
365 | |
|
|
366 | # okay, whatever is there, it isn't webapp-config-compatible |
|
|
367 | ewarn |
|
|
368 | ewarn "Whatever is in $my_dir, it's not" |
|
|
369 | ewarn "compatible with webapp-config." |
|
|
370 | ewarn |
|
|
371 | ewarn "This ebuild may be overwriting important files." |
|
|
372 | ewarn |
|
|
373 | elif [ "`echo $my_output | awk '{ print $1 }'`" != "$PN" ]; then |
|
|
374 | eerror "$my_dir contains $my_output" |
|
|
375 | eerror "I cannot upgrade that" |
|
|
376 | die "Cannot upgrade contents of $my_dir" |
|
|
377 | else |
|
|
378 | einfo |
|
|
379 | einfo "I can upgrade the contents of $my_dir" |
|
|
380 | einfo |
|
|
381 | fi |
|
|
382 | fi |
|
|
383 | fi |
|
|
384 | } |
|
|
385 | |
|
|
386 | function webapp_someunusedfunction () |
|
|
387 | { |
| 245 | # are we emerging something that is already installed? |
388 | # are we emerging something that is already installed? |
| 246 | |
389 | |
| 247 | if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then |
390 | if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then |
| 248 | # yes we are |
391 | # yes we are |
| 249 | ewarn "Removing existing copy of ${PN}-${PVR}" |
392 | ewarn "Removing existing copy of ${PN}-${PVR}" |
| 250 | rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}" |
393 | rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}" |
| 251 | fi |
394 | fi |
| 252 | } |
395 | } |
| 253 | |
396 | |
|
|
397 | function webapp_getinstalltype () |
|
|
398 | { |
|
|
399 | # or are we upgrading? |
|
|
400 | |
|
|
401 | if ! use vhosts ; then |
|
|
402 | # we only run webapp-config if vhosts USE flag is not set |
|
|
403 | |
|
|
404 | local my_output |
|
|
405 | |
|
|
406 | my_output="`webapp_check_installedat`" |
|
|
407 | |
|
|
408 | if [ "$?" = "0" ] ; then |
|
|
409 | # something is already installed there |
|
|
410 | # |
|
|
411 | # make sure it isn't the same version |
|
|
412 | |
|
|
413 | local my_pn="`echo $my_output | awk '{ print $1 }'`" |
|
|
414 | local my_pvr="`echo $my_output | awk '{ print $2 }'`" |
|
|
415 | |
|
|
416 | REMOVE_PKG="${my_pn}-${my_pvr}" |
|
|
417 | |
|
|
418 | if [ "$my_pn" == "$PN" ]; then |
|
|
419 | if [ "$my_pvr" != "$PVR" ]; then |
|
|
420 | einfo "This is an upgrade" |
|
|
421 | IS_UPGRADE=1 |
|
|
422 | else |
|
|
423 | einfo "This is a re-installation" |
|
|
424 | IS_REPLACE=1 |
|
|
425 | fi |
|
|
426 | else |
|
|
427 | einfo "$my_ouptut is installed there" |
|
|
428 | fi |
|
|
429 | else |
|
|
430 | einfo "This is an installation" |
|
|
431 | fi |
|
|
432 | fi |
|
|
433 | } |
|
|
434 | |
| 254 | function webapp_src_preinst () |
435 | function webapp_src_preinst () |
| 255 | { |
436 | { |
| 256 | # create the directories that we need |
437 | # create the directories that we need |
| 257 | |
438 | |
| 258 | dodir ${MY_HTDOCSDIR} |
439 | dodir "${MY_HTDOCSDIR}" |
| 259 | dodir ${MY_HOSTROOTDIR} |
440 | dodir "${MY_HOSTROOTDIR}" |
| 260 | dodir ${MY_CGIBINDIR} |
441 | dodir "${MY_CGIBINDIR}" |
| 261 | dodir ${MY_ICONSDIR} |
442 | dodir "${MY_ICONSDIR}" |
| 262 | dodir ${MY_ERRORSDIR} |
443 | dodir "${MY_ERRORSDIR}" |
| 263 | dodir ${MY_SQLSCRIPTSDIR} |
444 | dodir "${MY_SQLSCRIPTSDIR}" |
|
|
445 | dodir "${MY_HOOKSCRIPTSDIR}" |
|
|
446 | dodir "${MY_SERVERCONFIGDIR}" |
| 264 | } |
447 | } |
| 265 | |
448 | |
| 266 | function webapp_pkg_postinst () |
449 | function webapp_pkg_postinst () |
| 267 | { |
450 | { |
| 268 | einfo "webapp_pkg_postinst() called" |
451 | . "${ETC_CONFIG}" |
|
|
452 | |
|
|
453 | # sanity checks, to catch bugs in the ebuild |
|
|
454 | |
|
|
455 | if [ ! -f "${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]; then |
|
|
456 | eerror |
|
|
457 | eerror "This ebuild did not call webapp_src_install() at the end" |
|
|
458 | eerror "of the src_install() function" |
|
|
459 | eerror |
|
|
460 | eerror "Please log a bug on http://bugs.gentoo.org" |
|
|
461 | eerror |
|
|
462 | eerror "You should use emerge -C to remove this package, as the" |
|
|
463 | eerror "installation is incomplete" |
|
|
464 | eerror |
|
|
465 | die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org" |
|
|
466 | fi |
| 269 | |
467 | |
| 270 | # if 'vhosts' is not set in your USE flags, we install a copy of |
468 | # 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 |
469 | # this application in /var/www/localhost/htdocs/${PN}/ for you |
| 272 | |
|
|
| 273 | |
470 | |
| 274 | if ! use vhosts ; then |
471 | if ! use vhosts ; then |
|
|
472 | echo |
| 275 | einfo "vhosts USE flag not set - auto-installing using webapp-config" |
473 | einfo "vhosts USE flag not set - auto-installing using webapp-config" |
| 276 | |
474 | |
|
|
475 | webapp_getinstalltype |
|
|
476 | |
| 277 | G_HOSTNAME="localhost" |
477 | G_HOSTNAME="localhost" |
| 278 | . /etc/vhosts/webapp-config |
478 | . "${ETC_CONFIG}" |
| 279 | |
479 | |
| 280 | local my_mode=-I |
480 | local my_mode=-I |
| 281 | local my_dir="/${PN}" |
|
|
| 282 | |
481 | |
| 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 |
482 | if [ "$IS_REPLACE" = "1" ]; then |
| 295 | |
483 | einfo "${PN}-${PVR} is already installed - replacing" |
| 296 | # something is in there - but the question has to be ... what? |
484 | my_mode=-I |
| 297 | |
485 | elif [ "$IS_UPGRADE" = "1" ]; then |
| 298 | ewarn "$my_output already installed" |
486 | einfo "$REMOVE_PKG is already installed - upgrading" |
| 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 |
487 | 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 |
488 | else |
| 328 | einfo "${PN}-${PVR} is not installed - using install mode" |
489 | einfo "${PN}-${PVR} is not installed - using install mode" |
| 329 | fi |
490 | fi |
| 330 | |
491 | |
| 331 | my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $my_dir ${PN} ${PVR}" |
492 | my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $INSTALL_DIR ${PN} ${PVR}" |
| 332 | einfo "Running $my_cmd" |
493 | einfo "Running $my_cmd" |
| 333 | $my_cmd |
494 | $my_cmd |
|
|
495 | |
|
|
496 | # remove the old version |
|
|
497 | # |
|
|
498 | # why do we do this? well ... |
|
|
499 | # |
|
|
500 | # normally, emerge -u installs a new version and then removes the |
|
|
501 | # old version. however, if the new version goes into a different |
|
|
502 | # slot to the old version, then the old version gets left behind |
|
|
503 | # |
|
|
504 | # if USE=-vhosts, then we want to remove the old version, because |
|
|
505 | # the user is relying on portage to do the magical thing for it |
|
|
506 | |
|
|
507 | if [ "$IS_UPGRADE" = "1" ] ; then |
|
|
508 | einfo "Removing old version $REMOVE_PKG" |
|
|
509 | |
|
|
510 | emerge -C "$REMOVE_PKG" |
|
|
511 | fi |
|
|
512 | else |
|
|
513 | # vhosts flag is on |
|
|
514 | # |
|
|
515 | # let's tell the administrator what to do next |
|
|
516 | |
|
|
517 | einfo |
|
|
518 | einfo "The 'vhosts' USE flag is switched ON" |
|
|
519 | einfo "This means that Portage will not automatically run webapp-config to" |
|
|
520 | einfo "complete the installation." |
|
|
521 | einfo |
|
|
522 | einfo "To install $PN-$PVR into a virtual host, run the following command:" |
|
|
523 | einfo |
|
|
524 | einfo " webapp-config -I -h <host> -d $PN $PN $PVR" |
|
|
525 | einfo |
|
|
526 | einfo "For more details, see the webapp-config(8) man page" |
| 334 | fi |
527 | fi |
| 335 | |
528 | |
| 336 | return 0 |
529 | return 0 |
| 337 | } |
530 | } |
|
|
531 | |
|
|
532 | function webapp_pkg_prerm () |
|
|
533 | { |
|
|
534 | # remove any virtual installs that there are |
|
|
535 | |
|
|
536 | local my_output |
|
|
537 | local x |
|
|
538 | |
|
|
539 | my_output="`webapp-config --list-installs $PN $PVR`" |
|
|
540 | |
|
|
541 | if [ "$?" != "0" ]; then |
|
|
542 | return |
|
|
543 | fi |
|
|
544 | |
|
|
545 | # the changes to IFS here are necessary to ensure that we can cope |
|
|
546 | # with directories that contain spaces in the file names |
|
|
547 | |
|
|
548 | # OLD_IFS="$IFS" |
|
|
549 | # IFS="
" |
|
|
550 | |
|
|
551 | for x in $my_output ; do |
|
|
552 | # IFS="$OLD_IFS" |
|
|
553 | |
|
|
554 | [ -f $x/.webapp ] && . $x/.webapp || ewarn "Cannot find file $x/.webapp" |
|
|
555 | |
|
|
556 | if [ -z "WEB_HOSTNAME" -o -z "WEB_INSTALLDIR" ]; then |
|
|
557 | ewarn "Don't forget to use webapp-config to remove the copy of" |
|
|
558 | ewarn "${PN}-${PVR} installed in" |
|
|
559 | ewarn |
|
|
560 | ewarn " $x" |
|
|
561 | ewarn |
|
|
562 | else |
|
|
563 | # we have enough information to remove the virtual copy ourself |
|
|
564 | |
|
|
565 | webapp-config -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR} |
|
|
566 | |
|
|
567 | # if the removal fails - we carry on anyway! |
|
|
568 | fi |
|
|
569 | # IFS="
" |
|
|
570 | done |
|
|
571 | |
|
|
572 | # IFS="$OLD_IFS" |
|
|
573 | } |