/[gentoo-x86]/eclass/mysql-v2.eclass
Gentoo

Contents of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.32 - (show annotations) (download)
Sat Jul 19 10:18:41 2014 UTC (5 days, 7 hours ago) by grobian
Branch: MAIN
CVS Tags: HEAD
Changes since 1.31: +16 -16 lines
Fix misc issues for Prefix allowing install and config of mysql

1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/mysql-v2.eclass,v 1.31 2014/06/20 00:03:33 grknight Exp $
4
5 # @ECLASS: mysql-v2.eclass
6 # @MAINTAINER:
7 # Maintainers:
8 # - MySQL Team <mysql-bugs@gentoo.org>
9 # - Robin H. Johnson <robbat2@gentoo.org>
10 # - Jorge Manuel B. S. Vicetto <jmbsvicetto@gentoo.org>
11 # - Brian Evans <grknight@gentoo.org>
12 # @BLURB: This eclass provides most of the functions for mysql ebuilds
13 # @DESCRIPTION:
14 # The mysql-v2.eclass is the base eclass to build the mysql and
15 # alternative projects (mariadb and percona) ebuilds.
16 # This eclass uses the mysql-autotools and mysql-cmake eclasses for the
17 # specific bits related to the build system.
18 # It provides the src_unpack, src_prepare, src_configure, src_compile,
19 # src_install, pkg_preinst, pkg_postinst, pkg_config and pkg_postrm
20 # phase hooks.
21
22 # @ECLASS-VARIABLE: BUILD
23 # @DESCRIPTION:
24 # Build type of the mysql version
25 : ${BUILD:=autotools}
26
27 case ${BUILD} in
28 "cmake")
29 BUILD_INHERIT="mysql-cmake"
30 ;;
31 "autotools")
32 BUILD_INHERIT="mysql-autotools"
33
34 WANT_AUTOCONF="latest"
35 WANT_AUTOMAKE="latest"
36 ;;
37 *)
38 die "${BUILD} is not a valid build system for mysql"
39 ;;
40 esac
41
42 MYSQL_EXTRAS=""
43
44 # @ECLASS-VARIABLE: MYSQL_EXTRAS_VER
45 # @DESCRIPTION:
46 # The version of the MYSQL_EXTRAS repo to use to build mysql
47 # Use "none" to disable it's use
48 [[ ${MY_EXTRAS_VER} == "live" ]] && MYSQL_EXTRAS="git-2"
49
50 inherit eutils flag-o-matic gnuconfig ${MYSQL_EXTRAS} ${BUILD_INHERIT} mysql_fx versionator toolchain-funcs user
51
52 #
53 # Supported EAPI versions and export functions
54 #
55
56 case "${EAPI:-0}" in
57 4|5) ;;
58 *) die "Unsupported EAPI: ${EAPI}" ;;
59 esac
60
61 EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_install pkg_preinst pkg_postinst pkg_config pkg_postrm
62
63 #
64 # VARIABLES:
65 #
66
67 # Shorten the path because the socket path length must be shorter than 107 chars
68 # and we will run a mysql server during test phase
69 S="${WORKDIR}/mysql"
70
71 [[ ${MY_EXTRAS_VER} == "latest" ]] && MY_EXTRAS_VER="20090228-0714Z"
72 if [[ ${MY_EXTRAS_VER} == "live" ]]; then
73 EGIT_PROJECT=mysql-extras
74 EGIT_REPO_URI="git://git.overlays.gentoo.org/proj/mysql-extras.git"
75 RESTRICT="userpriv"
76 fi
77
78 # @ECLASS-VARIABLE: MYSQL_PV_MAJOR
79 # @DESCRIPTION:
80 # Upstream MySQL considers the first two parts of the version number to be the
81 # major version. Upgrades that change major version should always run
82 # mysql_upgrade.
83 MYSQL_PV_MAJOR="$(get_version_component_range 1-2 ${PV})"
84
85 # Cluster is a special case...
86 if [[ "${PN}" == "mysql-cluster" ]]; then
87 case $PV in
88 6.1*|7.0*|7.1*) MYSQL_PV_MAJOR=5.1 ;;
89 7.2*|7.3*) MYSQL_PV_MAJOR=5.5 ;;
90 esac
91 fi
92
93 # @ECLASS-VARIABLE: MYSQL_VERSION_ID
94 # @DESCRIPTION:
95 # MYSQL_VERSION_ID will be:
96 # major * 10e6 + minor * 10e4 + micro * 10e2 + gentoo revision number, all [0..99]
97 # This is an important part, because many of the choices the MySQL ebuild will do
98 # depend on this variable.
99 # In particular, the code below transforms a $PVR like "5.0.18-r3" in "5001803"
100 # We also strip off upstream's trailing letter that they use to respin tarballs
101 MYSQL_VERSION_ID=""
102 tpv="${PV%[a-z]}"
103 tpv=( ${tpv//[-._]/ } ) ; tpv[3]="${PVR:${#PV}}" ; tpv[3]="${tpv[3]##*-r}"
104 for vatom in 0 1 2 3 ; do
105 # pad to length 2
106 tpv[${vatom}]="00${tpv[${vatom}]}"
107 MYSQL_VERSION_ID="${MYSQL_VERSION_ID}${tpv[${vatom}]:0-2}"
108 done
109 # strip leading "0" (otherwise it's considered an octal number by BASH)
110 MYSQL_VERSION_ID=${MYSQL_VERSION_ID##"0"}
111
112 # This eclass should only be used with at least mysql-5.1.50
113 mysql_version_is_at_least "5.1.50" || die "This eclass should only be used with >=mysql-5.1.50"
114
115 # @ECLASS-VARIABLE: XTRADB_VER
116 # @DEFAULT_UNSET
117 # @DESCRIPTION:
118 # Version of the XTRADB storage engine
119
120 # @ECLASS-VARIABLE: PERCONA_VER
121 # @DEFAULT_UNSET
122 # @DESCRIPTION:
123 # Designation by PERCONA for a MySQL version to apply an XTRADB release
124
125 # Work out the default SERVER_URI correctly
126 if [[ -z ${SERVER_URI} ]]; then
127 [[ -z ${MY_PV} ]] && MY_PV="${PV//_/-}"
128 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]]; then
129 # Beginning with 5.5, MariaDB stopped putting beta, alpha or rc on their tarball names
130 mysql_version_is_at_least "5.5" && MARIA_FULL_PV=$(get_version_component_range 1-3) || \
131 MARIA_FULL_PV=$(replace_version_separator 3 '-' ${MY_PV})
132 MARIA_FULL_P="${PN}-${MARIA_FULL_PV}"
133 SERVER_URI="
134 http://ftp.osuosl.org/pub/mariadb/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
135 http://ftp.osuosl.org/pub/mariadb/${MARIA_FULL_P}/source/${MARIA_FULL_P}.tar.gz
136 http://mirror.jmu.edu/pub/mariadb/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
137 http://mirrors.coreix.net/mariadb/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
138 http://mirrors.syringanetworks.net/mariadb/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
139 http://mirrors.fe.up.pt/pub/mariadb/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
140 http://mirror2.hs-esslingen.de/mariadb/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
141 "
142 if [[ ${PN} == "mariadb-galera" ]]; then
143 MY_SOURCEDIR="${PN%%-galera}-${MARIA_FULL_PV}"
144 fi
145 elif [[ ${PN} == "percona-server" ]]; then
146 PERCONA_PN="Percona-Server"
147 MIRROR_PV=$(get_version_component_range 1-2 ${PV})
148 MY_PV=$(get_version_component_range 1-3 ${PV})
149 PERCONA_RELEASE=$(get_version_component_range 4-5 ${PV})
150 PERCONA_RC=$(get_version_component_range 6 ${PV})
151 SERVER_URI="http://www.percona.com/redir/downloads/${PERCONA_PN}-${MIRROR_PV}/${PERCONA_PN}-${MY_PV}-${PERCONA_RC}${PERCONA_RELEASE}/source/tarball/${PN}-${MY_PV}-${PERCONA_RC}${PERCONA_RELEASE}.tar.gz"
152 # http://www.percona.com/redir/downloads/Percona-Server-5.5/LATEST/source/tarball/Percona-Server-5.5.30-30.2.tar.gz
153 # http://www.percona.com/redir/downloads/Percona-Server-5.6/Percona-Server-5.6.13-rc60.5/source/tarball/Percona-Server-5.6.13-rc60.5.tar.gz
154 else
155 if [[ "${PN}" == "mysql-cluster" ]] ; then
156 URI_DIR="MySQL-Cluster"
157 URI_FILE="mysql-cluster-gpl"
158 else
159 URI_DIR="MySQL"
160 URI_FILE="mysql"
161 fi
162 URI_A="${URI_FILE}-${MY_PV}.tar.gz"
163 MIRROR_PV=$(get_version_component_range 1-2 ${PV})
164 # Recently upstream switched to an archive site, and not on mirrors
165 SERVER_URI="http://downloads.mysql.com/archives/${URI_FILE}-${MIRROR_PV}/${URI_A}
166 mirror://mysql/Downloads/${URI_DIR}-${PV%.*}/${URI_A}"
167 fi
168 fi
169
170 # Define correct SRC_URIs
171 SRC_URI="${SERVER_URI}"
172
173 # Gentoo patches to MySQL
174 if [[ ${MY_EXTRAS_VER} != "live" && ${MY_EXTRAS_VER} != "none" ]]; then
175 SRC_URI="${SRC_URI}
176 mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
177 http://g3nt8.org/patches/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
178 http://dev.gentoo.org/~robbat2/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
179 http://dev.gentoo.org/~jmbsvicetto/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
180 http://dev.gentoo.org/~grknight/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
181 fi
182
183 DESCRIPTION="A fast, multi-threaded, multi-user SQL database server"
184 HOMEPAGE="http://www.mysql.com/"
185 if [[ ${PN} == "mariadb" ]]; then
186 HOMEPAGE="http://mariadb.org/"
187 DESCRIPTION="An enhanced, drop-in replacement for MySQL"
188 fi
189 if [[ ${PN} == "mariadb-galera" ]]; then
190 HOMEPAGE="http://mariadb.org/"
191 DESCRIPTION="An enhanced, drop-in replacement for MySQL with Galera Replication"
192 fi
193 if [[ ${PN} == "percona-server" ]]; then
194 HOMEPAGE="http://www.percona.com/software/percona-server"
195 DESCRIPTION="An enhanced, drop-in replacement for MySQL from the Percona team"
196 fi
197 LICENSE="GPL-2"
198 SLOT="0"
199
200 case "${BUILD}" in
201 "autotools")
202 IUSE="big-tables debug embedded minimal +perl selinux ssl static test"
203 ;;
204 "cmake")
205 IUSE="debug embedded minimal +perl selinux ssl static static-libs test"
206 ;;
207 esac
208
209 # Common IUSE
210 IUSE="${IUSE} latin1 extraengine cluster max-idx-128 +community profiling"
211
212 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] && \
213 mysql_version_is_at_least "5.5" || mysql_check_version_range "5.5.37 to 5.6.11.99" ; then
214 IUSE="bindist ${IUSE}"
215 fi
216
217 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]]; then
218 mysql_check_version_range "5.1.38 to 5.3.99" && IUSE="${IUSE} libevent"
219 mysql_version_is_at_least "5.2" && IUSE="${IUSE} oqgraph" && \
220 REQUIRED_USE="${REQUIRED_USE} minimal? ( !oqgraph )"
221 mysql_version_is_at_least "5.2.5" && IUSE="${IUSE} sphinx" && \
222 REQUIRED_USE="${REQUIRED_USE} minimal? ( !sphinx )"
223 mysql_version_is_at_least "5.2.10" && IUSE="${IUSE} pam"
224 # 5.5.33 and 10.0.5 add TokuDB. Authors strongly recommend jemalloc or perfomance suffers
225 mysql_version_is_at_least "10.0.5" && IUSE="${IUSE} tokudb odbc xml" && \
226 REQUIRED_USE="${REQUIRED_USE} odbc? ( extraengine ) xml? ( extraengine ) tokudb? ( jemalloc )"
227 mysql_check_version_range "5.5.33 to 5.5.99" && IUSE="${IUSE} tokudb" && \
228 REQUIRED_USE="${REQUIRED_USE} tokudb? ( jemalloc )"
229 fi
230
231 if mysql_version_is_at_least "5.5"; then
232 REQUIRED_USE="${REQUIRED_USE} tcmalloc? ( !jemalloc ) jemalloc? ( !tcmalloc )"
233 IUSE="${IUSE} jemalloc tcmalloc"
234 fi
235
236 if mysql_version_is_at_least "5.5.7"; then
237 IUSE="${IUSE} systemtap"
238 fi
239
240 if [[ ${PN} == "percona-server" ]]; then
241 mysql_version_is_at_least "5.5.10" && IUSE="${IUSE} pam"
242 fi
243
244 REQUIRED_USE="${REQUIRED_USE} minimal? ( !cluster !extraengine !embedded ) static? ( !ssl )"
245
246 #
247 # DEPENDENCIES:
248 #
249
250 # Be warned, *DEPEND are version-dependant
251 # These are used for both runtime and compiletime
252 DEPEND="
253 ssl? ( >=dev-libs/openssl-0.9.6d )
254 kernel_linux? ( sys-process/procps )
255 >=sys-apps/sed-4
256 >=sys-apps/texinfo-4.7-r1
257 >=sys-libs/zlib-1.2.3
258 "
259 # TODO: add this as a dep if it is moved from the overlay
260 # !dev-db/mariadb-native-client[mysqlcompat]
261
262 # dev-db/mysql-5.6.12+ only works with dev-libs/libedit
263 if [[ ${PN} == "mysql" || ${PN} == "percona-server" ]] && mysql_version_is_at_least "5.6.12" ; then
264 DEPEND="${DEPEND} dev-libs/libedit"
265 else
266 if mysql_version_is_at_least "5.5" ; then
267 DEPEND="${DEPEND} !bindist? ( >=sys-libs/readline-4.1 )"
268 else
269 DEPEND="${DEPEND} >=sys-libs/readline-4.1"
270 fi
271 fi
272
273 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] ; then
274 mysql_check_version_range "5.1.38 to 5.3.99" && DEPEND="${DEPEND} libevent? ( >=dev-libs/libevent-1.4 )"
275 mysql_version_is_at_least "5.2" && DEPEND="${DEPEND} oqgraph? ( >=dev-libs/boost-1.40.0 )"
276 mysql_version_is_at_least "5.2.10" && DEPEND="${DEPEND} !minimal? ( pam? ( virtual/pam ) )"
277 # Bug 441700 MariaDB >=5.3 include custom mytop
278 mysql_version_is_at_least "5.3" && DEPEND="${DEPEND} perl? ( !dev-db/mytop )"
279 if mysql_version_is_at_least "10.0.5" ; then
280 DEPEND="${DEPEND}
281 odbc? ( dev-db/unixODBC )
282 xml? ( dev-libs/libxml2 )
283 "
284 fi
285 mysql_version_is_at_least "10.0.7" && DEPEND="${DEPEND} oqgraph? ( dev-libs/judy )"
286 if mysql_version_is_at_least "10.0.9" ; then
287 DEPEND="${DEPEND} >=dev-libs/libpcre-8.35"
288 fi
289 fi
290
291 # Having different flavours at the same time is not a good idea
292 for i in "mysql" "mariadb" "mariadb-galera" "percona-server" "mysql-cluster" ; do
293 [[ ${i} == ${PN} ]] ||
294 DEPEND="${DEPEND} !dev-db/${i}"
295 done
296
297 if mysql_version_is_at_least "5.5.7" ; then
298 DEPEND="${DEPEND}
299 jemalloc? ( dev-libs/jemalloc[static-libs?] )
300 tcmalloc? ( dev-util/google-perftools )
301 >=sys-libs/zlib-1.2.3[static-libs?]
302 ssl? ( >=dev-libs/openssl-0.9.6d[static-libs?] )
303 systemtap? ( >=dev-util/systemtap-1.3 )
304 kernel_linux? ( dev-libs/libaio )
305 "
306 fi
307
308 if [[ ${PN} == "mysql-cluster" ]] ; then
309 # TODO: This really should include net-misc/memcached
310 # but the package does not install the files it seeks.
311 mysql_version_is_at_least "7.2.3" && \
312 DEPEND="${DEPEND} dev-libs/libevent"
313 fi
314
315 # prefix: first need to implement something for #196294
316 RDEPEND="${DEPEND}
317 !minimal? ( !prefix? ( dev-db/mysql-init-scripts ) )
318 selinux? ( sec-policy/selinux-mysql )
319 "
320
321 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] ; then
322 # Bug 455016 Add dependencies of mytop
323 if mysql_version_is_at_least "5.3" ; then
324 RDEPEND="${RDEPEND}
325 perl? (
326 virtual/perl-Getopt-Long
327 dev-perl/TermReadKey
328 virtual/perl-Term-ANSIColor
329 virtual/perl-Time-HiRes
330 )
331 "
332 fi
333 fi
334
335 if [[ ${PN} == "mariadb-galera" ]] ; then
336 # The wsrep API version must match between the ebuild and sys-cluster/galera.
337 # This will be indicated by WSREP_REVISION in the ebuild and the first number
338 # in the version of sys-cluster/galera
339 RDEPEND="${RDEPEND}
340 =sys-cluster/galera-${WSREP_REVISION}*
341 "
342 fi
343
344 if [[ ${PN} == "mysql-cluster" ]] ; then
345 mysql_version_is_at_least "7.2.9" && RDEPEND="${RDEPEND} java? ( >=virtual/jre-1.6 )" && \
346 DEPEND="${DEPEND} java? ( >=virtual/jdk-1.6 )"
347 fi
348
349 DEPEND="${DEPEND}
350 virtual/yacc
351 "
352
353 DEPEND="${DEPEND} static? ( sys-libs/ncurses[static-libs] )"
354
355 # compile-time-only
356 DEPEND="${DEPEND} >=dev-util/cmake-2.4.3"
357
358 # compile-time-only
359 if mysql_version_is_at_least "5.5.8" ; then
360 DEPEND="${DEPEND} >=dev-util/cmake-2.6.3"
361 fi
362
363 # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
364 PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
365
366 # For other stuff to bring us in
367 PDEPEND="${PDEPEND} ~virtual/mysql-${MYSQL_PV_MAJOR}"
368
369 #
370 # External patches
371 #
372
373 # MariaDB has integrated PBXT until it was dropped in version 5.5.33
374 # PBXT_VERSION means that we have a PBXT patch for this PV
375 # PBXT was only introduced after 5.1.12
376 pbxt_patch_available() {
377 [[ ${PN} != "mariadb" && ${PN} != "mariadb-galera" && ( -n "${PBXT_VERSION}" ) ]]
378 return $?
379 }
380
381 pbxt_available() {
382 pbxt_patch_available || [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] && mysql_check_version_range "5.1 to 5.5.32"
383 return $?
384 }
385
386 # Get the percona tarball if XTRADB_VER and PERCONA_VER are both set
387 # MariaDB has integrated XtraDB
388 # XTRADB_VERS means that we have a XTRADB patch for this PV
389 # XTRADB was only introduced after 5.1.26
390 xtradb_patch_available() {
391 [[ ${PN} != "mariadb" && ${PN} != "mariadb-galera"
392 && ( -n "${XTRADB_VER}" ) && ( -n "${PERCONA_VER}" ) ]]
393 return $?
394 }
395
396 if pbxt_patch_available; then
397
398 PBXT_P="pbxt-${PBXT_VERSION}"
399 PBXT_SRC_URI="http://www.primebase.org/download/${PBXT_P}.tar.gz mirror://sourceforge/pbxt/${PBXT_P}.tar.gz"
400 SRC_URI="${SRC_URI} pbxt? ( ${PBXT_SRC_URI} )"
401 fi
402
403 # PBXT_NEWSTYLE means pbxt is in storage/ and gets enabled as other plugins
404 # vs. built outside the dir
405 if pbxt_available; then
406
407 IUSE="${IUSE} pbxt"
408 PBXT_NEWSTYLE=1
409 REQUIRED_USE="${REQUIRED_USE} pbxt? ( !embedded ) "
410 fi
411
412 if xtradb_patch_available; then
413 XTRADB_P="percona-xtradb-${XTRADB_VER}"
414 XTRADB_SRC_URI_COMMON="${PERCONA_VER}/source/${XTRADB_P}.tar.gz"
415 XTRADB_SRC_B1="http://www.percona.com/"
416 XTRADB_SRC_B2="${XTRADB_SRC_B1}/percona-builds/"
417 XTRADB_SRC_URI1="${XTRADB_SRC_B2}/Percona-Server/Percona-Server-${XTRADB_SRC_URI_COMMON}"
418 XTRADB_SRC_URI2="${XTRADB_SRC_B2}/xtradb/${XTRADB_SRC_URI_COMMON}"
419 XTRADB_SRC_URI3="${XTRADB_SRC_B1}/${PN}/xtradb/${XTRADB_SRC_URI_COMMON}"
420 SRC_URI="${SRC_URI} xtradb? ( ${XTRADB_SRC_URI1} ${XTRADB_SRC_URI2} ${XTRADB_SRC_URI3} )"
421 IUSE="${IUSE} xtradb"
422 REQUIRED_USE="${REQUIRED_USE} xtradb? ( !embedded ) "
423 fi
424
425 #
426 # HELPER FUNCTIONS:
427 #
428
429 # @FUNCTION: mysql-v2_disable_test
430 # @DESCRIPTION:
431 # Helper function to disable specific tests.
432 mysql-v2_disable_test() {
433 ${BUILD_INHERIT}_disable_test "$@"
434 }
435
436 # @FUNCTION: mysql-v2_configure_minimal
437 # @DESCRIPTION:
438 # Helper function to configure minimal build
439 configure_minimal() {
440 ${BUILD_INHERIT}_configure_minimal "$@"
441 }
442
443 # @FUNCTION: mysql-v2_configure_common
444 # @DESCRIPTION:
445 # Helper function to configure common builds
446 configure_common() {
447 ${BUILD_INHERIT}_configure_common "$@"
448 }
449
450 #
451 # EBUILD FUNCTIONS
452 #
453
454 # @FUNCTION: mysql-v2_pkg_setup
455 # @DESCRIPTION:
456 # Perform some basic tests and tasks during pkg_setup phase:
457 # die if FEATURES="test", USE="-minimal" and not using FEATURES="userpriv"
458 # check for conflicting use flags
459 # create new user and group for mysql
460 # warn about deprecated features
461 mysql-v2_pkg_setup() {
462
463 if has test ${FEATURES} ; then
464 if ! use minimal ; then
465 if ! has userpriv ${FEATURES} ; then
466 eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
467 fi
468 fi
469 fi
470
471 # Check for USE flag problems in pkg_setup
472 if ! mysql_version_is_at_least "5.2" && use debug ; then
473 # Also in package.use.mask
474 die "Bug #344885: Upstream has broken USE=debug for 5.1 series >=5.1.51"
475 fi
476
477 # This should come after all of the die statements
478 enewgroup mysql 60 || die "problem adding 'mysql' group"
479 enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
480
481 if use cluster && [[ "${PN}" != "mysql-cluster" ]]; then
482 ewarn "Upstream has noted that the NDB cluster support in the 5.0 and"
483 ewarn "5.1 series should NOT be put into production. In the near"
484 ewarn "future, it will be disabled from building."
485 fi
486
487 if [[ ${PN} == "mysql-cluster" ]] ; then
488 mysql_version_is_at_least "7.2.9" && java-pkg-opt-2_pkg_setup
489 fi
490
491 if use_if_iuse tokudb && [[ $(gcc-major-version) -lt 4 || $(gcc-major-version) -eq 4 && $(gcc-minor-version) -lt 7 ]] ; then
492 eerror "${PN} with tokudb needs to be built with gcc-4.7 or later."
493 eerror "Please use gcc-config to switch to gcc-4.7 or later version."
494 die
495 fi
496
497 }
498
499 # @FUNCTION: mysql-v2_src_unpack
500 # @DESCRIPTION:
501 # Unpack the source code
502 mysql-v2_src_unpack() {
503
504 # Initialize the proper variables first
505 mysql_init_vars
506
507 unpack ${A}
508 # Grab the patches
509 [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-2_src_unpack
510
511 mv -f "${WORKDIR}/${MY_SOURCEDIR}" "${S}"
512 }
513
514 # @FUNCTION: mysql-v2_src_prepare
515 # @DESCRIPTION:
516 # Apply patches to the source code and remove unneeded bundled libs.
517 mysql-v2_src_prepare() {
518 ${BUILD_INHERIT}_src_prepare "$@"
519 if [[ ${PN} == "mysql-cluster" ]] ; then
520 mysql_version_is_at_least "7.2.9" && java-pkg-opt-2_src_prepare
521 fi
522 }
523
524 # @FUNCTION: mysql-v2_src_configure
525 # @DESCRIPTION:
526 # Configure mysql to build the code for Gentoo respecting the use flags.
527 mysql-v2_src_configure() {
528 ${BUILD_INHERIT}_src_configure "$@"
529 }
530
531 # @FUNCTION: mysql-v2_src_compile
532 # @DESCRIPTION:
533 # Compile the mysql code.
534 mysql-v2_src_compile() {
535 ${BUILD_INHERIT}_src_compile "$@"
536 }
537
538 # @FUNCTION: mysql-v2_src_install
539 # @DESCRIPTION:
540 # Install mysql.
541 mysql-v2_src_install() {
542 ${BUILD_INHERIT}_src_install "$@"
543 }
544
545 # @FUNCTION: mysql-v2_pkg_preinst
546 # @DESCRIPTION:
547 # Create the user and groups for mysql - die if that fails.
548 mysql-v2_pkg_preinst() {
549 if [[ ${PN} == "mysql-cluster" ]] ; then
550 mysql_version_is_at_least "7.2.9" && java-pkg-opt-2_pkg_preinst
551 fi
552 enewgroup mysql 60 || die "problem adding 'mysql' group"
553 enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
554 }
555
556 # @FUNCTION: mysql-v2_pkg_postinst
557 # @DESCRIPTION:
558 # Run post-installation tasks:
559 # create the dir for logfiles if non-existant
560 # touch the logfiles and secure them
561 # install scripts
562 # issue required steps for optional features
563 # issue deprecation warnings
564 mysql-v2_pkg_postinst() {
565
566 # Make sure the vars are correctly initialized
567 mysql_init_vars
568
569 # Check FEATURES="collision-protect" before removing this
570 [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
571
572 # Secure the logfiles
573 touch "${ROOT}${MY_LOGDIR}"/mysql.{log,err}
574 chown mysql:mysql "${ROOT}${MY_LOGDIR}"/mysql*
575 chmod 0660 "${ROOT}${MY_LOGDIR}"/mysql*
576
577 # Minimal builds don't have the MySQL server
578 if ! use minimal ; then
579 docinto "support-files"
580 for script in \
581 support-files/my-*.cnf \
582 support-files/magic \
583 support-files/ndb-config-2-node.ini
584 do
585 [[ -f "${script}" ]] \
586 && dodoc "${script}"
587 done
588
589 docinto "scripts"
590 for script in scripts/mysql* ; do
591 if [[ -f "${script}" && "${script%.sh}" == "${script}" ]]; then
592 dodoc "${script}"
593 fi
594 done
595
596 if [[ ${PN} == "mariadb" || ${PN} == "mariadb-galera" ]] ; then
597 if use_if_iuse pam ; then
598 einfo
599 elog "This install includes the PAM authentication plugin."
600 elog "To activate and configure the PAM plugin, please read:"
601 elog "https://kb.askmonty.org/en/pam-authentication-plugin/"
602 einfo
603 fi
604 fi
605
606 einfo
607 elog "You might want to run:"
608 elog "\"emerge --config =${CATEGORY}/${PF}\""
609 elog "if this is a new install."
610 einfo
611
612 einfo
613 elog "If you are upgrading major versions, you should run the"
614 elog "mysql_upgrade tool."
615 einfo
616
617 if [[ ${PN} == "mariadb-galera" ]] ; then
618 einfo
619 elog "Be sure to edit the my.cnf file to activate your cluster settings."
620 elog "This should be done after running \"emerge --config =${CATEGORY}/${PF}\""
621 elog "The first time the cluster is activated, you should add"
622 elog "--wsrep-new-cluster to the options in /etc/conf.d/mysql for one node."
623 elog "This option should then be removed for subsequent starts."
624 einfo
625 fi
626 fi
627
628 if use_if_iuse pbxt ; then
629 elog "Note: PBXT is now statically built when enabled."
630 elog ""
631 elog "If, you previously installed as a plugin and "
632 elog "you cannot start the MySQL server,"
633 elog "remove the ${MY_DATADIR}/mysql/plugin.* files, then"
634 elog "use the MySQL upgrade script to restore the table"
635 elog "or execute the following SQL command:"
636 elog " CREATE TABLE IF NOT EXISTS plugin ("
637 elog " name char(64) binary DEFAULT '' NOT NULL,"
638 elog " dl char(128) DEFAULT '' NOT NULL,"
639 elog " PRIMARY KEY (name)"
640 elog " ) CHARACTER SET utf8 COLLATE utf8_bin;"
641 fi
642 }
643
644 # @FUNCTION: mysql-v2_getopt
645 # @DESCRIPTION:
646 # Use my_print_defaults to extract specific config options
647 mysql-v2_getopt() {
648 local mypd="${EROOT}"/usr/bin/my_print_defaults
649 section="$1"
650 flag="--${2}="
651 "${mypd}" $section | sed -n "/^${flag}/p"
652 }
653
654 # @FUNCTION: mysql-v2_getoptval
655 # @DESCRIPTION:
656 # Use my_print_defaults to extract specific config options
657 mysql-v2_getoptval() {
658 local mypd="${EROOT}"/usr/bin/my_print_defaults
659 section="$1"
660 flag="--${2}="
661 "${mypd}" $section | sed -n "/^${flag}/s,${flag},,gp"
662 }
663
664 # @FUNCTION: mysql-v2_pkg_config
665 # @DESCRIPTION:
666 # Configure mysql environment.
667 mysql-v2_pkg_config() {
668
669 local old_MY_DATADIR="${MY_DATADIR}"
670 local old_HOME="${HOME}"
671 # my_print_defaults needs to read stuff in $HOME/.my.cnf
672 export HOME=${EPREFIX}/root
673
674 # Make sure the vars are correctly initialized
675 mysql_init_vars
676
677 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
678
679 if built_with_use ${CATEGORY}/${PN} minimal ; then
680 die "Minimal builds do NOT include the MySQL server"
681 fi
682
683 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
684 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
685 MY_DATADIR_s="${MY_DATADIR_s%%/}"
686 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
687 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
688
689 if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]]; then
690 if [[ -d "${MY_DATADIR_s}" ]]; then
691 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
692 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
693 else
694 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
695 mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
696 || die "Moving MY_DATADIR failed"
697 fi
698 else
699 ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
700 if [[ -d "${MY_DATADIR_s}" ]]; then
701 ewarn "Attempting to use ${MY_DATADIR_s}"
702 else
703 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
704 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
705 fi
706 fi
707 fi
708
709 local pwd1="a"
710 local pwd2="b"
711 local maxtry=15
712
713 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
714 MYSQL_ROOT_PASSWORD="$(mysql-v2_getoptval 'client mysql' password)"
715 fi
716 MYSQL_TMPDIR="$(mysql-v2_getoptval mysqld tmpdir)"
717 # These are dir+prefix
718 MYSQL_RELAY_LOG="$(mysql-v2_getoptval mysqld relay-log)"
719 MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
720 MYSQL_LOG_BIN="$(mysql-v2_getoptval mysqld log-bin)"
721 MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
722
723 if [[ ! -d "${ROOT}"/$MYSQL_TMPDIR ]]; then
724 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
725 install -d -m 770 -o mysql -g mysql "${ROOT}"/$MYSQL_TMPDIR
726 fi
727 if [[ ! -d "${ROOT}"/$MYSQL_LOG_BIN ]]; then
728 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
729 install -d -m 770 -o mysql -g mysql "${ROOT}"/$MYSQL_LOG_BIN
730 fi
731 if [[ ! -d "${EROOT}"/$MYSQL_RELAY_LOG ]]; then
732 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
733 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_RELAY_LOG
734 fi
735
736 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
737 ewarn "You have already a MySQL database in place."
738 ewarn "(${ROOT}/${MY_DATADIR}/*)"
739 ewarn "Please rename or delete it if you wish to replace it."
740 die "MySQL database already exists!"
741 fi
742
743 # Bug #213475 - MySQL _will_ object strenously if your machine is named
744 # localhost. Also causes weird failures.
745 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
746
747 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
748
749 einfo "Please provide a password for the mysql 'root' user now, in the"
750 einfo "MYSQL_ROOT_PASSWORD env var or through the ${HOME}/.my.cnf file."
751 ewarn "Avoid [\"'\\_%] characters in the password"
752 read -rsp " >" pwd1 ; echo
753
754 einfo "Retype the password"
755 read -rsp " >" pwd2 ; echo
756
757 if [[ "x$pwd1" != "x$pwd2" ]] ; then
758 die "Passwords are not the same"
759 fi
760 MYSQL_ROOT_PASSWORD="${pwd1}"
761 unset pwd1 pwd2
762 fi
763
764 local options
765 local sqltmp="$(emktemp)"
766
767 # Fix bug 446200. Don't reference host my.cnf, needs to come first,
768 # see http://bugs.mysql.com/bug.php?id=31312
769 use prefix && options="${options} --defaults-file=${MY_SYSCONFDIR}/my.cnf"
770
771 local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
772 [[ -r "${help_tables}" ]] \
773 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
774 || touch "${TMPDIR}/fill_help_tables.sql"
775 help_tables="${TMPDIR}/fill_help_tables.sql"
776
777 # Figure out which options we need to disable to do the setup
778 helpfile="${TMPDIR}/mysqld-help"
779 ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
780 for opt in grant-tables host-cache name-resolve networking slave-start \
781 federated ssl log-bin relay-log slow-query-log external-locking \
782 ndbcluster log-slave-updates \
783 ; do
784 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
785 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
786 done
787 # But some options changed names
788 egrep -sq external-locking "${helpfile}" && \
789 options="${options/skip-locking/skip-external-locking}"
790
791 use prefix || options="${options} --user=mysql"
792
793 # MySQL 5.6+ needs InnoDB
794 if [[ ${PN} == "mysql" || ${PN} == "percona-server" ]] ; then
795 mysql_version_is_at_least "5.6" || options="${options} --loose-skip-innodb"
796 fi
797
798 einfo "Creating the mysql database and setting proper"
799 einfo "permissions on it ..."
800
801 # Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
802 PID_DIR="${EROOT}/var/run/mysqld"
803 if [[ ! -d "${PID_DIR}" ]]; then
804 mkdir -p "${PID_DIR}" || die "Could not create pid directory"
805 chown mysql:mysql "${PID_DIR}" || die "Could not set ownership on pid directory"
806 chmod 755 "${PID_DIR}" || die "Could not set permissions on pid directory"
807 fi
808
809 pushd "${TMPDIR}" &>/dev/null
810 #cmd="'${EROOT}/usr/share/mysql/scripts/mysql_install_db' '--basedir=${EPREFIX}/usr' ${options}"
811 cmd=${EROOT}usr/share/mysql/scripts/mysql_install_db
812 [[ -f ${cmd} ]] || cmd=${EROOT}usr/bin/mysql_install_db
813 cmd="'$cmd' '--basedir=${EPREFIX}/usr' ${options} '--datadir=${ROOT}/${MY_DATADIR}' '--tmpdir=${ROOT}/${MYSQL_TMPDIR}'"
814 einfo "Command: $cmd"
815 eval $cmd \
816 >"${TMPDIR}"/mysql_install_db.log 2>&1
817 if [ $? -ne 0 ]; then
818 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
819 die "Failed to run mysql_install_db. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
820 fi
821 popd &>/dev/null
822 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
823 || die "MySQL databases not installed"
824 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
825 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
826
827 # Filling timezones, see
828 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
829 "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
830
831 if [[ -r "${help_tables}" ]] ; then
832 cat "${help_tables}" >> "${sqltmp}"
833 fi
834
835 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
836 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
837 local mysqld="${EROOT}/usr/sbin/mysqld \
838 ${options} \
839 $(use prefix || echo --user=mysql) \
840 --log-warnings=0 \
841 --basedir=${EROOT}/usr \
842 --datadir=${ROOT}/${MY_DATADIR} \
843 --max_allowed_packet=8M \
844 --net_buffer_length=16K \
845 --default-storage-engine=MyISAM \
846 --socket=${socket} \
847 --pid-file=${pidfile}
848 --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
849 #einfo "About to start mysqld: ${mysqld}"
850 ebegin "Starting mysqld"
851 einfo "Command ${mysqld}"
852 ${mysqld} &
853 rc=$?
854 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
855 maxtry=$((${maxtry}-1))
856 echo -n "."
857 sleep 1
858 done
859 eend $rc
860
861 if ! [[ -S "${socket}" ]]; then
862 die "Completely failed to start up mysqld with: ${mysqld}"
863 fi
864
865 ebegin "Setting root password"
866 # Do this from memory, as we don't want clear text passwords in temp files
867 local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'"
868 "${EROOT}/usr/bin/mysql" \
869 --socket=${socket} \
870 -hlocalhost \
871 -e "${sql}"
872 eend $?
873
874 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..."
875 "${EROOT}/usr/bin/mysql" \
876 --socket=${socket} \
877 -hlocalhost \
878 -uroot \
879 --password="${MYSQL_ROOT_PASSWORD}" \
880 mysql < "${sqltmp}"
881 rc=$?
882 eend $?
883 [[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
884
885 # Stop the server and cleanup
886 einfo "Stopping the server ..."
887 kill $(< "${pidfile}" )
888 rm -f "${sqltmp}"
889 wait %1
890 einfo "Done"
891 }
892
893 # @FUNCTION: mysql-v2_pkg_postrm
894 # @DESCRIPTION:
895 # Remove mysql symlinks.
896 mysql-v2_pkg_postrm() {
897
898 : # mysql_lib_symlinks "${ED}"
899 }

  ViewVC Help
Powered by ViewVC 1.1.20