1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
5 MY_EXTRAS_VER="20190305-2052Z"
8 JAVA_PKG_OPT_USE="jdbc"
10 # Keeping eutils in EAPI=6 for emktemp in pkg_config
12 inherit eutils systemd flag-o-matic prefix toolchain-funcs java-pkg-opt-2 user cmake-utils multilib-build
14 SRC_URI="https://downloads.mariadb.org/interstitial/${P}/source/${P}.tar.gz "
16 # Gentoo patches to MySQL
17 if [[ "${MY_EXTRAS_VER}" != "live" && "${MY_EXTRAS_VER}" != "none" ]]; then
19 mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
20 https://gitweb.gentoo.org/proj/mysql-extras.git/snapshot/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
21 https://dev.gentoo.org/~grknight/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
22 https://dev.gentoo.org/~robbat2/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
23 https://dev.gentoo.org/~jmbsvicetto/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
26 HOMEPAGE="https://mariadb.org/"
27 DESCRIPTION="An enhanced, drop-in replacement for MySQL"
29 SLOT="0/${SUBSLOT:-0}"
30 IUSE="+backup bindist client-libs cracklib debug extraengine galera jdbc jemalloc kerberos
31 innodb-lz4 innodb-lzo innodb-snappy latin1 libressl mroonga numa odbc oqgraph pam
32 +perl profiling selinux +server sphinx sst-rsync sst-mariabackup sst-xtrabackup
33 systemd systemtap static static-libs tcmalloc test tokudb xml yassl"
35 # Tests always fail when libressl is enabled due to hard-coded ciphers in the tests
36 RESTRICT="!bindist? ( bindist ) libressl? ( test ) !test? ( test )"
38 REQUIRED_USE="jdbc? ( extraengine server !static )
39 server? ( tokudb? ( jemalloc !tcmalloc ) )
40 ?? ( tcmalloc jemalloc )
41 static? ( yassl !pam )"
43 KEYWORDS="~alpha amd64 arm ~arm64 ~hppa ia64 ~mips ~ppc ~ppc64 ~s390 ~sparc x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~x64-solaris ~x86-solaris"
45 # Shorten the path because the socket path length must be shorter than 107 chars
46 # and we will run a mysql server during test phase
49 if [[ "${MY_EXTRAS_VER}" == "live" ]] ; then
50 MY_PATCH_DIR="${WORKDIR%/}/mysql-extras"
52 EGIT_REPO_URI="git://anongit.gentoo.org/proj/mysql-extras.git"
53 EGIT_CHECKOUT_DIR="${WORKDIR%/}/mysql-extras"
54 EGIT_CLONE_TYPE=shallow
56 MY_PATCH_DIR="${WORKDIR%/}/mysql-extras-${MY_EXTRAS_VER}"
60 "${MY_PATCH_DIR}"/20006_all_cmake_elib-mariadb-10.1.27.patch
61 "${MY_PATCH_DIR}"/20009_all_mariadb_myodbc_symbol_fix-5.5.38.patch
62 "${MY_PATCH_DIR}"/20015_all_mariadb-pkgconfig-location.patch
63 "${MY_PATCH_DIR}"/20018_all_mariadb-10.1.16-without-clientlibs-tools.patch
64 "${MY_PATCH_DIR}"/20025_all_mariadb-10.1.26-gssapi-detect.patch
65 "${MY_PATCH_DIR}"/20029_all_mariadb-10.1.37-enable-numa.patch
66 "${MY_PATCH_DIR}"/20035_all_mariadb-10.1-atomic-detection.patch
69 # Be warned, *DEPEND are version-dependant
70 # These are used for both runtime and compiletime
77 >=sys-apps/texinfo-4.7-r1
78 jemalloc? ( dev-libs/jemalloc:0= )
79 tcmalloc? ( dev-util/google-perftools:0= )
80 systemtap? ( >=dev-util/systemtap-1.3:0= )
82 !libressl? ( dev-libs/openssl:0= !>=dev-libs/openssl-1.1 )
83 libressl? ( dev-libs/libressl:0= )
85 >=sys-libs/zlib-1.2.3:0=
88 sys-libs/binutils-libs:0=
89 >=sys-libs/readline-4.1:0=
92 backup? ( app-arch/libarchive:0= )
93 cracklib? ( sys-libs/cracklib:0= )
95 odbc? ( dev-db/unixODBC:0= )
96 xml? ( dev-libs/libxml2:2= )
97 sys-libs/zlib[minizip]
99 innodb-lz4? ( app-arch/lz4 )
100 innodb-lzo? ( dev-libs/lzo )
101 innodb-snappy? ( app-arch/snappy )
102 kerberos? ( virtual/krb5 )
103 mroonga? ( app-text/groonga-normalizer-mysql >=app-text/groonga-7.0.4 )
104 numa? ( sys-process/numactl )
105 oqgraph? ( >=dev-libs/boost-1.40.0:0= dev-libs/judy:0= )
106 pam? ( sys-libs/pam:0= )
107 systemd? ( sys-apps/systemd:= )
108 tokudb? ( app-arch/snappy )
110 !yassl? ( !libressl? ( !>=dev-libs/openssl-1.1.0 ) )
111 >=dev-libs/libpcre-8.41-r1:3=
112 !client-libs? ( dev-db/mysql-connector-c[${MULTILIB_USEDEP},static-libs?] )
115 static? ( sys-libs/ncurses[static-libs] )
116 || ( >=sys-devel/gcc-3.4.6 >=sys-devel/gcc-apple-4.0 )
117 server? ( extraengine? ( jdbc? ( >=virtual/jdk-1.6 ) ) )
119 RDEPEND="selinux? ( sec-policy/selinux-mysql )
120 client-libs? ( !dev-db/mariadb-connector-c[mysqlcompat] !dev-db/mysql-connector-c )
121 !dev-db/mysql !dev-db/mariadb-galera !dev-db/percona-server !dev-db/mysql-cluster
122 server? ( !prefix? ( dev-db/mysql-init-scripts ) )
126 =sys-cluster/galera-25*
127 sst-rsync? ( sys-process/lsof )
128 sst-mariabackup? ( net-misc/socat[ssl] )
129 sst-xtrabackup? ( net-misc/socat[ssl] )
131 perl? ( !dev-db/mytop
132 virtual/perl-Getopt-Long
134 virtual/perl-Term-ANSIColor
135 virtual/perl-Time-HiRes )
136 server? ( extraengine? ( jdbc? ( >=virtual/jre-1.6 ) ) )
138 # For other stuff to bring us in
139 # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
140 # percona-xtrabackup-bin causes a circular dependency if DBD-mysql is not already installed
141 PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )
142 server? ( galera? ( sst-xtrabackup? ( || ( >=dev-db/percona-xtrabackup-bin-2.2.4 dev-db/percona-xtrabackup ) ) ) )"
145 if [[ ${MERGE_TYPE} != binary ]] ; then
146 local GCC_MAJOR_SET=$(gcc-major-version)
147 local GCC_MINOR_SET=$(gcc-minor-version)
148 if use tokudb && [[ ${GCC_MAJOR_SET} -lt 4 || \
149 ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
150 eerror "${PN} with tokudb needs to be built with gcc-4.7 or later."
151 eerror "Please use gcc-config to switch to gcc-4.7 or later version."
154 # Bug 565584. InnoDB now requires atomic functions introduced with gcc-4.7 on
155 # non x86{,_64} arches
156 if ! use amd64 && ! use x86 && [[ ${GCC_MAJOR_SET} -lt 4 || \
157 ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
158 eerror "${PN} needs to be built with gcc-4.7 or later."
159 eerror "Please use gcc-config to switch to gcc-4.7 or later version."
163 java-pkg-opt-2_pkg_setup
164 if has test ${FEATURES} && \
165 use server && ! has userpriv ${FEATURES} ; then
166 eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
169 # This should come after all of the die statements
170 enewgroup mysql 60 || die "problem adding 'mysql' group"
171 enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
175 java-pkg-opt-2_pkg_preinst
179 # Make sure the vars are correctly initialized
182 # Create log directory securely if it does not exist
183 [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
188 elog "This install includes the PAM authentication plugin."
189 elog "To activate and configure the PAM plugin, please read:"
190 elog "https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/"
194 if [[ -z "${REPLACING_VERSIONS}" ]] ; then
196 elog "You might want to run:"
197 elog "\"emerge --config =${CATEGORY}/${PF}\""
198 elog "if this is a new install."
200 elog "If you are switching server implentations, you should run the"
201 elog "mysql_upgrade tool."
205 elog "If you are upgrading major versions, you should run the"
206 elog "mysql_upgrade tool."
211 elog "Be sure to edit the my.cnf file to activate your cluster settings."
212 elog "This should be done after running \"emerge --config =${CATEGORY}/${PF}\""
213 elog "The first time the cluster is activated, you should add"
214 elog "--wsrep-new-cluster to the options in /etc/conf.d/mysql for one node."
215 elog "This option should then be removed for subsequent starts."
223 [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR%/}/mysql-extras" git-r3_src_unpack
225 mv -f "${WORKDIR%/}/${PN%%-galera}-${PV}" "${S}" || die
230 echo > "${S%/}/storage/${1}/CMakeLists.txt" || die
234 echo > "${S%/}/plugin/${1}/CMakeLists.txt" || die
237 if use tcmalloc; then
238 echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S%/}/sql/CMakeLists.txt" || die
241 # Don't build bundled xz-utils for tokudb
242 echo > "${S%/}/storage/tokudb/PerconaFT/cmake_modules/TokuThirdParty.cmake" || die
243 sed -i -e 's/ build_lzma//' -e 's/ build_snappy//' "${S%/}/storage/tokudb/PerconaFT/ft/CMakeLists.txt" || die
244 sed -i -e 's/add_dependencies\(tokuportability_static_conv build_jemalloc\)//' "${S%/}/storage/tokudb/PerconaFT/portability/CMakeLists.txt" || die
247 local server_plugins=( handler_socket auth_socket feedback metadata_lock_info
248 locale_info qc_info server_audit semisync sql_errlog )
249 local test_plugins=( audit_null auth_examples daemon_example fulltext )
250 if ! use server; then # These plugins are for the server
251 for plugin in "${server_plugins[@]}" ; do
252 _disable_plugin "${plugin}"
256 if ! use test; then # These plugins are only used during testing
257 for plugin in "${test_plugins[@]}" ; do
258 _disable_plugin "${plugin}"
262 # Collides with mariadb-connector-c bug 655980
263 _disable_plugin auth_dialog
265 # Avoid useless library checks
266 use mroonga || _disable_engine mroonga
267 use oqgraph || _disable_engine oqgraph
268 _disable_engine example
270 # Don't clash with dev-db/mysql-connector-c
271 sed -i -e 's/ my_print_defaults.1//' \
273 "${S}"/man/CMakeLists.txt || die
275 cmake-utils_src_prepare
276 java-pkg-opt-2_src_prepare
280 # bug 508724 mariadb cannot use ld.gold
282 # Bug #114895, bug #110149
283 filter-flags "-O" "-O[01]"
285 append-cxxflags -felide-constructors
287 # bug #283926, with GCC4.4, this is required to get correct behavior.
288 append-flags -fno-strict-aliasing
290 CMAKE_BUILD_TYPE="RelWithDebInfo"
292 # debug hack wrt #497532
294 -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
295 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
296 -DDEFAULT_SYSCONFDIR="${EPREFIX}/etc/mysql"
298 -DINSTALL_DOCDIR=share/doc/${PF}
299 -DINSTALL_DOCREADMEDIR=share/doc/${PF}
300 -DINSTALL_INCLUDEDIR=include/mysql
301 -DINSTALL_INFODIR=share/info
302 -DINSTALL_LIBDIR=$(get_libdir)
303 -DINSTALL_MANDIR=share/man
304 -DINSTALL_MYSQLSHAREDIR=share/mariadb
305 -DINSTALL_MYSQLTESTDIR=$(usex test 'share/mariadb/mysql-test' '')
306 -DINSTALL_PLUGINDIR=$(get_libdir)/mariadb/plugin
307 -DINSTALL_SCRIPTDIR=share/mariadb/scripts
308 -DINSTALL_MYSQLDATADIR="${EPREFIX}/var/lib/mysql"
309 -DINSTALL_SBINDIR=sbin
310 -DINSTALL_SUPPORTFILESDIR="${EPREFIX}/usr/share/mariadb"
311 -DCOMPILATION_COMMENT="Gentoo Linux ${PF}"
312 -DWITH_UNIT_TESTS=$(usex test ON OFF)
314 -DENABLED_LOCAL_INFILE=1
315 -DMYSQL_UNIX_ADDR="${EPREFIX}/var/run/mysqld/mysqld.sock"
316 -DINSTALL_UNIX_ADDRDIR="${EPREFIX}/var/run/mysqld/mysqld.sock"
317 -DWITH_DEFAULT_COMPILER_OPTIONS=0
318 -DWITH_DEFAULT_FEATURE_SET=0
319 -DINSTALL_SYSTEMD_UNITDIR="$(systemd_get_systemunitdir)"
320 # The build forces this to be defined when cross-compiling. We pass it
321 # all the time for simplicity and to make sure it is actually correct.
322 -DSTACK_DIRECTION=$(tc-stack-grows-down && echo -1 || echo 1)
323 -DWITHOUT_CLIENTLIBS=YES
324 -DWITH_READLINE=$(usex bindist 1 0)
325 -DNOT_FOR_DISTRIBUTION=$(usex bindist 0 1)
326 -DENABLE_DTRACE=$(usex systemtap)
327 -DWITH_SSL=$(usex yassl bundled system)
328 -DPLUGIN_CLIENT_ED25519=NO
329 -DPLUGIN_AUTH_GSSAPI_CLIENT=NO
334 # Federated{,X} must be treated special otherwise they will not be built as plugins
335 if ! use extraengine ; then
337 -DPLUGIN_FEDERATED=NO
338 -DPLUGIN_FEDERATEDX=NO )
342 -DWITH_JEMALLOC=$(usex jemalloc system)
344 -DPLUGIN_OQGRAPH=$(usex oqgraph DYNAMIC NO)
345 -DPLUGIN_SPHINX=$(usex sphinx YES NO)
346 -DPLUGIN_TOKUDB=$(usex tokudb YES NO)
347 -DPLUGIN_AUTH_PAM=$(usex pam YES NO)
348 -DPLUGIN_CRACKLIB_PASSWORD_CHECK=$(usex cracklib YES NO)
349 -DPLUGIN_CASSANDRA=NO
350 -DPLUGIN_SEQUENCE=$(usex extraengine YES NO)
351 -DPLUGIN_SPIDER=$(usex extraengine YES NO)
352 -DPLUGIN_CONNECT=$(usex extraengine YES NO)
353 -DCONNECT_WITH_MYSQL=1
354 -DCONNECT_WITH_LIBXML2=$(usex xml)
355 -DCONNECT_WITH_ODBC=$(usex odbc)
356 -DCONNECT_WITH_JDBC=$(usex jdbc)
357 # Build failure and autodep wrt bug 639144
358 -DCONNECT_WITH_MONGO=OFF
359 -DWITH_WSREP=$(usex galera)
360 -DWITH_INNODB_LZ4=$(usex innodb-lz4 ON OFF)
361 -DWITH_INNODB_LZO=$(usex innodb-lzo ON OFF)
362 -DWITH_INNODB_SNAPPY=$(usex innodb-snappy ON OFF)
363 -DPLUGIN_MROONGA=$(usex mroonga DYNAMIC NO)
364 -DPLUGIN_AUTH_GSSAPI=$(usex kerberos DYNAMIC NO)
365 -DPLUGIN_AUTH_GSSAPI_CLIENT=NO
366 -DWITH_MARIABACKUP=$(usex backup ON OFF)
367 -DWITH_LIBARCHIVE=$(usex backup ON OFF)
368 -DWITH_SYSTEMD=$(usex systemd yes no)
369 -DWITH_NUMA=$(usex numa ON OFF)
370 -DINSTALL_SQLBENCHDIR=''
373 if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]]; then
374 ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
375 ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
376 ewarn "You MUST file bugs without these variables set."
379 -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
380 -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
383 elif ! use latin1 ; then
385 -DDEFAULT_CHARSET=utf8
386 -DDEFAULT_COLLATION=utf8_general_ci
390 -DDEFAULT_CHARSET=latin1
391 -DDEFAULT_COLLATION=latin1_swedish_ci
397 -DDISABLE_SHARED=$(usex static YES NO)
398 -DWITH_DEBUG=$(usex debug)
399 -DWITH_EMBEDDED_SERVER=OFF
400 -DENABLED_PROFILING=$(usex profiling)
404 mycmakeargs+=( -DWITH_PIC=1 )
407 if use jemalloc || use tcmalloc ; then
408 mycmakeargs+=( -DWITH_SAFEMALLOC=OFF )
413 -DWITH_ARCHIVE_STORAGE_ENGINE=1
414 -DWITH_BLACKHOLE_STORAGE_ENGINE=1
415 -DWITH_CSV_STORAGE_ENGINE=1
416 -DWITH_HEAP_STORAGE_ENGINE=1
417 -DWITH_INNOBASE_STORAGE_ENGINE=1
418 -DWITH_MYISAMMRG_STORAGE_ENGINE=1
419 -DWITH_MYISAM_STORAGE_ENGINE=1
420 -DWITH_PARTITION_STORAGE_ENGINE=1
426 -DWITH_EMBEDDED_SERVER=OFF
427 -DEXTRA_CHARSETS=none
428 -DINSTALL_SQLBENCHDIR=
433 cmake-utils_src_configure
437 cmake-utils_src_compile
441 cmake-utils_src_install
443 # Remove an unnecessary, private config header which will never match between ABIs and is not meant to be used
444 if [[ -f "${ED}/usr/include/mysql/server/private/config.h" ]] ; then
445 rm "${ED}/usr/include/mysql/server/private/config.h" || die
448 # Make sure the vars are correctly initialized
452 einfo "Making Convenience links for mysqlcheck multi-call binary"
453 dosym "mysqlcheck" "/usr/bin/mysqlanalyze"
454 dosym "mysqlcheck" "/usr/bin/mysqlrepair"
455 dosym "mysqlcheck" "/usr/bin/mysqloptimize"
457 # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
458 if [[ -d "${ED}/usr/data" ]] ; then
459 rm -Rf "${ED}/usr/data" || die
462 # Unless they explicitly specific USE=test, then do not install the
463 # testsuite. It DOES have a use to be installed, esp. when you want to do a
464 # validation of your database configuration after tuning it.
466 rm -rf "${D}/${MY_SHAREDSTATEDIR}/mysql-test"
469 # Configuration stuff
470 einfo "Building default configuration ..."
471 insinto "${MY_SYSCONFDIR#${EPREFIX}}"
472 [[ -f "${S}/scripts/mysqlaccess.conf" ]] && doins "${S}"/scripts/mysqlaccess.conf
473 local mycnf_src="my.cnf-5.6-r1"
474 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
475 "${FILESDIR}/${mycnf_src}" \
476 > "${TMPDIR}/my.cnf.ok" || die
477 use prefix && sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' "${TMPDIR}/my.cnf.ok"
480 -e "/character-set/s|utf8|latin1|g" \
481 "${TMPDIR}/my.cnf.ok" || die
483 eprefixify "${TMPDIR}/my.cnf.ok"
484 newins "${TMPDIR}/my.cnf.ok" my.cnf
487 einfo "Including support files and sample configurations"
488 docinto "support-files"
491 "${S}"/support-files/magic
493 [[ -f "$script" ]] && dodoc "${script}"
497 for script in "${S}"/scripts/mysql* ; do
498 [[ ( -f "$script" ) && ( "${script%.sh}" == "${script}" ) ]] && dodoc "${script}"
500 # Manually install supporting files that conflict with other packages
501 # but are needed for galera and initial installation
502 exeinto /usr/libexec/mariadb
503 doexe "${BUILD_DIR}/extra/my_print_defaults" "${BUILD_DIR}/extra/perror"
506 #Remove mytop if perl is not selected
507 [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
510 # Official test instructions:
511 # USE='extraengine perl server' \
512 # FEATURES='test userpriv -usersandbox' \
513 # ebuild mariadb-X.X.XX.ebuild \
514 # digest clean package
518 local rawtestname reason
519 rawtestname="${1}" ; shift
521 ewarn "test '${rawtestname}' disabled: '${reason}'"
522 echo ${rawtestname} : ${reason} >> "${T}/disabled.def"
525 local TESTDIR="${BUILD_DIR}/mysql-test"
527 local retstatus_tests
529 if ! use server ; then
530 einfo "Skipping server tests due to minimal build."
534 # Bug #213475 - MySQL _will_ object strenously if your machine is named
535 # localhost. Also causes weird failures.
536 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
538 if [[ $UID -eq 0 ]]; then
539 die "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
541 has usersandbox $FEATURES && ewarn "Some tests may fail with FEATURES=usersandbox"
543 einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
545 # Run CTest (test-units)
546 # cmake-utils_src_test
549 # Ensure that parallel runs don't die
550 export MTR_BUILD_THREAD="$((${RANDOM} % 100))"
551 # Enable parallel testing, auto will try to detect number of cores
552 # You may set this by hand.
553 # The default maximum is 8 unless MTR_MAX_PARALLEL is increased
554 export MTR_PARALLEL="${MTR_PARALLEL:-auto}"
556 # create directories because mysqladmin might run out of order
557 mkdir -p "${T}"/var-tests{,/log} || die
560 pushd "${TESTDIR}" > /dev/null || die
562 touch "${T}/disabled.def"
563 # These are failing in MariaDB 10.0 for now and are believed to be
566 # main.mysql_client_test, main.mysql_client_test_nonblock
567 # main.mysql_client_test_comp:
568 # segfaults at random under Portage only, suspect resource limits.
571 for t in plugins.cracklib_password_check plugins.two_password_validations ; do
572 _disable_test "$t" "False positive due to varying policies"
575 for t in main.mysql_client_test main.mysql_client_test_nonblock \
576 rpl.rpl_semi_sync_uninstall_plugin main.mysql \
577 main.mysql_client_test_comp rpl.rpl_extra_col_master_myisam ; do
578 _disable_test "$t" "False positives in Gentoo"
581 if ! use client-libs ; then
582 _disable_test main.plugin_auth "Needs client libraries built"
583 _disable_test plugins.auth_ed25519 "Needs client libraries built"
586 _disable_test main.gis_notembedded "Fails when latin1 USE is not set"
588 _disable_test sys_vars.sysvars_server_notembedded "Broken test" # bug #661700 required profiling always on
590 # run mysql-test tests
591 perl mysql-test-run.pl --force --vardir="${T}/var-tests" --reorder --skip-test=tokudb --skip-test-list="${T}/disabled.def"
594 popd > /dev/null || die
596 # Cleanup is important for these testcases.
597 pkill -9 -f "${S}/ndb" 2>/dev/null
598 pkill -9 -f "${S}/sql" 2>/dev/null
601 [[ $retstatus_unit -eq 0 ]] || failures="${failures} test-unit"
602 [[ $retstatus_tests -eq 0 ]] || failures="${failures} tests"
604 [[ -z "$failures" ]] || die "Test failures: $failures"
605 einfo "Tests successfully completed"
609 MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mariadb"}
610 MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
611 MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
612 MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
614 if [[ -z "${MY_DATADIR}" ]] ; then
616 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
617 MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
618 | sed -ne '/datadir/s|^--datadir=||p' \
620 if [[ -z "${MY_DATADIR}" ]] ; then
621 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
622 | sed -e 's/.*=\s*//' \
626 if [[ -z "${MY_DATADIR}" ]] ; then
627 MY_DATADIR="${MY_LOCALSTATEDIR}"
628 einfo "Using default MY_DATADIR"
630 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
632 if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
633 if [[ -e "${MY_DATADIR}" ]] ; then
634 # If you get this and you're wondering about it, see bug #207636
635 elog "MySQL datadir found in ${MY_DATADIR}"
636 elog "A new one will not be created."
637 PREVIOUS_DATADIR="yes"
639 PREVIOUS_DATADIR="no"
641 export PREVIOUS_DATADIR
644 if [[ ${EBUILD_PHASE} == "config" ]]; then
646 new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
647 | sed -ne '/datadir/s|^--datadir=||p' \
650 if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
651 ewarn "MySQL MY_DATADIR has changed"
652 ewarn "from ${MY_DATADIR}"
653 ewarn "to ${new_MY_DATADIR}"
654 MY_DATADIR="${new_MY_DATADIR}"
659 export MY_SHAREDSTATEDIR MY_SYSCONFDIR
660 export MY_LOCALSTATEDIR MY_LOGDIR
666 local mypd="${EROOT}"usr/libexec/mariadb/my_print_defaults
669 local extra_options="${3}"
670 "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
672 local old_MY_DATADIR="${MY_DATADIR}"
673 local old_HOME="${HOME}"
674 # my_print_defaults needs to read stuff in $HOME/.my.cnf
675 export HOME=${EPREFIX}/root
677 # Make sure the vars are correctly initialized
680 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
681 if [[ ! -x "${EROOT}/usr/sbin/mysqld" ]] ; then
682 die "Minimal builds do NOT include the MySQL server"
685 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
686 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
687 MY_DATADIR_s="${MY_DATADIR_s%%/}"
688 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
689 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
691 if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]]; then
692 if [[ -d "${MY_DATADIR_s}" ]]; then
693 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
694 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
696 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
697 mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
698 || die "Moving MY_DATADIR failed"
701 ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
702 if [[ -d "${MY_DATADIR_s}" ]]; then
703 ewarn "Attempting to use ${MY_DATADIR_s}"
705 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
706 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
715 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
716 local tmp_mysqld_password_source=
718 for tmp_mysqld_password_source in mysql client; do
719 einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
720 MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password)"
721 if [[ -n "${MYSQL_ROOT_PASSWORD}" ]]; then
722 if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]]; then
723 ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
728 einfo "Found password in '${tmp_mysqld_password_source}' section!"
733 # Sometimes --show is required to display passwords in some implementations of my_print_defaults
734 if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]]; then
735 MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password --show)"
738 unset tmp_mysqld_password_source
740 MYSQL_TMPDIR="$(_getoptval mysqld tmpdir | tail -n1)"
741 # These are dir+prefix
742 MYSQL_RELAY_LOG="$(_getoptval mysqld relay-log | tail -n1)"
743 MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
744 MYSQL_LOG_BIN="$(_getoptval mysqld log-bin | tail -n1)"
745 MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
747 if [[ ! -d "${ROOT}/$MYSQL_TMPDIR" ]]; then
748 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
749 install -d -m 770 -o mysql -g mysql "${EROOT}/$MYSQL_TMPDIR"
751 if [[ ! -d "${ROOT}/$MYSQL_LOG_BIN" ]]; then
752 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
753 install -d -m 770 -o mysql -g mysql "${EROOT}/$MYSQL_LOG_BIN"
755 if [[ ! -d "${EROOT}/$MYSQL_RELAY_LOG" ]]; then
756 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
757 install -d -m 770 -o mysql -g mysql "${EROOT}/$MYSQL_RELAY_LOG"
760 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
761 ewarn "You have already a MySQL database in place."
762 ewarn "(${ROOT}/${MY_DATADIR}/*)"
763 ewarn "Please rename or delete it if you wish to replace it."
764 die "MySQL database already exists!"
767 # Bug #213475 - MySQL _will_ object strenously if your machine is named
768 # localhost. Also causes weird failures.
769 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
771 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
773 einfo "Please provide a password for the mysql 'root' user now"
774 einfo "or through the ${HOME}/.my.cnf file."
775 ewarn "Avoid [\"'\\_%] characters in the password"
776 read -rsp " >" pwd1 ; echo
778 einfo "Retype the password"
779 read -rsp " >" pwd2 ; echo
781 if [[ "x$pwd1" != "x$pwd2" ]] ; then
782 die "Passwords are not the same"
784 MYSQL_ROOT_PASSWORD="${pwd1}"
789 local sqltmp="$(emktemp)"
791 # Fix bug 446200. Don't reference host my.cnf, needs to come first,
792 # see https://bugs.mysql.com/bug.php?id=31312
793 use prefix && options="${options} '--defaults-file=${MY_SYSCONFDIR}/my.cnf'"
795 # Figure out which options we need to disable to do the setup
796 local helpfile="${TMPDIR}/mysqld-help"
797 "${EROOT}/usr/sbin/mysqld" --verbose --help >"${helpfile}" 2>/dev/null
798 for opt in grant-tables host-cache name-resolve networking slave-start \
799 federated ssl log-bin relay-log slow-query-log external-locking \
802 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
803 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
806 einfo "Creating the mysql database and setting proper permissions on it ..."
808 # Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
809 PID_DIR="${EROOT}/var/run/mysqld"
810 if [[ ! -d "${PID_DIR}" ]]; then
811 install -d -m 755 -o mysql -g mysql "${PID_DIR}" || die "Could not create pid directory"
814 if [[ ! -d "${MY_DATADIR}" ]]; then
815 install -d -m 750 -o mysql -g mysql "${MY_DATADIR}" || die "Could not create data directory"
818 pushd "${TMPDIR}" &>/dev/null || die
820 # Filling timezones, see
821 # https://dev.mysql.com/doc/mysql/en/time-zone-support.html
822 "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
824 local cmd=( "${EROOT}usr/share/mariadb/scripts/mysql_install_db" )
825 [[ -f "${cmd}" ]] || cmd=( "${EROOT}usr/bin/mysql_install_db" )
826 cmd+=( "--basedir=${EPREFIX}/usr" ${options} "--datadir=${ROOT}/${MY_DATADIR}" "--tmpdir=${ROOT}/${MYSQL_TMPDIR}" )
827 einfo "Command: ${cmd[*]}"
828 su -s /bin/sh -c "${cmd[*]}" mysql \
829 >"${TMPDIR}"/mysql_install_db.log 2>&1
830 if [ $? -ne 0 ]; then
831 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
832 die "Failed to initialize mysqld. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
834 popd &>/dev/null || die
835 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
836 || die "MySQL databases not installed"
838 use prefix || options="${options} --user=mysql"
840 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
841 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
842 local mysqld="${EROOT}/usr/sbin/mysqld \
845 --basedir=${EROOT}/usr \
846 --datadir=${ROOT}/${MY_DATADIR} \
847 --max_allowed_packet=8M \
848 --net_buffer_length=16K \
850 --pid-file=${pidfile} \
851 --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
852 #einfo "About to start mysqld: ${mysqld}"
853 ebegin "Starting mysqld"
854 einfo "Command ${mysqld}"
857 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
858 maxtry=$((${maxtry}-1))
864 if ! [[ -S "${socket}" ]]; then
865 die "Completely failed to start up mysqld with: ${mysqld}"
868 ebegin "Setting root password"
869 # Do this from memory, as we don't want clear text passwords in temp files
870 local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'; FLUSH PRIVILEGES"
871 "${EROOT}/usr/bin/mysql" \
872 "--socket=${socket}" \
877 if [[ -n "${sqltmp}" ]] ; then
878 ebegin "Loading \"zoneinfo\", this step may require a few seconds"
879 "${EROOT}/usr/bin/mysql" \
880 "--socket=${socket}" \
883 --password="${MYSQL_ROOT_PASSWORD}" \
887 [[ $rc -ne 0 ]] && ewarn "Failed to load zoneinfo!"
890 # Stop the server and cleanup
891 einfo "Stopping the server ..."
892 kill $(< "${pidfile}" )