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