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