| 1 | # Copyright 1999-2006 Gentoo Foundation |
1 | # Copyright 1999-2006 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.47 2006/12/31 19:16:31 rl03 Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.50 2008/02/22 10:03:55 hollow Exp $ |
| 4 | # |
4 | # |
| 5 | # eclass/webapp.eclass |
5 | # @ECLASS: webapp.eclass |
|
|
6 | # @MAINTAINER: |
|
|
7 | # web-apps@gentoo.org |
| 6 | # Eclass for installing applications to run under a web server |
8 | # @BLURB: functions for installing applications to run under a web server |
| 7 | # |
9 | # @DESCRIPTION: |
|
|
10 | # The webapp eclass contains functions to handle web applications with |
| 8 | # Part of the implementation of GLEP #11 |
11 | # webapp-config. Part of the implementation of GLEP #11 |
| 9 | # |
|
|
| 10 | # Author(s) Stuart Herbert |
|
|
| 11 | # Renat Lumpau <rl03@gentoo.org> |
|
|
| 12 | # Gunnar Wrobel <wrobel@gentoo.org> |
|
|
| 13 | # |
|
|
| 14 | # ------------------------------------------------------------------------ |
|
|
| 15 | # |
|
|
| 16 | # The master copy of this eclass is held in our subversion repository. |
|
|
| 17 | # http://svn.gnqs.org/projects/vhost-tools/browser/ |
|
|
| 18 | # |
|
|
| 19 | # If you make changes to this file and don't tell us, chances are that |
|
|
| 20 | # your changes will be overwritten the next time we release a new version |
|
|
| 21 | # of webapp-config. |
|
|
| 22 | # |
|
|
| 23 | # ------------------------------------------------------------------------ |
|
|
| 24 | |
12 | |
| 25 | SLOT="${PVR}" |
13 | SLOT="${PVR}" |
| 26 | IUSE="vhosts" |
14 | IUSE="vhosts" |
| 27 | DEPEND=">=app-admin/webapp-config-1.50.15" |
15 | DEPEND=">=app-admin/webapp-config-1.50.15" |
| 28 | RDEPEND="${DEPEND}" |
16 | RDEPEND="${DEPEND}" |
| … | |
… | |
| 37 | |
25 | |
| 38 | ETC_CONFIG="${ROOT}/etc/vhosts/webapp-config" |
26 | ETC_CONFIG="${ROOT}/etc/vhosts/webapp-config" |
| 39 | WEBAPP_CONFIG="${ROOT}/usr/sbin/webapp-config" |
27 | WEBAPP_CONFIG="${ROOT}/usr/sbin/webapp-config" |
| 40 | WEBAPP_CLEANER="${ROOT}/usr/sbin/webapp-cleaner" |
28 | WEBAPP_CLEANER="${ROOT}/usr/sbin/webapp-cleaner" |
| 41 | |
29 | |
| 42 | # ------------------------------------------------------------------------ |
30 | # ============================================================================== |
| 43 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
31 | # INTERNAL FUNCTIONS |
| 44 | # |
32 | # ============================================================================== |
|
|
33 | |
| 45 | # Load the config file /etc/vhosts/webapp-config |
34 | # Load the config file /etc/vhosts/webapp-config |
| 46 | # |
|
|
| 47 | # Supports both the old bash version, and the new python version |
35 | # Supports both the old bash version, and the new python version |
| 48 | # |
|
|
| 49 | # ------------------------------------------------------------------------ |
|
|
| 50 | |
|
|
| 51 | function webapp_read_config () |
36 | webapp_read_config() { |
| 52 | { |
|
|
| 53 | if has_version '>=app-admin/webapp-config-1.50'; then |
37 | if has_version '>=app-admin/webapp-config-1.50'; then |
| 54 | ENVVAR=$(${WEBAPP_CONFIG} --query ${PN} ${PVR}) || die "Could not read settings from webapp-config!" |
38 | ENVVAR=$(${WEBAPP_CONFIG} --query ${PN} ${PVR}) || die "Could not read settings from webapp-config!" |
| 55 | eval ${ENVVAR} |
39 | eval ${ENVVAR} |
| 56 | else |
40 | else |
| 57 | . ${ETC_CONFIG} || die "Unable to read ${ETC_CONFIG}" |
41 | . ${ETC_CONFIG} || die "Unable to read ${ETC_CONFIG}" |
| 58 | fi |
42 | fi |
| 59 | } |
43 | } |
| 60 | |
44 | |
| 61 | # ------------------------------------------------------------------------ |
|
|
| 62 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
|
|
| 63 | # |
|
|
| 64 | # Check whether a specified file exists within the image/ directory |
45 | # Check whether a specified file exists in the given directory (`.' by default) |
| 65 | # or not. |
|
|
| 66 | # |
|
|
| 67 | # @param $1 - file to look for |
|
|
| 68 | # @param $2 - prefix directory to use |
|
|
| 69 | # @return 0 on success, never returns on an error |
|
|
| 70 | # ------------------------------------------------------------------------ |
|
|
| 71 | |
|
|
| 72 | function webapp_checkfileexists () |
46 | webapp_checkfileexists() { |
| 73 | { |
|
|
| 74 | local my_prefix |
47 | local my_prefix |
| 75 | |
48 | |
| 76 | [ -n "${2}" ] && my_prefix="${2}/" || my_prefix= |
49 | [ -n "${2}" ] && my_prefix="${2}/" || my_prefix= |
| 77 | |
50 | |
| 78 | if [ ! -e "${my_prefix}${1}" ]; then |
51 | if [ ! -e "${my_prefix}${1}" ]; then |
| … | |
… | |
| 81 | eerror "Please report this as a bug at http://bugs.gentoo.org/" |
54 | eerror "Please report this as a bug at http://bugs.gentoo.org/" |
| 82 | die "$msg" |
55 | die "$msg" |
| 83 | fi |
56 | fi |
| 84 | } |
57 | } |
| 85 | |
58 | |
| 86 | # ------------------------------------------------------------------------ |
|
|
| 87 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
|
|
| 88 | # ------------------------------------------------------------------------ |
|
|
| 89 | |
|
|
| 90 | function webapp_check_installedat |
59 | webapp_check_installedat() { |
| 91 | { |
|
|
| 92 | local my_output |
|
|
| 93 | |
|
|
| 94 | ${WEBAPP_CONFIG} --show-installed -h localhost -d "${INSTALL_DIR}" 2> /dev/null |
60 | ${WEBAPP_CONFIG} --show-installed -h localhost -d "${INSTALL_DIR}" 2> /dev/null |
| 95 | } |
61 | } |
| 96 | |
62 | |
| 97 | # ------------------------------------------------------------------------ |
|
|
| 98 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
|
|
| 99 | # |
|
|
| 100 | # ------------------------------------------------------------------------ |
|
|
| 101 | |
|
|
| 102 | function webapp_strip_appdir () |
63 | webapp_strip_appdir() { |
| 103 | { |
|
|
| 104 | local my_stripped="${1}" |
64 | local my_stripped="${1}" |
| 105 | echo "${1}" | sed -e "s|${MY_APPDIR}/||g;" |
65 | echo "${1}" | sed -e "s|${MY_APPDIR}/||g;" |
| 106 | } |
66 | } |
| 107 | |
67 | |
| 108 | function webapp_strip_d () |
68 | webapp_strip_d() { |
| 109 | { |
|
|
| 110 | echo "${1}" | sed -e "s|${D}||g;" |
69 | echo "${1}" | sed -e "s|${D}||g;" |
| 111 | } |
70 | } |
| 112 | |
71 | |
| 113 | function webapp_strip_cwd () |
72 | webapp_strip_cwd() { |
| 114 | { |
|
|
| 115 | local my_stripped="${1}" |
73 | local my_stripped="${1}" |
| 116 | echo "${1}" | sed -e 's|/./|/|g;' |
74 | echo "${1}" | sed -e 's|/./|/|g;' |
| 117 | } |
75 | } |
| 118 | |
76 | |
| 119 | # ------------------------------------------------------------------------ |
77 | webapp_getinstalltype() { |
| 120 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
78 | # or are we upgrading? |
| 121 | # |
|
|
| 122 | # Identify a config file for a web-based application. |
|
|
| 123 | # |
|
|
| 124 | # @param $1 - config file |
|
|
| 125 | # ------------------------------------------------------------------------ |
|
|
| 126 | |
79 | |
|
|
80 | if ! use vhosts ; then |
|
|
81 | # we only run webapp-config if vhosts USE flag is not set |
|
|
82 | |
|
|
83 | local my_output |
|
|
84 | |
|
|
85 | my_output="$(webapp_check_installedat)" |
|
|
86 | |
|
|
87 | if [ "${?}" = "0" ] ; then |
|
|
88 | # something is already installed there |
|
|
89 | # |
|
|
90 | # make sure it isn't the same version |
|
|
91 | |
|
|
92 | local my_pn="$(echo ${my_output} | awk '{ print $1 }')" |
|
|
93 | local my_pvr="$(echo ${my_output} | awk '{ print $2 }')" |
|
|
94 | |
|
|
95 | REMOVE_PKG="${my_pn}-${my_pvr}" |
|
|
96 | |
|
|
97 | if [ "${my_pn}" == "${PN}" ]; then |
|
|
98 | if [ "${my_pvr}" != "${PVR}" ]; then |
|
|
99 | elog "This is an upgrade" |
|
|
100 | IS_UPGRADE=1 |
|
|
101 | else |
|
|
102 | elog "This is a re-installation" |
|
|
103 | IS_REPLACE=1 |
|
|
104 | fi |
|
|
105 | else |
|
|
106 | elog "${my_output} is installed there" |
|
|
107 | fi |
|
|
108 | else |
|
|
109 | elog "This is an installation" |
|
|
110 | fi |
|
|
111 | fi |
|
|
112 | } |
|
|
113 | |
|
|
114 | # ============================================================================== |
|
|
115 | # PUBLIC FUNCTIONS |
|
|
116 | # ============================================================================== |
|
|
117 | |
|
|
118 | # @FUNCTION: webapp_configfile |
|
|
119 | # @USAGE: <file> [more files ...] |
|
|
120 | # @DESCRIPTION: |
|
|
121 | # Mark a file config-protected for a web-based application. |
| 127 | function webapp_configfile () |
122 | webapp_configfile() { |
| 128 | { |
|
|
| 129 | local m="" |
123 | local m="" |
| 130 | for m in "$@" ; do |
124 | for m in "$@" ; do |
| 131 | webapp_checkfileexists "${m}" "${D}" |
125 | webapp_checkfileexists "${m}" "${D}" |
| 132 | |
126 | |
| 133 | local MY_FILE="$(webapp_strip_appdir "${m}")" |
127 | local MY_FILE="$(webapp_strip_appdir "${m}")" |
| … | |
… | |
| 136 | elog "(config) ${MY_FILE}" |
130 | elog "(config) ${MY_FILE}" |
| 137 | echo "${MY_FILE}" >> ${D}/${WA_CONFIGLIST} |
131 | echo "${MY_FILE}" >> ${D}/${WA_CONFIGLIST} |
| 138 | done |
132 | done |
| 139 | } |
133 | } |
| 140 | |
134 | |
| 141 | # ------------------------------------------------------------------------ |
135 | # @FUNCTION: webapp_hook_script |
| 142 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
136 | # @USAGE: <file> |
| 143 | # |
137 | # @DESCRIPTION: |
| 144 | # Install a script that will run after a virtual copy is created, and |
138 | # Install a script that will run after a virtual copy is created, and |
| 145 | # before a virtual copy has been removed |
139 | # before a virtual copy has been removed. |
| 146 | # |
|
|
| 147 | # @param $1 - the script to run |
|
|
| 148 | # ------------------------------------------------------------------------ |
|
|
| 149 | |
|
|
| 150 | function webapp_hook_script () |
140 | webapp_hook_script() { |
| 151 | { |
|
|
| 152 | webapp_checkfileexists "${1}" |
141 | webapp_checkfileexists "${1}" |
| 153 | |
142 | |
| 154 | elog "(hook) ${1}" |
143 | elog "(hook) ${1}" |
| 155 | cp "${1}" "${D}/${MY_HOOKSCRIPTSDIR}/$(basename "${1}")" || die "Unable to install ${1} into ${D}/${MY_HOOKSCRIPTSDIR}/" |
144 | cp "${1}" "${D}/${MY_HOOKSCRIPTSDIR}/$(basename "${1}")" || die "Unable to install ${1} into ${D}/${MY_HOOKSCRIPTSDIR}/" |
| 156 | chmod 555 "${D}/${MY_HOOKSCRIPTSDIR}/$(basename "${1}")" |
145 | chmod 555 "${D}/${MY_HOOKSCRIPTSDIR}/$(basename "${1}")" |
| 157 | } |
146 | } |
| 158 | |
147 | |
| 159 | # ------------------------------------------------------------------------ |
148 | # @FUNCTION: webapp_postinst_txt |
| 160 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
149 | # @USAGE: <lang> <file> |
| 161 | # |
150 | # @DESCRIPTION: |
| 162 | # Install a text file containing post-installation instructions. |
151 | # Install a text file containing post-installation instructions. |
| 163 | # |
|
|
| 164 | # @param $1 - language code (use 'en' for now) |
|
|
| 165 | # @param $2 - the file to install |
|
|
| 166 | # ------------------------------------------------------------------------ |
|
|
| 167 | |
|
|
| 168 | function webapp_postinst_txt () |
152 | webapp_postinst_txt() { |
| 169 | { |
|
|
| 170 | webapp_checkfileexists "${2}" |
153 | webapp_checkfileexists "${2}" |
| 171 | |
154 | |
| 172 | elog "(info) ${2} (lang: ${1})" |
155 | elog "(info) ${2} (lang: ${1})" |
| 173 | cp "${2}" "${D}/${MY_APPDIR}/postinst-${1}.txt" |
156 | cp "${2}" "${D}/${MY_APPDIR}/postinst-${1}.txt" |
| 174 | } |
157 | } |
| 175 | |
158 | |
| 176 | # ------------------------------------------------------------------------ |
159 | # @FUNCTION: webapp_postupgrade_txt |
| 177 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
160 | # @USAGE: <lang> <file> |
| 178 | # |
161 | # @DESCRIPTION: |
| 179 | # Install a text file containing post-upgrade instructions. |
162 | # Install a text file containing post-upgrade instructions. |
| 180 | # |
|
|
| 181 | # @param $1 - language code (use 'en' for now) |
|
|
| 182 | # @param $2 - the file to install |
|
|
| 183 | # ------------------------------------------------------------------------ |
|
|
| 184 | |
|
|
| 185 | function webapp_postupgrade_txt () |
163 | webapp_postupgrade_txt() { |
| 186 | { |
|
|
| 187 | webapp_checkfileexists "${2}" |
164 | webapp_checkfileexists "${2}" |
| 188 | |
165 | |
| 189 | elog "(info) ${2} (lang: ${1})" |
166 | elog "(info) ${2} (lang: ${1})" |
| 190 | cp "${2}" "${D}/${MY_APPDIR}/postupgrade-${1}.txt" |
167 | cp "${2}" "${D}/${MY_APPDIR}/postupgrade-${1}.txt" |
| 191 | } |
168 | } |
| 192 | |
169 | |
| 193 | # ------------------------------------------------------------------------ |
170 | # @FUNCTION: webapp_serverowned |
| 194 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
171 | # @USAGE: [-R] <file> [more files ...] |
| 195 | # |
172 | # @DESCRIPTION: |
| 196 | # Identify a file which must be owned by the webserver's user:group |
173 | # Identify a file which must be owned by the webserver's user:group settings. |
| 197 | # settings. |
|
|
| 198 | # |
|
|
| 199 | # The ownership of the file is NOT set until the application is installed |
174 | # The ownership of the file is NOT set until the application is installed using |
| 200 | # using the webapp-config tool. |
175 | # the webapp-config tool. If -R is given directories are handled recursively. |
| 201 | # |
|
|
| 202 | # @param $1 - file to be owned by the webserver user:group combo |
|
|
| 203 | # |
|
|
| 204 | # ------------------------------------------------------------------------ |
|
|
| 205 | |
|
|
| 206 | function webapp_serverowned () |
176 | webapp_serverowned() { |
| 207 | { |
|
|
| 208 | local a="" |
177 | local a="" |
| 209 | local m="" |
178 | local m="" |
| 210 | if [ "${1}" = "-R" ]; then |
179 | if [ "${1}" = "-R" ]; then |
| 211 | shift |
180 | shift |
| 212 | for m in "$@" ; do |
181 | for m in "$@" ; do |
| … | |
… | |
| 230 | echo "${MY_FILE}" >> "${D}/${WA_SOLIST}" |
199 | echo "${MY_FILE}" >> "${D}/${WA_SOLIST}" |
| 231 | done |
200 | done |
| 232 | fi |
201 | fi |
| 233 | } |
202 | } |
| 234 | |
203 | |
| 235 | # ------------------------------------------------------------------------ |
204 | # @FUNCTION: webapp_server_configfile |
| 236 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
205 | # @USAGE: <server> <file> [new name] |
| 237 | # |
206 | # @DESCRIPTION: |
| 238 | # @param $1 - the webserver to install the config file for |
207 | # Install a configuration file for the webserver. You need to specify a |
| 239 | # (one of apache1, apache2, cherokee) |
208 | # webapp-config supported <server>. if no new name is given `basename $2' is |
| 240 | # @param $2 - the config file to install |
209 | # used by default. Note: this function will automagically prepend $1 to the |
| 241 | # @param $3 - new name for the config file (default is `basename $2`) |
210 | # front of your config file's name. |
| 242 | # this is an optional parameter |
|
|
| 243 | # |
|
|
| 244 | # NOTE: |
|
|
| 245 | # this function will automagically prepend $1 to the front of your |
|
|
| 246 | # config file's name |
|
|
| 247 | # ------------------------------------------------------------------------ |
|
|
| 248 | |
|
|
| 249 | function webapp_server_configfile () |
211 | webapp_server_configfile() { |
| 250 | { |
|
|
| 251 | webapp_checkfileexists "${2}" |
212 | webapp_checkfileexists "${2}" |
| 252 | |
213 | |
| 253 | # sort out what the name will be of the config file |
214 | # sort out what the name will be of the config file |
| 254 | |
215 | |
| 255 | local my_file |
216 | local my_file |
| … | |
… | |
| 267 | |
228 | |
| 268 | elog "(${1}) config file '${my_file}'" |
229 | elog "(${1}) config file '${my_file}'" |
| 269 | cp "${2}" "${D}/${MY_SERVERCONFIGDIR}/${my_file}" |
230 | cp "${2}" "${D}/${MY_SERVERCONFIGDIR}/${my_file}" |
| 270 | } |
231 | } |
| 271 | |
232 | |
| 272 | # ------------------------------------------------------------------------ |
233 | # @FUNCTION: webapp_sqlscript |
| 273 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
234 | # @USAGE: <db> <file> [version] |
| 274 | # |
235 | # @DESCRIPTION: |
| 275 | # @param $1 - the db engine that the script is for |
236 | # Install a SQL script that creates/upgrades a database schema for the web |
| 276 | # (one of: mysql|postgres) |
237 | # application. Currently supported database engines are mysql and postgres. |
| 277 | # @param $2 - the sql script to be installed |
238 | # If a version is given the script should upgrade the database schema from |
| 278 | # @param $3 - the older version of the app that this db script |
239 | # the given version to $PVR. |
| 279 | # will upgrade from |
|
|
| 280 | # (do not pass this option if your SQL script only creates |
|
|
| 281 | # a new db from scratch) |
|
|
| 282 | # ------------------------------------------------------------------------ |
|
|
| 283 | |
|
|
| 284 | function webapp_sqlscript () |
240 | webapp_sqlscript() { |
| 285 | { |
|
|
| 286 | webapp_checkfileexists "${2}" |
241 | webapp_checkfileexists "${2}" |
| 287 | |
242 | |
| 288 | # create the directory where this script will go |
243 | # create the directory where this script will go |
| 289 | # |
244 | # |
| 290 | # scripts for specific database engines go into their own subdirectory |
245 | # scripts for specific database engines go into their own subdirectory |
| … | |
… | |
| 311 | cp "${2}" "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql" |
266 | cp "${2}" "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql" |
| 312 | chmod 600 "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql" |
267 | chmod 600 "${D}/${MY_SQLSCRIPTSDIR}/${1}/${PVR}_create.sql" |
| 313 | fi |
268 | fi |
| 314 | } |
269 | } |
| 315 | |
270 | |
| 316 | # ------------------------------------------------------------------------ |
271 | # @FUNCTION: webapp_src_preinst |
| 317 | # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER |
272 | # @DESCRIPTION: |
| 318 | # everything else has run |
273 | # You need to call this function in src_install() BEFORE anything else has run. |
|
|
274 | # For now we just create required webapp-config directories. |
|
|
275 | webapp_src_preinst() { |
|
|
276 | dodir "${MY_HTDOCSDIR}" |
|
|
277 | dodir "${MY_HOSTROOTDIR}" |
|
|
278 | dodir "${MY_CGIBINDIR}" |
|
|
279 | dodir "${MY_ICONSDIR}" |
|
|
280 | dodir "${MY_ERRORSDIR}" |
|
|
281 | dodir "${MY_SQLSCRIPTSDIR}" |
|
|
282 | dodir "${MY_HOOKSCRIPTSDIR}" |
|
|
283 | dodir "${MY_SERVERCONFIGDIR}" |
|
|
284 | } |
|
|
285 | |
|
|
286 | # ============================================================================== |
|
|
287 | # EXPORTED FUNCTIONS |
|
|
288 | # ============================================================================== |
|
|
289 | |
|
|
290 | # @FUNCTION: webapp_src_install |
|
|
291 | # @DESCRIPTION: |
|
|
292 | # This is the default src_install(). For now, we just make sure that root owns |
|
|
293 | # everything, and that there are no setuid files. |
| 319 | # |
294 | # |
| 320 | # For now, we just make sure that root owns everything, and that there |
295 | # You need to call this function AFTER everything else has run in your custom |
| 321 | # are no setuid files. |
296 | # src_install(). |
| 322 | # ------------------------------------------------------------------------ |
|
|
| 323 | |
|
|
| 324 | function webapp_src_install () |
297 | webapp_src_install() { |
| 325 | { |
|
|
| 326 | chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/" |
298 | chown -R "${VHOST_DEFAULT_UID}:${VHOST_DEFAULT_GID}" "${D}/" |
| 327 | chmod -R u-s "${D}/" |
299 | chmod -R u-s "${D}/" |
| 328 | chmod -R g-s "${D}/" |
300 | chmod -R g-s "${D}/" |
| 329 | |
301 | |
| 330 | keepdir "${MY_PERSISTDIR}" |
302 | keepdir "${MY_PERSISTDIR}" |
| … | |
… | |
| 339 | # webapp_pkg_postinst() within the same shell process |
311 | # webapp_pkg_postinst() within the same shell process |
| 340 | |
312 | |
| 341 | touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}" |
313 | touch "${D}/${MY_APPDIR}/${INSTALL_CHECK_FILE}" |
| 342 | } |
314 | } |
| 343 | |
315 | |
| 344 | # ------------------------------------------------------------------------ |
316 | # @FUNCTION: webapp_pkg_setup |
| 345 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER |
317 | # @DESCRIPTION: |
| 346 | # everything else has run |
318 | # The default pkg_setup() for this eclass. This will gather required variables |
|
|
319 | # from webapp-config and check if there is an application installed to |
|
|
320 | # `${ROOT}/var/www/localhost/htdocs/${PN}/' if USE=vhosts is not set. |
| 347 | # |
321 | # |
| 348 | # If 'vhosts' USE flag is not set, auto-install this app |
322 | # You need to call this function BEFORE anything else has run in your custom |
| 349 | # |
323 | # pkg_setup(). |
| 350 | # ------------------------------------------------------------------------ |
|
|
| 351 | |
|
|
| 352 | function webapp_pkg_setup () |
324 | webapp_pkg_setup() { |
| 353 | { |
|
|
| 354 | # add sanity checks here |
325 | # add sanity checks here |
| 355 | |
326 | |
| 356 | # special case - some ebuilds *do* need to overwride the SLOT |
327 | # special case - some ebuilds *do* need to overwride the SLOT |
| 357 | if [[ "${SLOT}+" != "${PVR}+" && "${WEBAPP_MANUAL_SLOT}" != "yes" ]]; then |
328 | if [[ "${SLOT}+" != "${PVR}+" && "${WEBAPP_MANUAL_SLOT}" != "yes" ]]; then |
| 358 | die "Set WEBAPP_MANUAL_SLOT=\"yes\" if you need to SLOT manually" |
329 | die "Set WEBAPP_MANUAL_SLOT=\"yes\" if you need to SLOT manually" |
| … | |
… | |
| 389 | fi |
360 | fi |
| 390 | fi |
361 | fi |
| 391 | fi |
362 | fi |
| 392 | } |
363 | } |
| 393 | |
364 | |
| 394 | function webapp_getinstalltype () |
365 | # @FUNCTION: webapp_pkg_postinst |
| 395 | { |
366 | # @DESCRIPTION: |
| 396 | # or are we upgrading? |
367 | # The default pkg_postinst() for this eclass. This installs the web application to |
| 397 | |
368 | # `${ROOT}/var/www/localhost/htdocs/${PN}/' if USE=vhosts is not set. Otherwise |
| 398 | if ! use vhosts ; then |
369 | # display a short notice how to install this application with webapp-config. |
| 399 | # we only run webapp-config if vhosts USE flag is not set |
370 | # |
| 400 | |
371 | # You need to call this function AFTER everything else has run in your custom |
| 401 | local my_output |
372 | # pkg_postinst(). |
| 402 | |
|
|
| 403 | my_output="$(webapp_check_installedat)" |
|
|
| 404 | |
|
|
| 405 | if [ "${?}" = "0" ] ; then |
|
|
| 406 | # something is already installed there |
|
|
| 407 | # |
|
|
| 408 | # make sure it isn't the same version |
|
|
| 409 | |
|
|
| 410 | local my_pn="$(echo ${my_output} | awk '{ print $1 }')" |
|
|
| 411 | local my_pvr="$(echo ${my_output} | awk '{ print $2 }')" |
|
|
| 412 | |
|
|
| 413 | REMOVE_PKG="${my_pn}-${my_pvr}" |
|
|
| 414 | |
|
|
| 415 | if [ "${my_pn}" == "${PN}" ]; then |
|
|
| 416 | if [ "${my_pvr}" != "${PVR}" ]; then |
|
|
| 417 | elog "This is an upgrade" |
|
|
| 418 | IS_UPGRADE=1 |
|
|
| 419 | else |
|
|
| 420 | elog "This is a re-installation" |
|
|
| 421 | IS_REPLACE=1 |
|
|
| 422 | fi |
|
|
| 423 | else |
|
|
| 424 | elog "${my_output} is installed there" |
|
|
| 425 | fi |
|
|
| 426 | else |
|
|
| 427 | elog "This is an installation" |
|
|
| 428 | fi |
|
|
| 429 | fi |
|
|
| 430 | } |
|
|
| 431 | |
|
|
| 432 | function webapp_src_preinst () |
|
|
| 433 | { |
|
|
| 434 | # create the directories that we need |
|
|
| 435 | |
|
|
| 436 | dodir "${MY_HTDOCSDIR}" |
|
|
| 437 | dodir "${MY_HOSTROOTDIR}" |
|
|
| 438 | dodir "${MY_CGIBINDIR}" |
|
|
| 439 | dodir "${MY_ICONSDIR}" |
|
|
| 440 | dodir "${MY_ERRORSDIR}" |
|
|
| 441 | dodir "${MY_SQLSCRIPTSDIR}" |
|
|
| 442 | dodir "${MY_HOOKSCRIPTSDIR}" |
|
|
| 443 | dodir "${MY_SERVERCONFIGDIR}" |
|
|
| 444 | } |
|
|
| 445 | |
|
|
| 446 | function webapp_pkg_postinst () |
373 | webapp_pkg_postinst() { |
| 447 | { |
|
|
| 448 | webapp_read_config |
374 | webapp_read_config |
| 449 | |
375 | |
| 450 | # sanity checks, to catch bugs in the ebuild |
376 | # sanity checks, to catch bugs in the ebuild |
| 451 | |
377 | |
| 452 | if [ ! -f "${ROOT}${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]; then |
378 | if [ ! -f "${ROOT}${MY_APPDIR}/${INSTALL_CHECK_FILE}" ]; then |
| … | |
… | |
| 512 | fi |
438 | fi |
| 513 | |
439 | |
| 514 | return 0 |
440 | return 0 |
| 515 | } |
441 | } |
| 516 | |
442 | |
|
|
443 | # @FUNCTION: webapp_pkg_prerm |
|
|
444 | # @DESCRIPTION: |
|
|
445 | # This is the default pkg_prerm() for this eclass. If USE=vhosts is not set |
|
|
446 | # remove all installed copies of this web application. Otherwise instruct the |
|
|
447 | # user to manually remove those copies. |
| 517 | function webapp_pkg_prerm () |
448 | webapp_pkg_prerm() { |
| 518 | { |
|
|
| 519 | # remove any virtual installs that there are |
449 | # remove any virtual installs that there are |
| 520 | |
450 | |
| 521 | local my_output |
451 | local my_output |
| 522 | local x |
452 | local x |
| 523 | |
453 | |
| … | |
… | |
| 525 | |
455 | |
| 526 | if [ "${?}" != "0" ]; then |
456 | if [ "${?}" != "0" ]; then |
| 527 | return |
457 | return |
| 528 | fi |
458 | fi |
| 529 | |
459 | |
|
|
460 | if ! use vhosts ; then # remove any installed copies |
|
|
461 | |
| 530 | for x in ${my_output} ; do |
462 | for x in ${my_output} ; do |
| 531 | [ -f ${x}/.webapp ] && . ${x}/.webapp || ewarn "Cannot find file ${x}/.webapp" |
463 | [ -f ${x}/.webapp ] && . ${x}/.webapp || ewarn "Cannot find file ${x}/.webapp" |
| 532 | |
|
|
| 533 | if [ -z "${WEB_HOSTNAME}" -o -z "${WEB_INSTALLDIR}" ]; then |
464 | if [ "${WEB_HOSTNAME}" -a "${WEB_INSTALLDIR}" ]; then |
|
|
465 | ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR} |
|
|
466 | fi |
|
|
467 | done |
|
|
468 | else # don't remove anything, but warn user. bug #136959 |
|
|
469 | |
| 534 | ewarn "Don't forget to use webapp-config to remove the copy of" |
470 | ewarn "Don't forget to use webapp-config to remove any copies of" |
| 535 | ewarn "${PN}-${PVR} installed in" |
471 | ewarn "${PN}-${PVR} installed in" |
| 536 | ewarn |
472 | ewarn |
|
|
473 | |
|
|
474 | for x in ${my_output} ; do |
|
|
475 | [ -f ${x}/.webapp ] && . ${x}/.webapp || ewarn "Cannot find file ${x}/.webapp" |
| 537 | ewarn " ${x}" |
476 | ewarn " ${x}" |
| 538 | ewarn |
|
|
| 539 | else |
|
|
| 540 | # we have enough information to remove the virtual copy ourself |
|
|
| 541 | |
|
|
| 542 | ${WEBAPP_CONFIG} -C -h ${WEB_HOSTNAME} -d ${WEB_INSTALLDIR} |
|
|
| 543 | |
|
|
| 544 | # if the removal fails - we carry on anyway! |
|
|
| 545 | fi |
|
|
| 546 | done |
477 | done |
|
|
478 | fi |
| 547 | } |
479 | } |