Gentoo Archives: gentoo-commits

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