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