Gentoo Archives: gentoo-commits

From: Thomas Deutschmann <whissi@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-db/mariadb/
Date: Wed, 14 Apr 2021 14:47:10
Message-Id: 1618411618.d0a5513049e8323a50d1798525e677056832e81b.whissi@gentoo
1 commit: d0a5513049e8323a50d1798525e677056832e81b
2 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
3 AuthorDate: Wed Apr 14 14:46:49 2021 +0000
4 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
5 CommitDate: Wed Apr 14 14:46:58 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d0a55130
7
8 dev-db/mariadb: update patch set
9
10 Bug: https://bugs.gentoo.org/782703
11 Bug: https://bugs.gentoo.org/782796
12 Package-Manager: Portage-3.0.18, Repoman-3.0.3
13 Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>
14
15 dev-db/mariadb/Manifest | 1 +
16 dev-db/mariadb/mariadb-10.5.9-r5.ebuild | 1294 +++++++++++++++++++++++++++++++
17 2 files changed, 1295 insertions(+)
18
19 diff --git a/dev-db/mariadb/Manifest b/dev-db/mariadb/Manifest
20 index 9d25dc1abc2..abe04121347 100644
21 --- a/dev-db/mariadb/Manifest
22 +++ b/dev-db/mariadb/Manifest
23 @@ -36,5 +36,6 @@ DIST mariadb-10.5.7.tar.gz 88214625 BLAKE2B 8ec53b4b98565d99a707899fd6adfdc5bffb
24 DIST mariadb-10.5.8-patches-01.tar.xz 6212 BLAKE2B 7e4358d02d25edc51f5926a75646052ccf07fe2b5cab1901a133b27764793c94ca2a6c4d4b90b5d911b25a6d86f1cb7d2659edbcdab52c445fd6959ea080275d SHA512 f7a5d948c6d7d97896538b7df0de60c8e7969dd15b4ff406e8955a282e69fb7f19fe91424afc332029ac2a36c52781617bbf1c5f6d57dd3bfc21d3ea20ff4c5a
25 DIST mariadb-10.5.8.tar.gz 88206163 BLAKE2B eaaddaf240102428a23602655920bdf543d25cf85e669b1b07bedba5119a5e0f4498e999db39031dcff168ac810ed0b28f5fa9ac995b3634b84b99b753b4636c SHA512 9801a68440a3502b49655e34dcbfd09734f4a4f1ba8621ed9b895e194cea461a8c69fb0ff66488d5defd3065b43f73e5083a60142e11cc7e4a442f86769b06e5
26 DIST mariadb-10.5.9-patches-04.tar.xz 6544 BLAKE2B 283e289fd4c8a701426db6a329bb6da06db82093cb40d103ddc878cdae15cebc66d3b99c5315d460f0db4bfa370ddb0e9e5cc017d01515085b7dc1a27f97bf48 SHA512 6de84664ddd4f1a022280336d7ee742dfadbbd2f3e5e23c3e68b1f9423cc45becf403dda9976cb366d7afafd412f112720c27b558147486dca781f1053010ede
27 +DIST mariadb-10.5.9-patches-05.tar.xz 17120 BLAKE2B a6ea7c3ba3718e9667510db9fdfcedb3fa4a6a2da89f1c49f9a419c84191af9bf6148815afa836e31f47d752cafdaefdd98b530c29c849fa86af4ff0be9732ea SHA512 e39393505d5c5d45b3352d15b9e10a02a1057d5eb381335953c5dfca312791976be9e0e3b2adb6536a2f5cc6f00f01b9379a17806a029a9b73eb674a2a1fb583
28 DIST mariadb-10.5.9.tar.gz 88639930 BLAKE2B 512c3fb0541bbeb19878979104f7858ce18ce67187507c8395798cfc9ffe92bd83e39bd47251419363600348a85716406286bd27b3c28662ea63e8ec761a4e01 SHA512 d23d5bf8510b3c36a6521fb3244cf323ef0f5d100ba379ed7b5bbc2acae1765a5b46c17bd929f0b27b28923eb1b5975314abdf7ffb96905cf7a93a5c8837294e
29 DIST mysql-extras-20190305-2052Z.tar.bz2 331304 BLAKE2B 1d2c35a961159fa5ce9ee6699fce943f5a5b5cf60b11c9bb4bcccee4943f4508a9eb6d01050c642353ac592ce1a6b421abf2a1bebc706c44c4c8a36aa698ec43 SHA512 ae63403320e010acbb92f8aec6da8ed4f267cef0bad37147d594076fd94571de7f98bfc2afbe94af5d716f58d57696fd958b1e13e20e87052f252ed4a188cd3c
30
31 diff --git a/dev-db/mariadb/mariadb-10.5.9-r5.ebuild b/dev-db/mariadb/mariadb-10.5.9-r5.ebuild
32 new file mode 100644
33 index 00000000000..fc387a3d97c
34 --- /dev/null
35 +++ b/dev-db/mariadb/mariadb-10.5.9-r5.ebuild
36 @@ -0,0 +1,1294 @@
37 +# Copyright 1999-2021 Gentoo Authors
38 +# Distributed under the terms of the GNU General Public License v2
39 +
40 +EAPI="7"
41 +SUBSLOT="18"
42 +
43 +JAVA_PKG_OPT_USE="jdbc"
44 +
45 +inherit eutils systemd flag-o-matic prefix toolchain-funcs \
46 + multiprocessing java-pkg-opt-2 cmake
47 +
48 +# Patch version
49 +PATCH_SET="https://dev.gentoo.org/~whissi/dist/${PN}/${PN}-10.5.9-patches-05.tar.xz"
50 +
51 +SRC_URI="https://downloads.mariadb.org/interstitial/${P}/source/${P}.tar.gz
52 + ${PATCH_SET}"
53 +
54 +HOMEPAGE="https://mariadb.org/"
55 +DESCRIPTION="An enhanced, drop-in replacement for MySQL"
56 +LICENSE="GPL-2 LGPL-2.1+"
57 +SLOT="10.5/${SUBSLOT:-0}"
58 +IUSE="+backup bindist columnstore cracklib debug extraengine galera innodb-lz4
59 + innodb-lzo innodb-snappy jdbc jemalloc kerberos latin1 libressl mroonga
60 + numa odbc oqgraph pam +perl profiling rocksdb selinux +server sphinx
61 + sst-rsync sst-mariabackup static systemd systemtap s3 tcmalloc
62 + test xml yassl"
63 +
64 +# Tests always fail when libressl is enabled due to hard-coded ciphers in the tests
65 +RESTRICT="!bindist? ( bindist ) libressl? ( test ) !test? ( test )"
66 +
67 +REQUIRED_USE="jdbc? ( extraengine server !static )
68 + ?? ( tcmalloc jemalloc )
69 + static? ( yassl !pam )"
70 +
71 +KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x64-solaris ~x86-solaris"
72 +
73 +# Shorten the path because the socket path length must be shorter than 107 chars
74 +# and we will run a mysql server during test phase
75 +S="${WORKDIR}/mysql"
76 +
77 +# Be warned, *DEPEND are version-dependant
78 +# These are used for both runtime and compiletime
79 +COMMON_DEPEND="
80 + >=dev-libs/libpcre2-10.34:=
81 + >=sys-apps/sed-4
82 + >=sys-apps/texinfo-4.7-r1
83 + sys-libs/ncurses:0=
84 + >=sys-libs/zlib-1.2.3:0=
85 + !bindist? (
86 + sys-libs/binutils-libs:0=
87 + >=sys-libs/readline-4.1:0=
88 + )
89 + jemalloc? ( dev-libs/jemalloc:0= )
90 + kerberos? ( virtual/krb5 )
91 + kernel_linux? (
92 + sys-process/procps:0=
93 + dev-libs/libaio:0=
94 + )
95 + server? (
96 + app-arch/bzip2
97 + app-arch/xz-utils
98 + backup? ( app-arch/libarchive:0= )
99 + columnstore? (
100 + app-arch/snappy
101 + dev-libs/boost:0=
102 + dev-libs/libxml2:2=
103 + )
104 + cracklib? ( sys-libs/cracklib:0= )
105 + extraengine? (
106 + odbc? ( dev-db/unixODBC:0= )
107 + xml? ( dev-libs/libxml2:2= )
108 + )
109 + innodb-lz4? ( app-arch/lz4 )
110 + innodb-lzo? ( dev-libs/lzo )
111 + innodb-snappy? ( app-arch/snappy )
112 + mroonga? ( app-text/groonga-normalizer-mysql >=app-text/groonga-7.0.4 )
113 + numa? ( sys-process/numactl )
114 + oqgraph? ( >=dev-libs/boost-1.40.0:0= dev-libs/judy:0= )
115 + pam? ( sys-libs/pam:0= )
116 + s3? ( net-misc/curl )
117 + systemd? ( sys-apps/systemd:= )
118 + )
119 + systemtap? ( >=dev-util/systemtap-1.3:0= )
120 + tcmalloc? ( dev-util/google-perftools:0= )
121 + yassl? ( net-libs/gnutls:0= )
122 + !yassl? (
123 + !libressl? ( >=dev-libs/openssl-1.0.0:0= )
124 + libressl? ( dev-libs/libressl:0= )
125 + )
126 +"
127 +BDEPEND="virtual/yacc
128 + || ( >=sys-devel/gcc-3.4.6 >=sys-devel/gcc-apple-4.0 )
129 +"
130 +DEPEND="${COMMON_DEPEND}
131 + server? (
132 + extraengine? ( jdbc? ( >=virtual/jdk-1.6 ) )
133 + test? ( acct-group/mysql acct-user/mysql )
134 + )
135 + static? ( sys-libs/ncurses[static-libs] )
136 +"
137 +RDEPEND="${COMMON_DEPEND}
138 + !dev-db/mysql !dev-db/mariadb-galera !dev-db/percona-server !dev-db/mysql-cluster
139 + !dev-db/mariadb:0
140 + !dev-db/mariadb:5.5
141 + !dev-db/mariadb:10.1
142 + !dev-db/mariadb:10.2
143 + !dev-db/mariadb:10.3
144 + !dev-db/mariadb:10.4
145 + !<virtual/mysql-5.6-r11
146 + !<virtual/libmysqlclient-18-r1
147 + selinux? ( sec-policy/selinux-mysql )
148 + server? (
149 + columnstore? ( dev-db/mariadb-connector-c )
150 + extraengine? ( jdbc? ( >=virtual/jre-1.6 ) )
151 + galera? (
152 + sys-apps/iproute2
153 + =sys-cluster/galera-26*
154 + sst-rsync? ( sys-process/lsof )
155 + sst-mariabackup? ( net-misc/socat[ssl] )
156 + )
157 + !prefix? ( dev-db/mysql-init-scripts acct-group/mysql acct-user/mysql )
158 + )
159 +"
160 +# For other stuff to bring us in
161 +# dev-perl/DBD-mysql is needed by some scripts installed by MySQL
162 +PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
163 +
164 +mysql_init_vars() {
165 + MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mariadb"}
166 + MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
167 + MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
168 + MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
169 +
170 + if [[ -z "${MY_DATADIR}" ]] ; then
171 + MY_DATADIR=""
172 + if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
173 + MY_DATADIR=$(my_print_defaults mysqld 2>/dev/null \
174 + | sed -ne '/datadir/s|^--datadir=||p' \
175 + | tail -n1)
176 + if [[ -z "${MY_DATADIR}" ]] ; then
177 + MY_DATADIR=$(grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
178 + | sed -e 's/.*=\s*//' \
179 + | tail -n1)
180 + fi
181 + fi
182 + if [[ -z "${MY_DATADIR}" ]] ; then
183 + MY_DATADIR="${MY_LOCALSTATEDIR}"
184 + einfo "Using default MY_DATADIR"
185 + fi
186 + elog "MySQL MY_DATADIR is ${MY_DATADIR}"
187 +
188 + if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
189 + if [[ -e "${MY_DATADIR}" ]] ; then
190 + # If you get this and you're wondering about it, see bug #207636
191 + elog "MySQL datadir found in ${MY_DATADIR}"
192 + elog "A new one will not be created."
193 + PREVIOUS_DATADIR="yes"
194 + else
195 + PREVIOUS_DATADIR="no"
196 + fi
197 + export PREVIOUS_DATADIR
198 + fi
199 + else
200 + if [[ ${EBUILD_PHASE} == "config" ]]; then
201 + local new_MY_DATADIR
202 + new_MY_DATADIR=$(my_print_defaults mysqld 2>/dev/null \
203 + | sed -ne '/datadir/s|^--datadir=||p' \
204 + | tail -n1)
205 +
206 + if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
207 + ewarn "MySQL MY_DATADIR has changed"
208 + ewarn "from ${MY_DATADIR}"
209 + ewarn "to ${new_MY_DATADIR}"
210 + MY_DATADIR="${new_MY_DATADIR}"
211 + fi
212 + fi
213 + fi
214 +
215 + export MY_SHAREDSTATEDIR MY_SYSCONFDIR
216 + export MY_LOCALSTATEDIR MY_LOGDIR
217 + export MY_DATADIR
218 +}
219 +
220 +pkg_setup() {
221 + if [[ ${MERGE_TYPE} != binary ]] ; then
222 + local GCC_MAJOR_SET=$(gcc-major-version)
223 + local GCC_MINOR_SET=$(gcc-minor-version)
224 +
225 + # Bug 565584. InnoDB now requires atomic functions introduced with gcc-4.7 on
226 + # non x86{,_64} arches
227 + if ! use amd64 && ! use x86 && [[ ${GCC_MAJOR_SET} -lt 4 || \
228 + ${GCC_MAJOR_SET} -eq 4 && ${GCC_MINOR_SET} -lt 7 ]] ; then
229 + eerror "${PN} needs to be built with gcc-4.7 or later."
230 + eerror "Please use gcc-config to switch to gcc-4.7 or later version."
231 + die
232 + fi
233 +
234 + if has test ${FEATURES} ; then
235 + # Bug #213475 - MySQL _will_ object strenuously if your machine is named
236 + # localhost. Also causes weird failures.
237 + [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
238 +
239 + if ! has userpriv ${FEATURES} ; then
240 + die "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
241 + fi
242 + fi
243 + fi
244 +
245 + java-pkg-opt-2_pkg_setup
246 +}
247 +
248 +src_unpack() {
249 + unpack ${A}
250 +
251 + mv -f "${WORKDIR}/${P/_rc/}" "${S}" || die
252 +}
253 +
254 +src_prepare() {
255 + eapply "${WORKDIR}"/mariadb-patches
256 +
257 + eapply_user
258 +
259 + _disable_plugin() {
260 + echo > "${S}/plugin/${1}/CMakeLists.txt" || die
261 + }
262 + _disable_engine() {
263 + echo > "${S}/storage/${1}/CMakeLists.txt" || die
264 + }
265 +
266 + if use jemalloc; then
267 + echo "TARGET_LINK_LIBRARIES(mariadbd jemalloc)" >> "${S}/sql/CMakeLists.txt"
268 + elif use tcmalloc; then
269 + echo "TARGET_LINK_LIBRARIES(mariadbd tcmalloc)" >> "${S}/sql/CMakeLists.txt"
270 + fi
271 +
272 + local plugin
273 + local server_plugins=( handler_socket auth_socket feedback metadata_lock_info
274 + locale_info qc_info server_audit sql_errlog auth_ed25519 )
275 + local test_plugins=( audit_null auth_examples daemon_example fulltext
276 + debug_key_management example_key_management versioning )
277 + if ! use server; then # These plugins are for the server
278 + for plugin in "${server_plugins[@]}" ; do
279 + _disable_plugin "${plugin}"
280 + done
281 + fi
282 +
283 + if ! use test; then # These plugins are only used during testing
284 + for plugin in "${test_plugins[@]}" ; do
285 + _disable_plugin "${plugin}"
286 + done
287 + _disable_engine test_sql_discovery
288 + echo > "${S}/plugin/auth_pam/testing/CMakeLists.txt" || die
289 + fi
290 +
291 + _disable_engine example
292 +
293 + if ! use oqgraph ; then # avoids extra library checks
294 + _disable_engine oqgraph
295 + fi
296 +
297 + if use mroonga ; then
298 + # Remove the bundled groonga
299 + # There is no CMake flag, it simply checks for existance
300 + rm -r "${S}"/storage/mroonga/vendor/groonga || die "could not remove packaged groonga"
301 + else
302 + _disable_engine mroonga
303 + fi
304 +
305 + # Fix static bindings in galera replication
306 + sed -i -e 's~add_library(wsrep_api_v26$~add_library(wsrep_api_v26 STATIC~' \
307 + "${S}"/wsrep-lib/wsrep-API/CMakeLists.txt || die
308 + sed -i -e 's~add_library(wsrep-lib$~add_library(wsrep-lib STATIC~' \
309 + "${S}"/wsrep-lib/src/CMakeLists.txt || die
310 +
311 + # Fix galera_recovery.sh script
312 + sed -i -e "s~@bindir@/my_print_defaults~${EPREFIX}/usr/libexec/mariadb/my_print_defaults~" \
313 + scripts/galera_recovery.sh || die
314 +
315 + sed -i -e 's~ \$basedir/lib/\*/mariadb19/plugin~~' \
316 + "${S}"/scripts/mysql_install_db.sh || die
317 +
318 + cmake_src_prepare
319 + java-pkg-opt-2_src_prepare
320 +}
321 +
322 +src_configure() {
323 + # bug 508724 mariadb cannot use ld.gold
324 + tc-ld-disable-gold
325 + # Bug #114895, bug #110149
326 + filter-flags "-O" "-O[01]"
327 +
328 + # It fails on alpha without this
329 + use alpha && append-ldflags "-Wl,--no-relax"
330 +
331 + append-cxxflags -felide-constructors
332 +
333 + # bug #283926, with GCC4.4, this is required to get correct behavior.
334 + append-flags -fno-strict-aliasing
335 +
336 + CMAKE_BUILD_TYPE="RelWithDebInfo"
337 +
338 + # debug hack wrt #497532
339 + mycmakeargs=(
340 + -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
341 + -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
342 + -DMYSQL_DATADIR="${EPREFIX}/var/lib/mysql"
343 + -DSYSCONFDIR="${EPREFIX}/etc/mysql"
344 + -DINSTALL_BINDIR=bin
345 + -DINSTALL_DOCDIR=share/doc/${PF}
346 + -DINSTALL_DOCREADMEDIR=share/doc/${PF}
347 + -DINSTALL_INCLUDEDIR=include/mysql
348 + -DINSTALL_INFODIR=share/info
349 + -DINSTALL_LIBDIR=$(get_libdir)
350 + -DINSTALL_MANDIR=share/man
351 + -DINSTALL_MYSQLSHAREDIR=share/mariadb
352 + -DINSTALL_PLUGINDIR=$(get_libdir)/mariadb/plugin
353 + -DINSTALL_SCRIPTDIR=bin
354 + -DINSTALL_MYSQLDATADIR="${EPREFIX}/var/lib/mysql"
355 + -DINSTALL_SBINDIR=sbin
356 + -DINSTALL_SUPPORTFILESDIR="${EPREFIX}/usr/share/mariadb"
357 + -DWITH_COMMENT="Gentoo Linux ${PF}"
358 + -DWITH_UNIT_TESTS=$(usex test ON OFF)
359 + -DWITH_LIBEDIT=0
360 + -DWITH_ZLIB=system
361 + -DWITHOUT_LIBWRAP=1
362 + -DENABLED_LOCAL_INFILE=1
363 + -DMYSQL_UNIX_ADDR="${EPREFIX}/var/run/mysqld/mysqld.sock"
364 + -DINSTALL_UNIX_ADDRDIR="${EPREFIX}/var/run/mysqld/mysqld.sock"
365 + -DWITH_DEFAULT_COMPILER_OPTIONS=0
366 + -DWITH_DEFAULT_FEATURE_SET=0
367 + -DINSTALL_SYSTEMD_UNITDIR="$(systemd_get_systemunitdir)"
368 + # The build forces this to be defined when cross-compiling. We pass it
369 + # all the time for simplicity and to make sure it is actually correct.
370 + -DSTACK_DIRECTION=$(tc-stack-grows-down && echo -1 || echo 1)
371 + -DPKG_CONFIG_EXECUTABLE="${EPREFIX}/usr/bin/$(tc-getPKG_CONFIG)"
372 + -DPLUGIN_AUTH_GSSAPI=$(usex kerberos DYNAMIC NO)
373 + -DAUTH_GSSAPI_PLUGIN_TYPE=$(usex kerberos DYNAMIC OFF)
374 + -DCONC_WITH_EXTERNAL_ZLIB=YES
375 + -DWITH_EXTERNAL_ZLIB=YES
376 + -DSUFFIX_INSTALL_DIR=""
377 + -DWITH_UNITTEST=OFF
378 + -DWITHOUT_CLIENTLIBS=YES
379 + -DCLIENT_PLUGIN_DIALOG=OFF
380 + -DCLIENT_PLUGIN_AUTH_GSSAPI_CLIENT=OFF
381 + -DCLIENT_PLUGIN_CLIENT_ED25519=OFF
382 + -DCLIENT_PLUGIN_MYSQL_CLEAR_PASSWORD=STATIC
383 + -DCLIENT_PLUGIN_CACHING_SHA2_PASSWORD=OFF
384 + )
385 + if use test ; then
386 + mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mariadb/mysql-test )
387 + else
388 + mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
389 + fi
390 +
391 + if ! use yassl ; then
392 + mycmakeargs+=( -DWITH_SSL=system -DCLIENT_PLUGIN_SHA256_PASSWORD=STATIC )
393 + else
394 + mycmakeargs+=( -DWITH_SSL=bundled )
395 + fi
396 +
397 + # bfd.h is only used starting with 10.1 and can be controlled by NOT_FOR_DISTRIBUTION
398 + mycmakeargs+=(
399 + -DWITH_READLINE=$(usex bindist 1 0)
400 + -DNOT_FOR_DISTRIBUTION=$(usex bindist 0 1)
401 + -DENABLE_DTRACE=$(usex systemtap)
402 + )
403 +
404 + if use server ; then
405 +
406 + # Federated{,X} must be treated special otherwise they will not be built as plugins
407 + if ! use extraengine ; then
408 + mycmakeargs+=(
409 + -DPLUGIN_FEDERATED=NO
410 + -DPLUGIN_FEDERATEDX=NO
411 + )
412 + fi
413 +
414 + mycmakeargs+=(
415 + -DWITH_PCRE=system
416 + -DPLUGIN_OQGRAPH=$(usex oqgraph DYNAMIC NO)
417 + -DPLUGIN_SPHINX=$(usex sphinx YES NO)
418 + -DPLUGIN_AUTH_PAM=$(usex pam YES NO)
419 + -DPLUGIN_CRACKLIB_PASSWORD_CHECK=$(usex cracklib YES NO)
420 + -DPLUGIN_CASSANDRA=NO
421 + -DPLUGIN_SEQUENCE=$(usex extraengine YES NO)
422 + -DPLUGIN_SPIDER=$(usex extraengine YES NO)
423 + -DPLUGIN_S3=$(usex s3 YES NO)
424 + -DPLUGIN_COLUMNSTORE=$(usex columnstore YES NO)
425 + -DPLUGIN_CONNECT=$(usex extraengine YES NO)
426 + -DCONNECT_WITH_MYSQL=1
427 + -DCONNECT_WITH_LIBXML2=$(usex xml)
428 + -DCONNECT_WITH_ODBC=$(usex odbc)
429 + -DCONNECT_WITH_JDBC=$(usex jdbc)
430 + # Build failure and autodep wrt bug 639144
431 + -DCONNECT_WITH_MONGO=OFF
432 + -DWITH_WSREP=$(usex galera)
433 + -DWITH_INNODB_LZ4=$(usex innodb-lz4 ON OFF)
434 + -DWITH_INNODB_LZO=$(usex innodb-lzo ON OFF)
435 + -DWITH_INNODB_SNAPPY=$(usex innodb-snappy ON OFF)
436 + -DPLUGIN_MROONGA=$(usex mroonga DYNAMIC NO)
437 + -DPLUGIN_AUTH_GSSAPI=$(usex kerberos DYNAMIC NO)
438 + -DWITH_MARIABACKUP=$(usex backup ON OFF)
439 + -DWITH_LIBARCHIVE=$(usex backup ON OFF)
440 + -DINSTALL_SQLBENCHDIR=""
441 + -DPLUGIN_ROCKSDB=$(usex rocksdb DYNAMIC NO)
442 + # systemd is only linked to for server notification
443 + -DWITH_SYSTEMD=$(usex systemd yes no)
444 + -DWITH_NUMA=$(usex numa ON OFF)
445 + )
446 +
447 + if use test ; then
448 + # This is needed for the new client lib which tests a real, open server
449 + mycmakeargs+=( -DSKIP_TESTS=ON )
450 + fi
451 +
452 + if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]]; then
453 + ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
454 + ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
455 + ewarn "You MUST file bugs without these variables set."
456 +
457 + mycmakeargs+=(
458 + -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
459 + -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
460 + )
461 +
462 + elif ! use latin1 ; then
463 + mycmakeargs+=(
464 + -DDEFAULT_CHARSET=utf8
465 + -DDEFAULT_COLLATION=utf8_general_ci
466 + )
467 + else
468 + mycmakeargs+=(
469 + -DDEFAULT_CHARSET=latin1
470 + -DDEFAULT_COLLATION=latin1_swedish_ci
471 + )
472 + fi
473 + mycmakeargs+=(
474 + -DEXTRA_CHARSETS=all
475 + -DMYSQL_USER=mysql
476 + -DDISABLE_SHARED=$(usex static YES NO)
477 + -DWITH_DEBUG=$(usex debug)
478 + -DWITH_EMBEDDED_SERVER=OFF
479 + -DWITH_PROFILING=$(usex profiling)
480 + )
481 +
482 + if use static; then
483 + mycmakeargs+=( -DWITH_PIC=1 )
484 + fi
485 +
486 + if use jemalloc || use tcmalloc ; then
487 + mycmakeargs+=( -DWITH_SAFEMALLOC=OFF )
488 + fi
489 +
490 + # Storage engines
491 + mycmakeargs+=(
492 + -DWITH_ARCHIVE_STORAGE_ENGINE=1
493 + -DWITH_BLACKHOLE_STORAGE_ENGINE=1
494 + -DWITH_CSV_STORAGE_ENGINE=1
495 + -DWITH_HEAP_STORAGE_ENGINE=1
496 + -DWITH_INNOBASE_STORAGE_ENGINE=1
497 + -DWITH_MYISAMMRG_STORAGE_ENGINE=1
498 + -DWITH_MYISAM_STORAGE_ENGINE=1
499 + -DWITH_PARTITION_STORAGE_ENGINE=1
500 + )
501 +
502 + else
503 + mycmakeargs+=(
504 + -DWITHOUT_SERVER=1
505 + -DWITH_EMBEDDED_SERVER=OFF
506 + -DEXTRA_CHARSETS=none
507 + -DINSTALL_SQLBENCHDIR=
508 + -DWITH_SYSTEMD=no
509 + )
510 + fi
511 +
512 + cmake_src_configure
513 +}
514 +
515 +src_compile() {
516 + cmake_src_compile
517 +}
518 +
519 +# Official test instructions:
520 +# USE='extraengine perl server' \
521 +# FEATURES='test userpriv' \
522 +# ebuild mariadb-X.X.XX.ebuild \
523 +# digest clean package
524 +src_test() {
525 + _disable_test() {
526 + local rawtestname bug reason
527 + rawtestname="${1}" ; shift
528 + bug="${1}" ; shift
529 + reason="${@}"
530 + ewarn "test '${rawtestname}' disabled: '${reason}' (BUG#${bug})"
531 + echo "${rawtestname} : BUG#${bug} ${reason}" >> "${T}/disabled.def"
532 + }
533 +
534 + local TESTDIR="${BUILD_DIR}/mysql-test"
535 + local retstatus_unit
536 + local retstatus_tests
537 +
538 + if ! use server ; then
539 + einfo "Skipping server tests due to minimal build."
540 + return 0
541 + fi
542 +
543 + einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
544 +
545 + # Run CTest (test-units)
546 + cmake_src_test
547 + retstatus_unit=$?
548 +
549 + # Ensure that parallel runs don't die
550 + export MTR_BUILD_THREAD="$((${RANDOM} % 100))"
551 +
552 + if [[ -z "${MTR_PARALLEL}" ]] ; then
553 + local -x MTR_PARALLEL=$(makeopts_jobs)
554 +
555 + if [[ ${MTR_PARALLEL} -gt 4 ]] ; then
556 + # Running multiple tests in parallel usually require higher ulimit
557 + # and fs.aio-max-nr setting. In addition, tests like main.multi_update
558 + # are known to hit timeout when system is busy.
559 + # To avoid test failure we will limit MTR_PARALLEL to 4 instead of
560 + # using "auto".
561 + local info_msg="Parallel MySQL test suite jobs limited to 4 (MAKEOPTS=${MTR_PARALLEL})"
562 + info_msg+=" to avoid test failures. Set MTR_PARALLEL if you know what you are doing!"
563 + einfo "${info_msg}"
564 + unset info_msg
565 + MTR_PARALLEL=4
566 + fi
567 + else
568 + einfo "MTR_PARALLEL is set to '${MTR_PARALLEL}'"
569 + fi
570 +
571 + # Try to increase file limits to increase test coverage
572 + if ! ulimit -n 16500 1>/dev/null 2>&1 ; then
573 + # Upper limit comes from parts.partition_* tests
574 + ewarn "For maximum test coverage please raise open file limit to 16500 (ulimit -n 16500) before calling the package manager."
575 +
576 + if ! ulimit -n 4162 1>/dev/null 2>&1 ; then
577 + # Medium limit comes from '[Warning] Buffered warning: Could not increase number of max_open_files to more than 3000 (request: 4162)'
578 + ewarn "For medium test coverage please raise open file limit to 4162 (ulimit -n 4162) before calling the package manager."
579 +
580 + if ! ulimit -n 3000 1>/dev/null 2>&1 ; then
581 + ewarn "For minimum test coverage please raise open file limit to 3000 (ulimit -n 3000) before calling the package manager."
582 + else
583 + einfo "Will run test suite with open file limit set to 3000 (minimum test coverage)."
584 + fi
585 + else
586 + einfo "Will run test suite with open file limit set to 4162 (medium test coverage)."
587 + fi
588 + else
589 + einfo "Will run test suite with open file limit set to 16500 (best test coverage)."
590 + fi
591 +
592 + # create directories because mysqladmin might run out of order
593 + mkdir -p "${T}"/var-tests{,/log} || die
594 +
595 + cp "${S}"/mysql-test/unstable-tests "${T}/disabled.def" || die
596 +
597 + local -a disabled_tests
598 + disabled_tests+=( "compat/oracle.plugin;0;Needs example plugin which Gentoo disables" )
599 + disabled_tests+=( "main.explain_non_select;0;Sporadically failing test" )
600 + disabled_tests+=( "main.func_time;0;Dependent on time test was written" )
601 + disabled_tests+=( "main.plugin_auth;0;Needs client libraries built" )
602 + disabled_tests+=( "main.stat_tables;0;Sporadically failing test" )
603 + disabled_tests+=( "main.stat_tables_innodb;0;Sporadically failing test" )
604 + disabled_tests+=( "main.upgrade_MDEV-19650;25096;Known to be broken" )
605 + disabled_tests+=( "mariabackup.*;0;Broken test suite" )
606 + disabled_tests+=( "perfschema.nesting;23458;Known to be broken" )
607 + disabled_tests+=( "plugins.auth_ed25519;0;Needs client libraries built" )
608 + disabled_tests+=( "plugins.cracklib_password_check;0;False positive due to varying policies" )
609 + disabled_tests+=( "plugins.two_password_validations;0;False positive due to varying policies" )
610 + disabled_tests+=( "roles.acl_statistics;0;False positive due to a user count mismatch caused by previous test" )
611 +
612 + if ! use latin1 ; then
613 + disabled_tests+=( "funcs_1.is_columns_mysql;0;Requires USE=latin1" )
614 + disabled_tests+=( "main.information_schema;0;Requires USE=latin1" )
615 + disabled_tests+=( "main.sp2;24177;Requires USE=latin1" )
616 + disabled_tests+=( "main.system_mysql_db;0;Requires USE=latin1" )
617 + disabled_tests+=( "main.upgrade_MDEV-19650;24178;Requires USE=latin1" )
618 + fi
619 +
620 + local test_infos_str test_infos_arr
621 + for test_infos_str in "${disabled_tests[@]}" ; do
622 + IFS=';' read -r -a test_infos_arr <<< "${test_infos_str}"
623 +
624 + if [[ ${#test_infos_arr[@]} != 3 ]] ; then
625 + die "Invalid test data set, not matching format: ${test_infos_str}"
626 + fi
627 +
628 + _disable_test "${test_infos_arr[0]}" "${test_infos_arr[1]}" "${test_infos_arr[2]}"
629 + done
630 + unset test_infos_str test_infos_arr
631 +
632 + # run mysql-test tests
633 + pushd "${TESTDIR}" &>/dev/null || die
634 + perl mysql-test-run.pl --force --vardir="${T}/var-tests" --reorder --skip-test-list="${T}/disabled.def"
635 + retstatus_tests=$?
636 +
637 + popd &>/dev/null || die
638 +
639 + # Cleanup is important for these testcases.
640 + pkill -9 -f "${S}/ndb" 2>/dev/null
641 + pkill -9 -f "${S}/sql" 2>/dev/null
642 +
643 + local failures=""
644 + [[ $retstatus_unit -eq 0 ]] || failures="${failures} test-unit"
645 + [[ $retstatus_tests -eq 0 ]] || failures="${failures} tests"
646 +
647 + [[ -z "$failures" ]] || die "Test failures: $failures"
648 + einfo "Tests successfully completed"
649 +}
650 +
651 +src_install() {
652 + cmake_src_install
653 +
654 + # Remove an unnecessary, private config header which will never match between ABIs and is not meant to be used
655 + if [[ -f "${ED}/usr/include/mysql/server/private/config.h" ]] ; then
656 + rm "${ED}/usr/include/mysql/server/private/config.h" || die
657 + fi
658 +
659 + # Make sure the vars are correctly initialized
660 + mysql_init_vars
661 +
662 + # Convenience links
663 + einfo "Making Convenience links for mysqlcheck multi-call binary"
664 + dosym "mysqlcheck" "/usr/bin/mysqlanalyze"
665 + dosym "mysqlcheck" "/usr/bin/mysqlrepair"
666 + dosym "mysqlcheck" "/usr/bin/mysqloptimize"
667 +
668 + # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
669 + if [[ -d "${ED}/usr/data" ]] ; then
670 + rm -Rf "${ED}/usr/data" || die
671 + fi
672 +
673 + # Unless they explicitly specific USE=test, then do not install the
674 + # testsuite. It DOES have a use to be installed, esp. when you want to do a
675 + # validation of your database configuration after tuning it.
676 + if ! use test ; then
677 + rm -rf "${D}/${MY_SHAREDSTATEDIR}/mysql-test"
678 + fi
679 +
680 + # Configuration stuff
681 + einfo "Building default configuration ..."
682 + insinto "${MY_SYSCONFDIR#${EPREFIX}}"
683 + [[ -f "${S}/scripts/mysqlaccess.conf" ]] && doins "${S}"/scripts/mysqlaccess.conf
684 + cp "${FILESDIR}/my.cnf-10.2" "${TMPDIR}/my.cnf" || die
685 + eprefixify "${TMPDIR}/my.cnf"
686 + doins "${TMPDIR}/my.cnf"
687 + insinto "${MY_SYSCONFDIR#${EPREFIX}}/mariadb.d"
688 + cp "${FILESDIR}/my.cnf.distro-client" "${TMPDIR}/50-distro-client.cnf" || die
689 + eprefixify "${TMPDIR}/50-distro-client.cnf"
690 + doins "${TMPDIR}/50-distro-client.cnf"
691 +
692 + if use server ; then
693 + mycnf_src="my.cnf.distro-server"
694 + sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
695 + "${FILESDIR}/${mycnf_src}" \
696 + > "${TMPDIR}/my.cnf.ok" || die
697 + if use prefix ; then
698 + sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' \
699 + "${TMPDIR}/my.cnf.ok" || die
700 + fi
701 + if use latin1 ; then
702 + sed -i \
703 + -e "/character-set/s|utf8|latin1|g" \
704 + "${TMPDIR}/my.cnf.ok" || die
705 + fi
706 + eprefixify "${TMPDIR}/my.cnf.ok"
707 + newins "${TMPDIR}/my.cnf.ok" 50-distro-server.cnf
708 +
709 + einfo "Including support files and sample configurations"
710 + docinto "support-files"
711 + local script
712 + for script in \
713 + "${S}"/support-files/magic
714 + do
715 + [[ -f "$script" ]] && dodoc "${script}"
716 + done
717 +
718 + docinto "scripts"
719 + for script in "${S}"/scripts/mysql* ; do
720 + [[ ( -f "$script" ) && ( "${script%.sh}" == "${script}" ) ]] && dodoc "${script}"
721 + done
722 + # Manually install supporting files that conflict with other packages
723 + # but are needed for galera and initial installation
724 + exeinto /usr/libexec/mariadb
725 + doexe "${BUILD_DIR}/extra/my_print_defaults" "${BUILD_DIR}/extra/perror"
726 +
727 + if use pam ; then
728 + keepdir /usr/$(get_libdir)/mariadb/plugin/auth_pam_tool_dir
729 + fi
730 + fi
731 +
732 + # Remove bundled mytop in favor of dev-db/mytop
733 + local mytop_file
734 + for mytop_file in \
735 + "${ED}/usr/bin/mytop" \
736 + "${ED}/usr/share/man/man1/mytop.1" \
737 + ; do
738 + if [[ -e "${mytop_file}" ]] ; then
739 + rm -v "${mytop_file}" || die
740 + fi
741 + done
742 +
743 + # Fix a dangling symlink when galera is not built
744 + if [[ -L "${ED}/usr/bin/wsrep_sst_rsync_wan" ]] && ! use galera ; then
745 + rm "${ED}/usr/bin/wsrep_sst_rsync_wan" || die
746 + fi
747 +
748 + # Remove broken SST scripts that are incompatible
749 + local scriptremove
750 + for scriptremove in wsrep_sst_xtrabackup wsrep_sst_xtrabackup-v2 ; do
751 + if [[ -e "${ED}/usr/bin/${scriptremove}" ]] ; then
752 + rm "${ED}/usr/bin/${scriptremove}" || die
753 + fi
754 + done
755 +}
756 +
757 +pkg_preinst() {
758 + java-pkg-opt-2_pkg_preinst
759 +}
760 +
761 +pkg_postinst() {
762 + # Make sure the vars are correctly initialized
763 + mysql_init_vars
764 +
765 + # Create log directory securely if it does not exist
766 + [[ -d "${ROOT}/${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}/${MY_LOGDIR}"
767 +
768 + if use server ; then
769 + if use pam; then
770 + einfo
771 + elog "This install includes the PAM authentication plugin."
772 + elog "To activate and configure the PAM plugin, please read:"
773 + elog "https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/"
774 + einfo
775 + chown mysql:mysql "${EROOT}/usr/$(get_libdir)/mariadb/plugin/auth_pam_tool_dir" || die
776 + fi
777 +
778 + if [[ -z "${REPLACING_VERSIONS}" ]] ; then
779 + einfo
780 + elog "You might want to run:"
781 + elog "\"emerge --config =${CATEGORY}/${PF}\""
782 + elog "if this is a new install."
783 + elog
784 + elog "If you are switching server implentations, you should run the"
785 + elog "mysql_upgrade tool."
786 + einfo
787 + else
788 + einfo
789 + elog "If you are upgrading major versions, you should run the"
790 + elog "mysql_upgrade tool."
791 + einfo
792 + fi
793 +
794 + if use galera ; then
795 + einfo
796 + elog "Be sure to edit the my.cnf file to activate your cluster settings."
797 + elog "This should be done after running \"emerge --config =${CATEGORY}/${PF}\""
798 + elog "The first time the cluster is activated, you should add"
799 + elog "--wsrep-new-cluster to the options in /etc/conf.d/mysql for one node."
800 + elog "This option should then be removed for subsequent starts."
801 + einfo
802 + if [[ -n "${REPLACING_VERSIONS}" ]] ; then
803 + local rver
804 + for rver in ${REPLACING_VERSIONS} ; do
805 + if ver_test "${rver}" -lt "10.4.0" ; then
806 + ewarn "Upgrading galera from a previous version requires admin restart of the entire cluster."
807 + ewarn "Please refer to https://mariadb.com/kb/en/library/changes-improvements-in-mariadb-104/#galera-4"
808 + ewarn "for more information"
809 + fi
810 + done
811 + fi
812 + fi
813 + fi
814 +
815 + # Note about configuration change
816 + einfo
817 + elog "This version of mariadb reorganizes the configuration from a single my.cnf"
818 + elog "to several files in /etc/mysql/${PN}.d."
819 + elog "Please backup any changes you made to /etc/mysql/my.cnf"
820 + elog "and add them as a new file under /etc/mysql/${PN}.d with a .cnf extension."
821 + elog "You may have as many files as needed and they are read alphabetically."
822 + elog "Be sure the options have the appropriate section headers, i.e. [mysqld]."
823 + einfo
824 +}
825 +
826 +pkg_config() {
827 + _getoptval() {
828 + local section="${1}"
829 + local flag="--${2}="
830 + local extra_options="${3}"
831 + local cmd=(
832 + "${my_print_defaults_binary}"
833 + "${extra_options}"
834 + "${section}"
835 + )
836 + local results=( $(eval "${cmd[@]}" 2>/dev/null | sed -n "/^${flag}/s,${flag},,gp") )
837 +
838 + if [[ ${#results[@]} -gt 0 ]] ; then
839 + # When option is set multiple times only return last value
840 + echo "${results[-1]}"
841 + fi
842 + }
843 +
844 + _mktemp_dry() {
845 + # emktemp has no --dry-run option
846 + local template="${1}"
847 +
848 + if [[ -z "${template}" ]] ; then
849 + if [[ -z "${T}" ]] ; then
850 + template="/tmp/XXXXXXX"
851 + else
852 + template="${T}/XXXXXXX"
853 + fi
854 + fi
855 +
856 + local template_wo_X=${template//X/}
857 + local n_X
858 + let n_X=${#template}-${#template_wo_X}
859 + if [[ ${n_X} -lt 3 ]] ; then
860 + echo "${FUNCNAME[0]}: too few X's in template ‘${template}’" >&2
861 + return
862 + fi
863 +
864 + local attempts=0
865 + local character tmpfile
866 + while [[ true ]] ; do
867 + let attempts=attempts+1
868 +
869 + new_file=
870 + while read -n1 character ; do
871 + if [[ "${character}" == "X" ]] ; then
872 + tmpfile+="${RANDOM:0:1}"
873 + else
874 + tmpfile+="${character}"
875 + fi
876 + done < <(echo -n "${template}")
877 +
878 + if [[ ! -f "${tmpfile}" ]]
879 + then
880 + echo "${tmpfile}"
881 + return
882 + fi
883 +
884 + if [[ ${attempts} -ge 100 ]] ; then
885 + echo "${FUNCNAME[0]}: Cannot create temporary file after 100 attempts." >&2
886 + return
887 + fi
888 + done
889 + }
890 +
891 + local mysql_binary="${EROOT}/usr/bin/mysql"
892 + if [[ ! -x "${mysql_binary}" ]] ; then
893 + die "'${mysql_binary}' not found! Please re-install ${CATEGORY}/${PN}!"
894 + fi
895 +
896 + local mysqld_binary="${EROOT}/usr/sbin/mysqld"
897 + if [[ ! -x "${mysqld_binary}" ]] ; then
898 + die "'${mysqld_binary}' not found! Please re-install ${CATEGORY}/${PN}!"
899 + fi
900 +
901 + local mysql_install_db_binary="${EROOT}/usr/bin/mysql_install_db"
902 + if [[ ! -x "${mysql_install_db_binary}" ]] ; then
903 + die "'${mysql_install_db_binary}' not found! Please re-install ${CATEGORY}/${PN}!"
904 + fi
905 +
906 + local my_print_defaults_binary="${EROOT}/usr/bin/my_print_defaults"
907 + if [[ ! -x "${my_print_defaults_binary}" ]] ; then
908 + die "'${my_print_defaults_binary}' not found! Please re-install dev-db/mysql-connector-c!"
909 + fi
910 +
911 + if [[ -z "${MYSQL_USER}" ]] ; then
912 + MYSQL_USER=mysql
913 + if use prefix ; then
914 + MYSQL_USER=$(id -u -n 2>/dev/null)
915 + if [[ -z "${MYSQL_USER}" ]] ; then
916 + die "Failed to determine current username!"
917 + fi
918 + fi
919 + fi
920 +
921 + if [[ -z "${MYSQL_GROUP}" ]] ; then
922 + MYSQL_GROUP=mysql
923 + if use prefix ; then
924 + MYSQL_GROUP=$(id -g -n 2>/dev/null)
925 + if [[ -z "${MYSQL_GROUP}" ]] ; then
926 + die "Failed to determine current user groupname!"
927 + fi
928 + fi
929 + fi
930 +
931 + # my_print_defaults needs to read stuff in $HOME/.my.cnf
932 + local -x HOME="${EROOT}/root"
933 +
934 + # Make sure the vars are correctly initialized
935 + mysql_init_vars
936 +
937 + # Read currently set data directory
938 + MY_DATADIR="$(_getoptval mysqld datadir "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
939 +
940 + # Bug #213475 - MySQL _will_ object strenously if your machine is named
941 + # localhost. Also causes weird failures.
942 + [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
943 +
944 + if [[ -z "${MY_DATADIR}" ]] ; then
945 + die "Sorry, unable to find MY_DATADIR!"
946 + elif [[ -d "${MY_DATADIR}/mysql" ]] ; then
947 + ewarn "Looks like your data directory '${MY_DATADIR}' is already initialized!"
948 + ewarn "Please rename or delete its content if you wish to initialize a new data directory."
949 + die "${PN} data directory at '${MY_DATADIR}' looks already initialized!"
950 + fi
951 +
952 + MYSQL_TMPDIR="$(_getoptval mysqld tmpdir "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
953 + MYSQL_TMPDIR=${MYSQL_TMPDIR%/}
954 + # These are dir+prefix
955 + MYSQL_LOG_BIN="$(_getoptval mysqld log-bin "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
956 + MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
957 + MYSQL_RELAY_LOG="$(_getoptval mysqld relay-log "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
958 + MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
959 +
960 + # Create missing directories.
961 + # Always check if mysql user can write to directory even if we just
962 + # created directory because a parent directory might be not
963 + # accessible for that user.
964 + PID_DIR="${EROOT}/run/mysqld"
965 + if [[ ! -d "${PID_DIR}" ]] ; then
966 + einfo "Creating ${PN} PID directory '${PID_DIR}' ..."
967 + install -d -m 755 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${PID_DIR}" \
968 + || die "Failed to create PID directory '${PID_DIR}'!"
969 + fi
970 +
971 + local _pid_dir_testfile="$(_mktemp_dry "${PID_DIR}/.pkg_config-access-test.XXXXXXXXX")"
972 + [[ -z "${_pid_dir_testfile}" ]] \
973 + && die "_mktemp_dry() for '${PID_DIR}/.pkg_config-access-test.XXXXXXXXX' failed!"
974 +
975 + if use prefix ; then
976 + touch "${_pid_dir_testfile}" &>/dev/null
977 + else
978 + su -s /bin/sh -c "touch ${_pid_dir_testfile}" ${MYSQL_USER} &>/dev/null
979 + fi
980 +
981 + if [[ $? -ne 0 ]] ; then
982 + die "${MYSQL_USER} user cannot write into PID dir '${PID_DIR}'!"
983 + else
984 + rm "${_pid_dir_testfile}" || die
985 + unset _pid_dir_testfile
986 + fi
987 +
988 + if [[ ! -d "${MY_DATADIR}" ]] ; then
989 + einfo "Creating ${PN} data directory '${MY_DATADIR}' ..."
990 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MY_DATADIR}" \
991 + || die "Failed to create ${PN} data directory '${MY_DATADIR}'!"
992 + fi
993 +
994 + local _my_datadir_testfile="$(_mktemp_dry "${MY_DATADIR}/.pkg_config-access-test.XXXXXXXXX")"
995 + [[ -z "${_my_datadir_testfile}" ]] \
996 + && die "_mktemp_dry() for '${MY_DATADIR}/.pkg_config-access-test.XXXXXXXXX' failed!"
997 +
998 + if use prefix ; then
999 + touch "${_my_datadir_testfile}" &>/dev/null
1000 + else
1001 + su -s /bin/sh -c "touch ${_my_datadir_testfile}" ${MYSQL_USER} &>/dev/null
1002 + fi
1003 +
1004 + if [[ $? -ne 0 ]] ; then
1005 + die "${MYSQL_USER} user cannot write into data directory '${MY_DATADIR}'!"
1006 + else
1007 + rm "${_my_datadir_testfile}" || die
1008 + unset _my_datadir_testfile
1009 + fi
1010 +
1011 + if [[ -n "${MYSQL_TMPDIR}" && ! -d "${MYSQL_TMPDIR}" ]] ; then
1012 + einfo "Creating ${PN} tmpdir '${MYSQL_TMPDIR}' ..."
1013 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MYSQL_TMPDIR}" \
1014 + || die "Failed to create ${PN} tmpdir '${MYSQL_TMPDIR}'!"
1015 + fi
1016 +
1017 + if [[ -z "${MYSQL_TMPDIR}" ]] ; then
1018 + MYSQL_TMPDIR="$(_mktemp_dry "${EROOT}/tmp/mysqld-tmp.XXXXXXXXX")"
1019 + [[ -z "${MYSQL_TMPDIR}" ]] \
1020 + && die "_mktemp_dry() for '${MYSQL_TMPDIR}' failed!"
1021 +
1022 + mkdir "${MYSQL_TMPDIR}" || die
1023 + chown ${MYSQL_USER} "${MYSQL_TMPDIR}" || die
1024 + fi
1025 +
1026 + # Now we need to test MYSQL_TMPDIR...
1027 + local _my_tmpdir_testfile="$(_mktemp_dry "${MYSQL_TMPDIR}/.pkg_config-access-test.XXXXXXXXX")"
1028 + [[ -z "${_my_tmpdir_testfile}" ]] \
1029 + && die "_mktemp_dry() for '${MYSQL_TMPDIR}/.pkg_config-access-test.XXXXXXXXX' failed!"
1030 +
1031 + if use prefix ; then
1032 + touch "${_my_tmpdir_testfile}" &>/dev/null
1033 + else
1034 + su -s /bin/sh -c "touch ${_my_tmpdir_testfile}" ${MYSQL_USER} &>/dev/null
1035 + fi
1036 +
1037 + if [[ $? -ne 0 ]] ; then
1038 + die "${MYSQL_USER} user cannot write into tmpdir '${MYSQL_TMPDIR}'!"
1039 + else
1040 + rm "${_my_tmpdir_testfile}" || die
1041 + unset _my_tmpdir_testfile
1042 + fi
1043 +
1044 + if [[ -n "${MYSQL_LOG_BIN}" && ! -d "${MYSQL_LOG_BIN}" ]] ; then
1045 + einfo "Creating ${PN} log-bin directory '${MYSQL_LOG_BIN}' ..."
1046 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MYSQL_LOG_BIN}" \
1047 + || die "Failed to create ${PN} log-bin directory '${MYSQL_LOG_BIN}'"
1048 + fi
1049 +
1050 + if [[ -n "${MYSQL_LOG_BIN}" ]] ; then
1051 + local _my_logbin_testfile="$(_mktemp_dry "${MYSQL_LOG_BIN}/.pkg_config-access-test.XXXXXXXXX")"
1052 + [[ -z "${_my_logbin_testfile}" ]] \
1053 + && die "_mktemp_dry() for '${MYSQL_LOG_BIN}/.pkg_config-access-test.XXXXXXXXX' failed!"
1054 +
1055 + if use prefix ; then
1056 + touch "${_my_logbin_testfile}" &>/dev/null
1057 + else
1058 + su -s /bin/sh -c "touch ${_my_logbin_testfile}" ${MYSQL_USER} &>/dev/null
1059 + fi
1060 +
1061 + if [[ $? -ne 0 ]] ; then
1062 + die "${MYSQL_USER} user cannot write into log-bin directory '${MYSQL_LOG_BIN}'!"
1063 + else
1064 + rm "${_my_logbin_testfile}" || die
1065 + unset _my_logbin_testfile
1066 + fi
1067 + fi
1068 +
1069 + if [[ -n "${MYSQL_RELAY_LOG}" && ! -d "${MYSQL_RELAY_LOG}" ]] ; then
1070 + einfo "Creating ${PN} relay-log directory '${MYSQL_RELAY_LOG}' ..."
1071 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MYSQL_RELAY_LOG}" \
1072 + || die "Failed to create ${PN} relay-log directory '${MYSQL_RELAY_LOG}'!"
1073 + fi
1074 +
1075 + if [[ -n "${MYSQL_RELAY_LOG}" ]] ; then
1076 + local _my_relaylog_testfile="$(_mktemp_dry "${MYSQL_RELAY_LOG}/.pkg_config-access-test.XXXXXXXXX")"
1077 + [[ -z "${_my_relaylog_testfile}" ]] \
1078 + && die "_mktemp_dry() for '${MYSQL_RELAY_LOG}/.pkg_config-access-test.XXXXXXXXX' failed!"
1079 +
1080 + if use prefix ; then
1081 + touch "${_my_relaylog_testfile}" &>/dev/null
1082 + else
1083 + su -s /bin/sh -c "touch ${_my_relaylog_testfile}" ${MYSQL_USER} &>/dev/null
1084 + fi
1085 +
1086 + if [[ $? -ne 0 ]] ; then
1087 + die "${MYSQL_USER} user cannot write into relay-log directory '${MYSQL_RELAY_LOG}'!"
1088 + else
1089 + rm "${_my_relaylog_testfile}" || die
1090 + unset _my_relaylog_testfile
1091 + fi
1092 + fi
1093 +
1094 + local SETUP_TMPDIR=$(mktemp -d "/tmp/${PN}-config.XXXXXXXXX" 2>/dev/null)
1095 + [[ -z "${SETUP_TMPDIR}" ]] && die "Failed to create setup tmpdir"
1096 +
1097 + # Limit access
1098 + chmod 0770 "${SETUP_TMPDIR}" || die
1099 + chown ${MYSQL_USER} "${SETUP_TMPDIR}" || die
1100 +
1101 + local mysql_install_log="${SETUP_TMPDIR}/install_db.log"
1102 + local mysqld_logfile="${SETUP_TMPDIR}/mysqld.log"
1103 +
1104 + echo ""
1105 + einfo "Detected settings:"
1106 + einfo "=================="
1107 + einfo "MySQL User:\t\t\t\t${MYSQL_USER}"
1108 + einfo "MySQL Group:\t\t\t\t${MYSQL_GROUP}"
1109 + einfo "MySQL DATA directory:\t\t${MY_DATADIR}"
1110 + einfo "MySQL TMP directory:\t\t\t${MYSQL_TMPDIR}"
1111 +
1112 + if [[ -n "${MYSQL_LOG_BIN}" ]] ; then
1113 + einfo "MySQL Binary Log File location:\t${MYSQL_LOG_BIN}"
1114 + fi
1115 +
1116 + if [[ -n "${MYSQL_RELAY_LOG}" ]] ; then
1117 + einfo "MySQL Relay Log File location:\t${MYSQL_RELAY_LOG}"
1118 + fi
1119 +
1120 + einfo "PID DIR:\t\t\t\t${PID_DIR}"
1121 + einfo "Install db log:\t\t\t${mysql_install_log}"
1122 + einfo "Install server log:\t\t\t${mysqld_logfile}"
1123 +
1124 + echo
1125 +
1126 + if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
1127 + local tmp_mysqld_password_source=
1128 +
1129 + for tmp_mysqld_password_source in mysql client ; do
1130 + einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
1131 + MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password)"
1132 + if [[ -n "${MYSQL_ROOT_PASSWORD}" ]] ; then
1133 + if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]] ; then
1134 + ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
1135 + MYSQL_ROOT_PASSWORD=
1136 + continue
1137 + fi
1138 +
1139 + einfo "Found password in '${tmp_mysqld_password_source}' section!"
1140 + break
1141 + fi
1142 + done
1143 +
1144 + # Sometimes --show is required to display passwords in some implementations of my_print_defaults
1145 + if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]] ; then
1146 + MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password --show)"
1147 + fi
1148 +
1149 + unset tmp_mysqld_password_source
1150 + fi
1151 +
1152 + if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
1153 + local pwd1="a"
1154 + local pwd2="b"
1155 +
1156 + echo
1157 + einfo "No password for mysql 'root' user was specified via environment"
1158 + einfo "variable MYSQL_ROOT_PASSWORD and no password was found in config"
1159 + einfo "file like '${HOME}/.my.cnf'."
1160 + einfo "To continue please provide a password for the mysql 'root' user"
1161 + einfo "now on console:"
1162 + ewarn "NOTE: Please avoid [\"'\\_%] characters in the password!"
1163 + read -rsp " >" pwd1 ; echo
1164 +
1165 + einfo "Retype the password"
1166 + read -rsp " >" pwd2 ; echo
1167 +
1168 + if [[ "x${pwd1}" != "x${pwd2}" ]] ; then
1169 + die "Passwords are not the same!"
1170 + fi
1171 +
1172 + MYSQL_ROOT_PASSWORD="${pwd1}"
1173 + unset pwd1 pwd2
1174 +
1175 + echo
1176 + fi
1177 +
1178 + local -a mysqld_options
1179 +
1180 + # Fix bug 446200. Don't reference host my.cnf, needs to come first,
1181 + # see http://bugs.mysql.com/bug.php?id=31312
1182 + use prefix && mysqld_options+=( "--defaults-file='${MY_SYSCONFDIR}/my.cnf'" )
1183 +
1184 + # Figure out which options we need to disable to do the setup
1185 + local helpfile="${TMPDIR}/mysqld-help"
1186 + "${EROOT}/usr/sbin/mysqld" --verbose --help >"${helpfile}" 2>/dev/null
1187 +
1188 + local opt optexp optfull
1189 + for opt in host-cache name-resolve networking slave-start \
1190 + federated ssl log-bin relay-log slow-query-log external-locking \
1191 + log-slave-updates \
1192 + ; do
1193 + optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
1194 + egrep -sq -- "${optexp}" "${helpfile}" && mysqld_options+=( "${optfull}" )
1195 + done
1196 +
1197 + # Prepare timezones, see
1198 + # https://dev.mysql.com/doc/mysql/en/time-zone-support.html
1199 + local tz_sql="${SETUP_TMPDIR}/tz.sql"
1200 +
1201 + echo "USE mysql;" >"${tz_sql}"
1202 + "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" >> "${tz_sql}" 2>/dev/null
1203 + if [[ $? -ne 0 ]] ; then
1204 + die "mysql_tzinfo_to_sql failed!"
1205 + fi
1206 +
1207 + local cmd=(
1208 + "${mysql_install_db_binary}"
1209 + "${mysqld_options[@]}"
1210 + "--init-file='${tz_sql}'"
1211 + "--basedir='${EROOT}/usr'"
1212 + "--datadir='${MY_DATADIR}'"
1213 + "--tmpdir='${MYSQL_TMPDIR}'"
1214 + "--log-error='${mysql_install_log}'"
1215 + "--rpm"
1216 + "--cross-bootstrap"
1217 + "--skip-test-db"
1218 + "--user=${MYSQL_USER}"
1219 + )
1220 +
1221 + einfo "Initializing ${PN} data directory: ${cmd[@]}"
1222 + eval "${cmd[@]}" >>"${mysql_install_log}" 2>&1
1223 +
1224 + if [[ $? -ne 0 || ! -f "${MY_DATADIR}/mysql/user.frm" ]] ; then
1225 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysql_install_log}" 1>&2
1226 + die "Failed to initialize ${PN} data directory. Please review '${mysql_install_log}'!"
1227 + fi
1228 +
1229 + local x=${RANDOM}
1230 + local socket="${PID_DIR}/mysqld.${x}.sock"
1231 + [[ -f "${socket}" ]] && die "Randomness failed; Socket ${socket} already exists!"
1232 + local pidfile="${PID_DIR}/mysqld.${x}.pid"
1233 + [[ -f "${pidfile}" ]] && die "Randomness failed; Pidfile ${pidfile} already exists!"
1234 + unset x
1235 +
1236 + cmd=(
1237 + "${mysqld_binary}"
1238 + "${mysqld_options[@]}"
1239 + "--basedir='${EROOT}/usr'"
1240 + "--datadir='${MY_DATADIR}'"
1241 + "--tmpdir='${MYSQL_TMPDIR}'"
1242 + --max_allowed_packet=8M
1243 + --net_buffer_length=16K
1244 + "--socket='${socket}'"
1245 + "--pid-file='${pidfile}'"
1246 + "--log-error='${mysqld_logfile}'"
1247 + "--user=${MYSQL_USER}"
1248 + )
1249 +
1250 + einfo "Starting mysqld to finalize initialization: ${cmd[@]}"
1251 + eval "${cmd[@]}" >>"${mysqld_logfile}" 2>&1 &
1252 +
1253 + echo -n "Waiting for mysqld to accept connections "
1254 + local maxtry=15
1255 + while [[ ! -S "${socket}" && "${maxtry}" -gt 1 ]] ; do
1256 + maxtry=$((${maxtry}-1))
1257 + echo -n "."
1258 + sleep 1
1259 + done
1260 +
1261 + if [[ -S "${socket}" ]] ; then
1262 + # Even with a socket we don't know if mysqld will abort
1263 + # start due to an error so just wait a little bit more...
1264 + maxtry=5
1265 + while [[ -S "${socket}" && "${maxtry}" -gt 1 ]] ; do
1266 + maxtry=$((${maxtry}-1))
1267 + echo -n "."
1268 + sleep 1
1269 + done
1270 + fi
1271 +
1272 + echo
1273 +
1274 + if [[ ! -S "${socket}" ]] ; then
1275 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysqld_logfile}" 1>&2
1276 + die "mysqld was unable to start from initialized data directory. Please review '${mysqld_logfile}'!"
1277 + fi
1278 +
1279 + local mysql_logfile="${SETUP_TMPDIR}/set_root_pw.log"
1280 + touch "${mysql_logfile}" || die
1281 +
1282 + ebegin "Setting root password"
1283 + # Do this from memory, as we don't want clear text passwords in temp files
1284 + local sql="ALTER USER 'root'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}'"
1285 + cmd=(
1286 + "${mysql_binary}"
1287 + --no-defaults
1288 + "--socket='${socket}'"
1289 + -hlocalhost
1290 + "-e \"${sql}\""
1291 + )
1292 + eval "${cmd[@]}" >"${mysql_logfile}" 2>&1
1293 + local rc=$?
1294 + eend ${rc}
1295 +
1296 + if [[ ${rc} -ne 0 ]] ; then
1297 + # Poor man's solution which tries to avoid having password
1298 + # in log. NOTE: sed can fail if user didn't follow advice
1299 + # and included character which will require escaping...
1300 + sed -i -e "s/${MYSQL_ROOT_PASSWORD}/*****/" "${mysql_logfile}" 2>/dev/null
1301 +
1302 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysql_logfile}"
1303 + die "Failed to set ${PN} root password. Please review '${mysql_logfile}'!"
1304 + fi
1305 +
1306 + # Stop the server
1307 + if [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; then
1308 + echo -n "Stopping the server "
1309 + pkill -F "${pidfile}" &>/dev/null
1310 +
1311 + maxtry=10
1312 + while [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; do
1313 + maxtry=$((${maxtry}-1))
1314 + echo -n "."
1315 + sleep 1
1316 + done
1317 +
1318 + echo
1319 +
1320 + if [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; then
1321 + # We somehow failed to stop server.
1322 + # However, not a fatal error. Just warn the user.
1323 + ewarn "WARNING: mysqld[$(cat "${pidfile}")] is still running!"
1324 + fi
1325 + fi
1326 +
1327 + rm -r "${SETUP_TMPDIR}" || die
1328 +
1329 + einfo "${PN} data directory at '${MY_DATADIR}' successfully initialized!"
1330 +}