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