1 |
robbat2 11/07/13 07:01:47 |
2 |
|
3 |
Added: mysql-v2.eclass |
4 |
Log: |
5 |
Add mysql v2 eclass ready for newer mysql 5.1, and supporting mysql/mariadb 5.5/5.6. Reviewed April 2011 on gentoo-dev mailing list. |
6 |
|
7 |
Revision Changes Path |
8 |
1.1 eclass/mysql-v2.eclass |
9 |
|
10 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/mysql-v2.eclass?rev=1.1&view=markup |
11 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/mysql-v2.eclass?rev=1.1&content-type=text/plain |
12 |
|
13 |
Index: mysql-v2.eclass |
14 |
=================================================================== |
15 |
# Copyright 1999-2011 Gentoo Foundation |
16 |
# Distributed under the terms of the GNU General Public License v2 |
17 |
# $Header: /var/cvsroot/gentoo-x86/eclass/mysql-v2.eclass,v 1.1 2011/07/13 07:01:47 robbat2 Exp $ |
18 |
|
19 |
# @ECLASS: mysql-v2.eclass |
20 |
# @MAINTAINER: |
21 |
# Maintainers: |
22 |
# - MySQL Team <mysql-bugs@g.o> |
23 |
# - Robin H. Johnson <robbat2@g.o> |
24 |
# - Jorge Manuel B. S. Vicetto <jmbsvicetto@g.o> |
25 |
# @BLURB: This eclass provides most of the functions for mysql ebuilds |
26 |
# @DESCRIPTION: |
27 |
# The mysql-v2.eclass is the base eclass to build the mysql and |
28 |
# alternative projects (mariadb) ebuilds. |
29 |
# This eclass uses the mysql-autotools and mysql-cmake eclasses for the |
30 |
# specific bits related to the build system. |
31 |
# It provides the src_unpack, src_prepare, src_configure, src_compile, |
32 |
# scr_install, pkg_preinst, pkg_postinst, pkg_config and pkg_postrm |
33 |
# phase hooks. |
34 |
|
35 |
# @ECLASS-VARIABLE: BUILD |
36 |
# @DESCRIPTION: Build type of the mysql version |
37 |
# The default value is autotools |
38 |
: ${BUILD:=autotools} |
39 |
|
40 |
case ${BUILD} in |
41 |
"cmake") |
42 |
BUILD_INHERIT="mysql-cmake" |
43 |
;; |
44 |
"autotools") |
45 |
BUILD_INHERIT="mysql-autotools" |
46 |
|
47 |
WANT_AUTOCONF="latest" |
48 |
WANT_AUTOMAKE="latest" |
49 |
;; |
50 |
*) |
51 |
die "${BUILD} is not a valid build system for mysql" |
52 |
;; |
53 |
esac |
54 |
|
55 |
MYSQL_EXTRAS="" |
56 |
|
57 |
# @ECLASS-VARIABLE: MYSQL_EXTRAS_VER |
58 |
# @DESCRIPTION: The version of the MYSQL_EXTRAS repo to use to build mysql |
59 |
[[ "${MY_EXTRAS_VER}" == "live" ]] && MYSQL_EXTRAS="git-2" |
60 |
|
61 |
inherit eutils flag-o-matic gnuconfig ${MYSQL_EXTRAS} ${BUILD_INHERIT} mysql_fx versionator toolchain-funcs |
62 |
|
63 |
# |
64 |
# Supported EAPI versions and export functions |
65 |
# |
66 |
|
67 |
case "${EAPI:-0}" in |
68 |
2|3|4) ;; |
69 |
*) die "Unsupported EAPI: ${EAPI}" ;; |
70 |
esac |
71 |
|
72 |
EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install |
73 |
|
74 |
# |
75 |
# VARIABLES: |
76 |
# |
77 |
|
78 |
# Shorten the path because the socket path length must be shorter than 107 chars |
79 |
# and we will run a mysql server during test phase |
80 |
S="${WORKDIR}/mysql" |
81 |
|
82 |
[[ "${MY_EXTRAS_VER}" == "latest" ]] && MY_EXTRAS_VER="20090228-0714Z" |
83 |
if [[ "${MY_EXTRAS_VER}" == "live" ]]; then |
84 |
EGIT_PROJECT=mysql-extras |
85 |
EGIT_REPO_URI="git://git.overlays.gentoo.org/proj/mysql-extras.git" |
86 |
fi |
87 |
|
88 |
# @ECLASS-VARIABLE: MYSQL_PV_MAJOR |
89 |
# @DESCRIPTION: |
90 |
# Upstream MySQL considers the first two parts of the version number to be the |
91 |
# major version. Upgrades that change major version should always run |
92 |
# mysql_upgrade. |
93 |
MYSQL_PV_MAJOR="$(get_version_component_range 1-2 ${PV})" |
94 |
|
95 |
# Cluster is a special case... |
96 |
if [[ "${PN}" == "mysql-cluster" ]]; then |
97 |
case $PV in |
98 |
6.1*|7.0*|7.1*) MYSQL_PV_MAJOR=5.1 ;; |
99 |
esac |
100 |
fi |
101 |
|
102 |
|
103 |
# @ECLASS-VARIABLE: MYSQL_VERSION_ID |
104 |
# @DESCRIPTION: |
105 |
# MYSQL_VERSION_ID will be: |
106 |
# major * 10e6 + minor * 10e4 + micro * 10e2 + gentoo revision number, all [0..99] |
107 |
# This is an important part, because many of the choices the MySQL ebuild will do |
108 |
# depend on this variable. |
109 |
# In particular, the code below transforms a $PVR like "5.0.18-r3" in "5001803" |
110 |
# We also strip off upstream's trailing letter that they use to respin tarballs |
111 |
MYSQL_VERSION_ID="" |
112 |
tpv="${PV%[a-z]}" |
113 |
tpv=( ${tpv//[-._]/ } ) ; tpv[3]="${PVR:${#PV}}" ; tpv[3]="${tpv[3]##*-r}" |
114 |
for vatom in 0 1 2 3 ; do |
115 |
# pad to length 2 |
116 |
tpv[${vatom}]="00${tpv[${vatom}]}" |
117 |
MYSQL_VERSION_ID="${MYSQL_VERSION_ID}${tpv[${vatom}]:0-2}" |
118 |
done |
119 |
# strip leading "0" (otherwise it's considered an octal number by BASH) |
120 |
MYSQL_VERSION_ID=${MYSQL_VERSION_ID##"0"} |
121 |
|
122 |
# This eclass should only be used with at least mysql-5.1.50 |
123 |
mysql_version_is_at_least "5.1.50" || die "This eclass should only be used with >=mysql-5.1.50" |
124 |
|
125 |
# @ECLASS-VARIABLE: MYSQL_COMMUNITY_FEATURES |
126 |
# @DESCRIPTION: |
127 |
# Specifiy if community features are available. Possible values are 1 (yes) |
128 |
# and 0 (no). |
129 |
# Community features are available in mysql-community |
130 |
# AND in the re-merged mysql-5.0.82 and newer |
131 |
if [ "${PN}" == "mysql-community" -o "${PN}" == "mariadb" ]; then |
132 |
MYSQL_COMMUNITY_FEATURES=1 |
133 |
elif [ "${MYSQL_PV_MAJOR}" == "5.1" ]; then |
134 |
MYSQL_COMMUNITY_FEATURES=1 |
135 |
elif mysql_version_is_at_least "5.4.0"; then |
136 |
MYSQL_COMMUNITY_FEATURES=1 |
137 |
else |
138 |
MYSQL_COMMUNITY_FEATURES=0 |
139 |
fi |
140 |
|
141 |
|
142 |
# @ECLASS-VARIABLE: XTRADB_VER |
143 |
# @DEFAULT_UNSET |
144 |
# @DESCRIPTION: |
145 |
# Version of the XTRADB storage engine |
146 |
|
147 |
# @ECLASS-VARIABLE: PERCONA_VER |
148 |
# @DEFAULT_UNSET |
149 |
# @DESCRIPTION: |
150 |
# Designation by PERCONA for a MySQL version to apply an XTRADB release |
151 |
|
152 |
# Work out the default SERVER_URI correctly |
153 |
if [ -z "${SERVER_URI}" ]; then |
154 |
[ -z "${MY_PV}" ] && MY_PV="${PV//_/-}" |
155 |
if [ "${PN}" == "mariadb" ]; then |
156 |
MARIA_FULL_PV="$(replace_version_separator 3 '-' ${PV})" |
157 |
MARIA_FULL_P="${PN}-${MARIA_FULL_PV}" |
158 |
SERVER_URI=" |
159 |
http://ftp.osuosl.org/pub/mariadb/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz |
160 |
http://ftp.rediris.es/mirror/MariaDB/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz |
161 |
http://maria.llarian.net/download/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz |
162 |
http://launchpad.net/maria/${MYSQL_PV_MAJOR}/ongoing/+download/${MARIA_FULL_P}.tar.gz |
163 |
http://mirrors.fe.up.pt/pub/${PN}/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz |
164 |
http://ftp-stud.hs-esslingen.de/pub/Mirrors/${PN}/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz |
165 |
" |
166 |
# The community and cluster builds are on the mirrors |
167 |
elif [[ "${MYSQL_COMMUNITY_FEATURES}" == "1" || ${PN} == "mysql-cluster" ]] ; then |
168 |
if [[ "${PN}" == "mysql-cluster" ]] ; then |
169 |
URI_DIR="MySQL-Cluster" |
170 |
URI_FILE="mysql-cluster-gpl" |
171 |
else |
172 |
URI_DIR="MySQL" |
173 |
URI_FILE="mysql" |
174 |
fi |
175 |
URI_A="${URI_FILE}-${MY_PV}.tar.gz" |
176 |
MIRROR_PV=$(get_version_component_range 1-2 ${PV}) |
177 |
# Recently upstream switched to an archive site, and not on mirrors |
178 |
SERVER_URI="http://downloads.mysql.com/archives/${URI_FILE}-${MIRROR_PV}/${URI_A} |
179 |
mirror://mysql/Downloads/${URI_DIR}-${PV%.*}/${URI_A}" |
180 |
# The (old) enterprise source is on the primary site only |
181 |
elif [ "${PN}" == "mysql" ]; then |
182 |
SERVER_URI="ftp://ftp.mysql.com/pub/mysql/src/mysql-${MY_PV}.tar.gz" |
183 |
fi |
184 |
fi |
185 |
|
186 |
# Define correct SRC_URIs |
187 |
SRC_URI="${SERVER_URI}" |
188 |
|
189 |
# Gentoo patches to MySQL |
190 |
[[ ${MY_EXTRAS_VER} != live ]] \ |
191 |
&& SRC_URI="${SRC_URI} |
192 |
mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2 |
193 |
http://g3nt8.org/patches/mysql-extras-${MY_EXTRAS_VER}.tar.bz2 |
194 |
http://dev.gentoo.org/~robbat2/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2" |
195 |
|
196 |
DESCRIPTION="A fast, multi-threaded, multi-user SQL database server." |
197 |
HOMEPAGE="http://www.mysql.com/" |
198 |
if [[ "${PN}" == "mariadb" ]]; then |
199 |
HOMEPAGE="http://mariadb.org/" |
200 |
DESCRIPTION="MariaDB is a MySQL fork with 3rd-party patches and additional storage engines merged." |
201 |
fi |
202 |
if [[ "${PN}" == "mysql-community" ]]; then |
203 |
DESCRIPTION="${DESCRIPTION} (obsolete, move to dev-db/mysql)" |
204 |
fi |
205 |
LICENSE="GPL-2" |
206 |
SLOT="0" |
207 |
|
208 |
case "${BUILD}" in |
209 |
"autotools") |
210 |
IUSE="big-tables debug embedded minimal +perl selinux ssl static test" |
211 |
;; |
212 |
"cmake") |
213 |
IUSE="debug embedded minimal +perl selinux ssl static test" |
214 |
;; |
215 |
esac |
216 |
|
217 |
IUSE="${IUSE} latin1" |
218 |
|
219 |
IUSE="${IUSE} extraengine" |
220 |
if [[ ${PN} != "mysql-cluster" ]] ; then |
221 |
IUSE="${IUSE} cluster" |
222 |
fi |
223 |
|
224 |
IUSE="${IUSE} max-idx-128" |
225 |
IUSE="${IUSE} berkdb" |
226 |
|
227 |
[[ ${MYSQL_COMMUNITY_FEATURES} == 1 ]] \ |
228 |
&& IUSE="${IUSE} +community profiling" |
229 |
|
230 |
[[ ${PN} == "mariadb" ]] \ |
231 |
&& IUSE="${IUSE} libevent" |
232 |
|
233 |
[[ ${PN} == "mariadb" ]] \ |
234 |
&& mysql_version_is_at_least "5.2" \ |
235 |
&& IUSE="${IUSE} oqgraph" |
236 |
|
237 |
[[ ${PN} == "mariadb" ]] \ |
238 |
&& mysql_version_is_at_least "5.2.5" \ |
239 |
&& IUSE="${IUSE} sphinx" |
240 |
|
241 |
|
242 |
# |
243 |
# DEPENDENCIES: |
244 |
# |
245 |
|
246 |
# Be warned, *DEPEND are version-dependant |
247 |
# These are used for both runtime and compiletime |
248 |
DEPEND=" |
249 |
ssl? ( >=dev-libs/openssl-0.9.6d ) |
250 |
userland_GNU? ( sys-process/procps ) |
251 |
>=sys-apps/sed-4 |
252 |
>=sys-apps/texinfo-4.7-r1 |
253 |
>=sys-libs/readline-4.1 |
254 |
>=sys-libs/zlib-1.2.3 |
255 |
" |
256 |
|
257 |
[[ ${PN} == mariadb ]] \ |
258 |
&& DEPEND="${DEPEND} libevent? ( >=dev-libs/libevent-1.4 )" |
259 |
|
260 |
# Having different flavours at the same time is not a good idea |
261 |
for i in "mysql" "mysql-community" "mysql-cluster" "mariadb" ; do |
262 |
[[ ${i} == ${PN} ]] || |
263 |
DEPEND="${DEPEND} !dev-db/${i}" |
264 |
done |
265 |
|
266 |
RDEPEND="${DEPEND} |
267 |
!minimal? ( dev-db/mysql-init-scripts ) |
268 |
selinux? ( sec-policy/selinux-mysql ) |
269 |
" |
270 |
|
271 |
DEPEND="${DEPEND} static? ( || ( sys-libs/ncurses[static-libs] <=sys-libs/ncurses-5.7-r3 ) )" |
272 |
|
273 |
# compile-time-only |
274 |
DEPEND="${DEPEND} >=dev-util/cmake-2.4.3" |
275 |
|
276 |
# compile-time-only |
277 |
mysql_version_is_at_least "5.5.8" \ |
278 |
&& DEPEND="${DEPEND} >=dev-util/cmake-2.6.3" |
279 |
|
280 |
[[ "${PN}" == "mariadb" ]] \ |
281 |
&& mysql_version_is_at_least "5.2" \ |
282 |
&& DEPEND="${DEPEND} oqgraph? ( >=dev-libs/boost-1.40.0 )" |
283 |
|
284 |
[[ "${PN}" == "mariadb" ]] \ |
285 |
&& mysql_version_is_at_least "5.2.5" \ |
286 |
&& DEPEND="${DEPEND} sphinx? ( app-misc/sphinx )" |
287 |
|
288 |
# dev-perl/DBD-mysql is needed by some scripts installed by MySQL |
289 |
PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )" |
290 |
|
291 |
# For other stuff to bring us in |
292 |
PDEPEND="${PDEPEND} =virtual/mysql-${MYSQL_PV_MAJOR}" |
293 |
|
294 |
|
295 |
# |
296 |
# External patches |
297 |
# |
298 |
|
299 |
# MariaDB has integrated PBXT |
300 |
# PBXT_VERSION means that we have a PBXT patch for this PV |
301 |
# PBXT was only introduced after 5.1.12 |
302 |
pbxt_patch_available() { |
303 |
[[ ${PN} != "mariadb" ]] \ |
304 |
&& [[ -n "${PBXT_VERSION}" ]] |
305 |
return $? |
306 |
} |
307 |
|
308 |
pbxt_available() { |
309 |
pbxt_patch_available || [[ ${PN} == "mariadb" ]] |
310 |
return $? |
311 |
} |
312 |
|
313 |
# Get the percona tarball if XTRADB_VER and PERCONA_VER are both set |
314 |
# MariaDB has integrated XtraDB |
315 |
# XTRADB_VERS means that we have a XTRADB patch for this PV |
316 |
# XTRADB was only introduced after 5.1.26 |
317 |
xtradb_patch_available() { |
318 |
[[ ${PN} != "mariadb" ]] \ |
319 |
&& [[ -n "${XTRADB_VER}" && -n "${PERCONA_VER}" ]] |
320 |
return $? |
321 |
} |
322 |
|
323 |
|
324 |
if pbxt_patch_available; then |
325 |
|
326 |
PBXT_P="pbxt-${PBXT_VERSION}" |
327 |
PBXT_SRC_URI="http://www.primebase.org/download/${PBXT_P}.tar.gz mirror://sourceforge/pbxt/${PBXT_P}.tar.gz" |
328 |
SRC_URI="${SRC_URI} pbxt? ( ${PBXT_SRC_URI} )" |
329 |
|
330 |
# PBXT_NEWSTYLE means pbxt is in storage/ and gets enabled as other plugins |
331 |
# vs. built outside the dir |
332 |
if pbxt_available; then |
333 |
|
334 |
IUSE="${IUSE} pbxt" |
335 |
PBXT_NEWSTYLE=1 |
336 |
fi |
337 |
fi |
338 |
|
339 |
if xtradb_patch_available; then |
340 |
XTRADB_P="percona-xtradb-${XTRADB_VER}" |
341 |
XTRADB_SRC_URI_COMMON="${PERCONA_VER}/source/${XTRADB_P}.tar.gz" |
342 |
XTRADB_SRC_B1="http://www.percona.com/" |
343 |
XTRADB_SRC_B2="${XTRADB_SRC_B1}/percona-builds/" |
344 |
XTRADB_SRC_URI1="${XTRADB_SRC_B2}/Percona-Server/Percona-Server-${XTRADB_SRC_URI_COMMON}" |
345 |
XTRADB_SRC_URI2="${XTRADB_SRC_B2}/xtradb/${XTRADB_SRC_URI_COMMON}" |
346 |
XTRADB_SRC_URI3="${XTRADB_SRC_B1}/${PN}/xtradb/${XTRADB_SRC_URI_COMMON}" |
347 |
SRC_URI="${SRC_URI} xtradb? ( ${XTRADB_SRC_URI1} ${XTRADB_SRC_URI2} ${XTRADB_SRC_URI3} )" |
348 |
IUSE="${IUSE} xtradb" |
349 |
fi |
350 |
|
351 |
# |
352 |
# HELPER FUNCTIONS: |
353 |
# |
354 |
|
355 |
# @FUNCTION: mysql-v2_disable_test |
356 |
# @DESCRIPTION: |
357 |
# Helper function to disable specific tests. |
358 |
mysql-v2_disable_test() { |
359 |
${BUILD_INHERIT}_disable_test "$@" |
360 |
} |
361 |
|
362 |
# @FUNCTION: mysql-v2_configure_minimal |
363 |
# @DESCRIPTION: |
364 |
# Helper function to configure minimal build |
365 |
configure_minimal() { |
366 |
${BUILD_INHERIT}_configure_minimal "$@" |
367 |
} |
368 |
|
369 |
# @FUNCTION: mysql-v2_configure_common |
370 |
# @DESCRIPTION: |
371 |
# Helper function to configure common builds |
372 |
configure_common() { |
373 |
${BUILD_INHERIT}_configure_common "$@" |
374 |
} |
375 |
|
376 |
# |
377 |
# EBUILD FUNCTIONS |
378 |
# |
379 |
|
380 |
# @FUNCTION: mysql-v2_pkg_setup |
381 |
# @DESCRIPTION: |
382 |
# Perform some basic tests and tasks during pkg_setup phase: |
383 |
# die if FEATURES="test", USE="-minimal" and not using FEATURES="userpriv" |
384 |
# check for conflicting use flags |
385 |
# create new user and group for mysql |
386 |
# warn about deprecated features |
387 |
mysql-v2_pkg_setup() { |
388 |
|
389 |
if has test ${FEATURES} ; then |
390 |
if ! use minimal ; then |
391 |
if [[ $UID -eq 0 ]]; then |
392 |
eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root." |
393 |
fi |
394 |
fi |
395 |
fi |
396 |
|
397 |
# Check for USE flag problems in pkg_setup |
398 |
if use static && use ssl ; then |
399 |
M="MySQL does not support being built statically with SSL support enabled!" |
400 |
eerror "${M}" |
401 |
die "${M}" |
402 |
fi |
403 |
|
404 |
if ! mysql_version_is_at_least "5.2" \ |
405 |
&& use debug ; then |
406 |
# Also in package.use.mask |
407 |
die "Bug #344885: Upstream has broken USE=debug for 5.1 series >=5.1.51" |
408 |
fi |
409 |
|
410 |
if ( use cluster || use extraengine || use embedded ) \ |
411 |
&& use minimal ; then |
412 |
M="USE flags 'cluster', 'extraengine', 'embedded' conflict with 'minimal' USE flag!" |
413 |
eerror "${M}" |
414 |
die "${M}" |
415 |
fi |
416 |
|
417 |
if xtradb_patch_available \ |
418 |
&& use xtradb \ |
419 |
&& use embedded ; then |
420 |
M="USE flags 'xtradb' and 'embedded' conflict and cause build failures" |
421 |
eerror "${M}" |
422 |
die "${M}" |
423 |
fi |
424 |
|
425 |
# This should come after all of the die statements |
426 |
enewgroup mysql 60 || die "problem adding 'mysql' group" |
427 |
enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user" |
428 |
|
429 |
if [ "${PN}" != "mysql-cluster" ] && use cluster; then |
430 |
ewarn "Upstream has noted that the NDB cluster support in the 5.0 and" |
431 |
ewarn "5.1 series should NOT be put into production. In the near" |
432 |
ewarn "future, it will be disabled from building." |
433 |
ewarn "" |
434 |
ewarn "If you need NDB support, you should instead move to the new" |
435 |
ewarn "mysql-cluster package that represents that upstream NDB" |
436 |
ewarn "development." |
437 |
fi |
438 |
} |
439 |
|
440 |
# @FUNCTION: mysql-v2_src_unpack |
441 |
# @DESCRIPTION: |
442 |
# Unpack the source code |
443 |
mysql-v2_src_unpack() { |
444 |
|
445 |
# Initialize the proper variables first |
446 |
mysql_init_vars |
447 |
|
448 |
unpack ${A} |
449 |
# Grab the patches |
450 |
[[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-2_src_unpack |
451 |
|
452 |
mv -f "${WORKDIR}/${MY_SOURCEDIR}" "${S}" |
453 |
} |
454 |
|
455 |
# @FUNCTION: mysql-v2_src_prepare |
456 |
# @DESCRIPTION: |
457 |
# Apply patches to the source code and remove unneeded bundled libs. |
458 |
mysql-v2_src_prepare() { |
459 |
${BUILD_INHERIT}_src_prepare "$@" |
460 |
} |
461 |
|
462 |
# @FUNCTION: mysql-v2_src_configure |
463 |
# @DESCRIPTION: |
464 |
# Configure mysql to build the code for Gentoo respecting the use flags. |
465 |
mysql-v2_src_configure() { |
466 |
${BUILD_INHERIT}_src_configure "$@" |
467 |
} |
468 |
|
469 |
# @FUNCTION: mysql-v2_src_compile |
470 |
# @DESCRIPTION: |
471 |
# Compile the mysql code. |
472 |
mysql-v2_src_compile() { |
473 |
${BUILD_INHERIT}_src_compile "$@" |
474 |
} |
475 |
|
476 |
# @FUNCTION: mysql-v2_src_install |
477 |
# @DESCRIPTION: |
478 |
# Install mysql. |
479 |
mysql-v2_src_install() { |
480 |
${BUILD_INHERIT}_src_install "$@" |
481 |
} |
482 |
|
483 |
# @FUNCTION: mysql-v2_pkg_preinst |
484 |
# @DESCRIPTION: |
485 |
# Create the user and groups for mysql - die if that fails. |
486 |
mysql-v2_pkg_preinst() { |
487 |
enewgroup mysql 60 || die "problem adding 'mysql' group" |
488 |
enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user" |
489 |
} |
490 |
|
491 |
# @FUNCTION: mysql-v2_pkg_postinst |
492 |
# @DESCRIPTION: |
493 |
# Run post-installation tasks: |
494 |
# create the dir for logfiles if non-existant |
495 |
# touch the logfiles and secure them |
496 |
# install scripts |
497 |
# issue required steps for optional features |
498 |
# issue deprecation warnings |
499 |
mysql-v2_pkg_postinst() { |
500 |
|
501 |
# Make sure the vars are correctly initialized |
502 |
mysql_init_vars |
503 |
|
504 |
# Check FEATURES="collision-protect" before removing this |
505 |
[[ -d "${ROOT}/var/log/mysql" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}" |
506 |
|
507 |
# Secure the logfiles |
508 |
touch "${ROOT}${MY_LOGDIR}"/mysql.{log,err} |
509 |
chown mysql:mysql "${ROOT}${MY_LOGDIR}"/mysql* |
510 |
chmod 0660 "${ROOT}${MY_LOGDIR}"/mysql* |
511 |
|
512 |
# Minimal builds don't have the MySQL server |
513 |
if ! use minimal ; then |
514 |
docinto "support-files" |
515 |
for script in \ |
516 |
support-files/my-*.cnf \ |
517 |
support-files/magic \ |
518 |
support-files/ndb-config-2-node.ini |
519 |
do |
520 |
[[ -f "${script}" ]] \ |
521 |
&& dodoc "${script}" |
522 |
done |
523 |
|
524 |
docinto "scripts" |
525 |
for script in scripts/mysql* ; do |
526 |
[[ -f "${script}" ]] \ |
527 |
&& [[ "${script%.sh}" == "${script}" ]] \ |
528 |
&& dodoc "${script}" |
529 |
done |
530 |
|
531 |
einfo |
532 |
elog "You might want to run:" |
533 |
elog "\"emerge --config =${CATEGORY}/${PF}\"" |
534 |
elog "if this is a new install." |
535 |
einfo |
536 |
|
537 |
einfo |
538 |
elog "If you are upgrading major versions, you should run the" |
539 |
elog "mysql_upgrade tool." |
540 |
einfo |
541 |
fi |
542 |
|
543 |
if pbxt_available && use pbxt ; then |
544 |
# TODO: explain it better |
545 |
elog " mysql> INSTALL PLUGIN pbxt SONAME 'libpbxt.so';" |
546 |
elog " mysql> CREATE TABLE t1 (c1 int, c2 text) ENGINE=pbxt;" |
547 |
elog "if, after that, you cannot start the MySQL server," |
548 |
elog "remove the ${MY_DATADIR}/mysql/plugin.* files, then" |
549 |
elog "use the MySQL upgrade script to restore the table" |
550 |
elog "or execute the following SQL command:" |
551 |
elog " CREATE TABLE IF NOT EXISTS plugin (" |
552 |
elog " name char(64) binary DEFAULT '' NOT NULL," |
553 |
elog " dl char(128) DEFAULT '' NOT NULL," |
554 |
elog " PRIMARY KEY (name)" |
555 |
elog " ) CHARACTER SET utf8 COLLATE utf8_bin;" |
556 |
fi |
557 |
|
558 |
mysql_check_version_range "4.0 to 5.0.99.99" \ |
559 |
&& use berkdb \ |
560 |
&& elog "Berkeley DB support is deprecated and will be removed in future versions!" |
561 |
} |
562 |
|
563 |
# @FUNCTION: mysql-v2_pkg_config |
564 |
# @DESCRIPTION: |
565 |
# Configure mysql environment. |
566 |
mysql-v2_pkg_config() { |
567 |
|
568 |
local old_MY_DATADIR="${MY_DATADIR}" |
569 |
|
570 |
# Make sure the vars are correctly initialized |
571 |
mysql_init_vars |
572 |
|
573 |
[[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR" |
574 |
|
575 |
if built_with_use ${CATEGORY}/${PN} minimal ; then |
576 |
die "Minimal builds do NOT include the MySQL server" |
577 |
fi |
578 |
|
579 |
if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then |
580 |
local MY_DATADIR_s="$(strip_duplicate_slashes ${ROOT}/${MY_DATADIR})" |
581 |
local old_MY_DATADIR_s="$(strip_duplicate_slashes ${ROOT}/${old_MY_DATADIR})" |
582 |
|
583 |
if [[ -d "${old_MY_DATADIR_s}" ]]; then |
584 |
if [[ -d "${MY_DATADIR_s}" ]]; then |
585 |
ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist" |
586 |
ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}" |
587 |
else |
588 |
elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}" |
589 |
mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \ |
590 |
|| die "Moving MY_DATADIR failed" |
591 |
fi |
592 |
else |
593 |
ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist" |
594 |
if [[ -d "${MY_DATADIR_s}" ]]; then |
595 |
ewarn "Attempting to use ${MY_DATADIR_s}" |
596 |
else |
597 |
eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist" |
598 |
die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}" |
599 |
fi |
600 |
fi |
601 |
fi |
602 |
|
603 |
local pwd1="a" |
604 |
local pwd2="b" |
605 |
local maxtry=15 |
606 |
|
607 |
if [ -z "${MYSQL_ROOT_PASSWORD}" -a -f "${ROOT}/root/.my.cnf" ]; then |
608 |
MYSQL_ROOT_PASSWORD="$(sed -n -e '/^password=/s,^password=,,gp' "${ROOT}/root/.my.cnf")" |
609 |
fi |
610 |
|
611 |
if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then |
612 |
ewarn "You have already a MySQL database in place." |
613 |
ewarn "(${ROOT}/${MY_DATADIR}/*)" |
614 |
ewarn "Please rename or delete it if you wish to replace it." |
615 |
die "MySQL database already exists!" |
616 |
fi |
617 |
|
618 |
# Bug #213475 - MySQL _will_ object strenously if your machine is named |
619 |
# localhost. Also causes weird failures. |
620 |
[[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost" |
621 |
|
622 |
if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then |
623 |
|
624 |
einfo "Please provide a password for the mysql 'root' user now, in the" |
625 |
einfo "MYSQL_ROOT_PASSWORD env var or through the /root/.my.cnf file." |
626 |
ewarn "Avoid [\"'\\_%] characters in the password" |
627 |
read -rsp " >" pwd1 ; echo |
628 |
|
629 |
einfo "Retype the password" |
630 |
read -rsp " >" pwd2 ; echo |
631 |
|
632 |
if [[ "x$pwd1" != "x$pwd2" ]] ; then |
633 |
die "Passwords are not the same" |
634 |
fi |
635 |
MYSQL_ROOT_PASSWORD="${pwd1}" |
636 |
unset pwd1 pwd2 |
637 |
fi |
638 |
|
639 |
local options="" |
640 |
local sqltmp="$(emktemp)" |
641 |
|
642 |
local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql" |
643 |
[[ -r "${help_tables}" ]] \ |
644 |
&& cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \ |
645 |
|| touch "${TMPDIR}/fill_help_tables.sql" |
646 |
help_tables="${TMPDIR}/fill_help_tables.sql" |
647 |
|
648 |
pushd "${TMPDIR}" &>/dev/null |
649 |
"${ROOT}/usr/bin/mysql_install_db" >"${TMPDIR}"/mysql_install_db.log 2>&1 |
650 |
if [ $? -ne 0 ]; then |
651 |
grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2 |
652 |
die "Failed to run mysql_install_db. Please review /var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log" |
653 |
fi |
654 |
popd &>/dev/null |
655 |
[[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \ |
656 |
|| die "MySQL databases not installed" |
657 |
chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null |
658 |
chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null |
659 |
|
660 |
# Figure out which options we need to disable to do the setup |
661 |
helpfile="${TMPDIR}/mysqld-help" |
662 |
${ROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null |
663 |
for opt in grant-tables host-cache name-resolve networking slave-start bdb \ |
664 |
federated innodb ssl log-bin relay-log slow-query-log external-locking \ |
665 |
ndbcluster \ |
666 |
; do |
667 |
optexp="--(skip-)?${opt}" optfull="--skip-${opt}" |
668 |
egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}" |
669 |
done |
670 |
# But some options changed names |
671 |
egrep -sq external-locking "${helpfile}" && \ |
672 |
options="${options/skip-locking/skip-external-locking}" |
673 |
|
674 |
# Filling timezones, see |
675 |
# http://dev.mysql.com/doc/mysql/en/time-zone-support.html |
676 |
"${ROOT}/usr/bin/mysql_tzinfo_to_sql" "${ROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null |
677 |
|
678 |
if [[ -r "${help_tables}" ]] ; then |
679 |
cat "${help_tables}" >> "${sqltmp}" |
680 |
fi |
681 |
|
682 |
einfo "Creating the mysql database and setting proper" |
683 |
einfo "permissions on it ..." |
684 |
|
685 |
local socket="${ROOT}/var/run/mysqld/mysqld${RANDOM}.sock" |
686 |
local pidfile="${ROOT}/var/run/mysqld/mysqld${RANDOM}.pid" |
687 |
local mysqld="${ROOT}/usr/sbin/mysqld \ |
688 |
${options} \ |
689 |
--user=mysql \ |
690 |
--basedir=${ROOT}/usr \ |
691 |
--datadir=${ROOT}/${MY_DATADIR} \ |
692 |
--max_allowed_packet=8M \ |
693 |
--net_buffer_length=16K \ |
694 |
--default-storage-engine=MyISAM \ |
695 |
--socket=${socket} \ |
696 |
--pid-file=${pidfile}" |
697 |
#einfo "About to start mysqld: ${mysqld}" |
698 |
ebegin "Starting mysqld" |
699 |
${mysqld} & |
700 |
rc=$? |
701 |
while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do |
702 |
maxtry=$((${maxtry}-1)) |
703 |
echo -n "." |
704 |
sleep 1 |
705 |
done |
706 |
eend $rc |
707 |
|
708 |
if ! [[ -S "${socket}" ]]; then |
709 |
die "Completely failed to start up mysqld with: ${mysqld}" |
710 |
fi |
711 |
|
712 |
ebegin "Setting root password" |
713 |
# Do this from memory, as we don't want clear text passwords in temp files |
714 |
local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'" |
715 |
"${ROOT}/usr/bin/mysql" \ |
716 |
--socket=${socket} \ |
717 |
-hlocalhost \ |
718 |
-e "${sql}" |
719 |
eend $? |
720 |
|
721 |
ebegin "Loading \"zoneinfo\", this step may require a few seconds ..." |
722 |
"${ROOT}/usr/bin/mysql" \ |
723 |
--socket=${socket} \ |
724 |
-hlocalhost \ |
725 |
-uroot \ |
726 |
-p"${MYSQL_ROOT_PASSWORD}" \ |
727 |
mysql < "${sqltmp}" |
728 |
rc=$? |
729 |
eend $? |
730 |
[ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!" |
731 |
|
732 |
# Stop the server and cleanup |
733 |
einfo "Stopping the server ..." |
734 |
kill $(< "${pidfile}" ) |
735 |
rm -f "${sqltmp}" |
736 |
wait %1 |
737 |
einfo "Done" |
738 |
} |
739 |
|
740 |
# @FUNCTION: mysql-v2_pkg_postrm |
741 |
# @DESCRIPTION: |
742 |
# Remove mysql symlinks. |
743 |
mysql-v2_pkg_postrm() { |
744 |
|
745 |
: # mysql_lib_symlinks "${D}" |
746 |
} |