Gentoo Archives: gentoo-commits

From: Thomas Deutschmann <whissi@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-db/percona-server/
Date: Thu, 31 Oct 2019 01:41:41
Message-Id: 1572486082.1675444a6cc3f7b25911b91bf4f9076a08b5ec63.whissi@gentoo
1 commit: 1675444a6cc3f7b25911b91bf4f9076a08b5ec63
2 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
3 AuthorDate: Thu Oct 31 01:38:08 2019 +0000
4 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
5 CommitDate: Thu Oct 31 01:41:22 2019 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=1675444a
7
8 dev-db/percona-server: bump to v8.0.17-8
9
10 Closes: https://bugs.gentoo.org/697980
11 Closes: https://bugs.gentoo.org/679266
12 Package-Manager: Portage-2.3.78, Repoman-2.3.17
13 Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>
14
15 dev-db/percona-server/Manifest | 3 +
16 dev-db/percona-server/metadata.xml | 1 +
17 .../percona-server/percona-server-8.0.17.8.ebuild | 1128 ++++++++++++++++++++
18 3 files changed, 1132 insertions(+)
19
20 diff --git a/dev-db/percona-server/Manifest b/dev-db/percona-server/Manifest
21 index f766c8cf7fc..27e6e7919bb 100644
22 --- a/dev-db/percona-server/Manifest
23 +++ b/dev-db/percona-server/Manifest
24 @@ -1,4 +1,7 @@
25 DIST boost_1_59_0.tar.gz 83709983 BLAKE2B 8c6676fa05fa401a6ecb3b890d95aceb4421ec48dd0eab38ce8d170c618e177c82dc67a165938f6be1a01daab24ce41888f5442dbc19ad3dd41368a01a6f89e4 SHA512 05fdbe5637543defdbc630b921515425885593d16db14534ed7b9aa60925ade8fb598d50cb894aed6dae688e789047216daa1bf03fa1aeb6b531060d9dae52ae
26 +DIST boost_1_69_0.tar.bz2 95078138 BLAKE2B ccab52b911066ed41db6555fe13fbc142cd51250ad620665d3fcf25508e158b7b766f4f3654333b4a19517215ebe4a6ce14e64395b093b9604b3f0e570419841 SHA512 d0e9bb858c44880d56c0291afef6a1b011a62f659a2d8f58dcb6147ea0899f9157bd8db3097896618fee0116847ebeac78b6d0f0fec8a92c3469500828bbe552
27 DIST mysql-extras-20190822-1908Z.tar.bz2 338830 BLAKE2B bc197f8e541206548d8982814e82e028d699ba9c41aec8d5191bcc46581f7880ed2741dbe2206fde44a5e8d8d54bbcf40efbd0709b357636c4c8fdb2ccc3a7bb SHA512 be469e55f7e9966638600d6836a44258c74e5600240fafe2d79eaeebe7d1695b043678184b5d18ee9946f28154bc2529586a7f860b510180a30c82454ed575c8
28 +DIST mysql-extras-20191031-0134Z.tar.bz2 340718 BLAKE2B 8c228d6953aa888449a006ab1000ef3ecb1747fd055f58a8eaa5f5680b223fa840debbb7fce7404aa7ef4524ce71144a6a970483ad6536ff7521bd949f4dfa90 SHA512 6d61c4a70980759ac90fc3ac35a677a340d88f63260fb2c130ef70de0c05654895fe17b5f4915ca6d96f2406f215559182af61f7d88c1a4157e9bcbcc0f4d4e2
29 DIST percona-server-5.7.26-29.tar.gz 84327421 BLAKE2B beedb4b5025c337a63ae56644e47991e90c2c0e57c6d03f1562095f9470cef4b67c8df6c3774d88dfc6ed6dfb81f9dd4b62325db30bc26802651279921bd3a2d SHA512 c8100e69f7e29a5aa2de9dddbc1a3cba9836fe485b7f829a8db0a7e5ac1d1bdabfb1360dacad90665f4c9c78ac91226209c6c15158ef449e84519e36bb06f0a1
30 DIST percona-server-5.7.27-30.tar.gz 84672298 BLAKE2B 8431d231f602b704195868110e8eb73adb3db7c761906c15eff182e54634ef091a3ffa0d4f3498a93dbfbf65cd5cdd12102871abaaaa0f32378ba3068d083b2b SHA512 d62c66de3128df87dce52292ad1671e01fe2c923e668ef0faf9cb663c11c9cd0b976345aea1de6ea2bc458d0e1066b42c022849e422121d96cea082ed12c8f4b
31 +DIST percona-server-8.0.17-8.tar.gz 249562136 BLAKE2B d3bf20d9fee43f17b8aef3e403e74d9c5924a5a012d0c4208b22ffffce37f48867a2a1fb7992d7837f35492d5c5871901f3e0f68cde54793090bb2c089cee310 SHA512 c875492e8b67307aef439ae54b8ff6320464ac495a2d06029f1b33b2117e56bd1c2b3ce4ba7b406c1bd6604d0016d04a5c3f36643097cbf36425d60a44b6adc3
32
33 diff --git a/dev-db/percona-server/metadata.xml b/dev-db/percona-server/metadata.xml
34 index 01da26f9882..f282af30876 100644
35 --- a/dev-db/percona-server/metadata.xml
36 +++ b/dev-db/percona-server/metadata.xml
37 @@ -14,6 +14,7 @@
38 <flag name="numa">Enable NUMA support using <pkg>sys-process/numactl</pkg> (NUMA kernel support is also required)</flag>
39 <flag name="profiling">Add support for statement profiling (requires USE=community).</flag>
40 <flag name="rocksdb">Add support for RocksDB; a key/value, LSM database optimized for flash storage</flag>
41 + <flag name="router">Build the MySQL router program</flag>
42 <flag name="server">Build the server program</flag>
43 <flag name="systemtap">Build support for profiling and tracing using <pkg>dev-util/systemtap</pkg></flag>
44 <flag name="tokudb">Add support for TokuDB storage engine</flag>
45
46 diff --git a/dev-db/percona-server/percona-server-8.0.17.8.ebuild b/dev-db/percona-server/percona-server-8.0.17.8.ebuild
47 new file mode 100644
48 index 00000000000..4d7c2105e69
49 --- /dev/null
50 +++ b/dev-db/percona-server/percona-server-8.0.17.8.ebuild
51 @@ -0,0 +1,1128 @@
52 +# Copyright 1999-2019 Gentoo Authors
53 +# Distributed under the terms of the GNU General Public License v2
54 +
55 +EAPI="7"
56 +MY_EXTRAS_VER="20191031-0134Z"
57 +
58 +CMAKE_MAKEFILE_GENERATOR=emake
59 +
60 +inherit cmake-utils flag-o-matic linux-info \
61 + multiprocessing prefix toolchain-funcs check-reqs
62 +
63 +MY_BOOST_VERSION="1.69.0"
64 +MY_PV=$(ver_rs 3 '-')
65 +MY_PV="${MY_PV//_pre*}"
66 +MY_PN="Percona-Server"
67 +MY_P="${PN}-${MY_PV}"
68 +MY_MAJOR_PV=$(ver_cut 1-2)
69 +MY_RELEASE_NOTES_URI="https://www.percona.com/doc/percona-server/${MY_MAJOR_PV}/"
70 +
71 +S="${WORKDIR}/${PN}-${MY_PV}"
72 +
73 +SRC_URI="https://www.percona.com/downloads/${MY_PN}-${MY_MAJOR_PV}/${MY_PN}-${MY_PV}/source/tarball/${PN}-${MY_PV}.tar.gz
74 + https://dl.bintray.com/boostorg/release/${MY_BOOST_VERSION}/source/boost_$(ver_rs 1- _ ${MY_BOOST_VERSION}).tar.bz2
75 +"
76 +
77 +# Gentoo patches to MySQL
78 +if [[ "${MY_EXTRAS_VER}" != "live" && "${MY_EXTRAS_VER}" != "none" ]] ; then
79 + SRC_URI="${SRC_URI}
80 + mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
81 + https://gitweb.gentoo.org/proj/mysql-extras.git/snapshot/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
82 +fi
83 +
84 +HOMEPAGE="https://www.percona.com/software/mysql-database/percona-server"
85 +DESCRIPTION="Fully compatible, enhanced and open source drop-in replacement for MySQL"
86 +LICENSE="GPL-2"
87 +SLOT="0"
88 +IUSE="cjk cracklib debug jemalloc latin1 libressl numa +perl profiling
89 + rocksdb router selinux +server tcmalloc test tokudb tokudb-backup-plugin"
90 +
91 +# Tests always fail when libressl is enabled due to hard-coded ciphers in the tests
92 +RESTRICT="libressl? ( test )"
93 +
94 +REQUIRED_USE="?? ( tcmalloc jemalloc )"
95 +
96 +KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~x64-macos ~x86-macos ~x64-solaris ~x86-solaris"
97 +
98 +# Shorten the path because the socket path length must be shorter than 107 chars
99 +# and we will run a mysql server during test phase
100 +S="${WORKDIR}/mysql"
101 +
102 +if [[ "${MY_EXTRAS_VER}" == "live" ]] ; then
103 + inherit git-r3
104 + EGIT_REPO_URI="https://anongit.gentoo.org/git/proj/mysql-extras.git"
105 + EGIT_CHECKOUT_DIR="${WORKDIR}/mysql-extras"
106 + EGIT_CLONE_TYPE=shallow
107 + MY_PATCH_DIR="${WORKDIR}/mysql-extras"
108 +else
109 + MY_PATCH_DIR="${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}"
110 +fi
111 +
112 +PATCHES=(
113 + "${MY_PATCH_DIR}"/20001_all_fix-minimal-build-cmake-mysql-8.0.17.patch
114 + "${MY_PATCH_DIR}"/20007_all_cmake-debug-werror-8.0.17.patch
115 + "${MY_PATCH_DIR}"/20018_all_mysql-5.7.23-fix-grant_user_lock-a-root.patch
116 + "${MY_PATCH_DIR}"/20018_all_percona-server-8.0.17-without-clientlibs-tools.patch
117 + "${MY_PATCH_DIR}"/20018_all_mysql-8.0.17-add-protobuf-3.8+-support.patch
118 + "${MY_PATCH_DIR}"/20018_all_percona-server-8.0.17-fix-libressl-support.patch
119 + "${MY_PATCH_DIR}"/20018_all_percona-server-8.0.16-dont-install-tokudb-misc-files.patch
120 + "${MY_PATCH_DIR}"/20038_all_percona-server-8.0.16-PS-5873.patch
121 +)
122 +
123 +# Be warned, *DEPEND are version-dependant
124 +# These are used for both runtime and compiletime
125 +COMMON_DEPEND="
126 + >=app-arch/lz4-0_p131:=
127 + dev-libs/icu:=
128 + dev-libs/libedit
129 + dev-libs/libevent:=
130 + net-libs/libtirpc:=
131 + >=sys-libs/zlib-1.2.3:0=
132 + cjk? ( app-text/mecab:= )
133 + jemalloc? ( dev-libs/jemalloc:0= )
134 + kernel_linux? (
135 + dev-libs/libaio:0=
136 + sys-process/procps:0=
137 + )
138 + libressl? ( dev-libs/libressl:0= )
139 + !libressl? ( >=dev-libs/openssl-1.0.0:0= )
140 + numa? ( sys-process/numactl )
141 + tcmalloc? ( dev-util/google-perftools:0= )
142 +"
143 +DEPEND="${COMMON_DEPEND}
144 + || ( >=sys-devel/gcc-3.4.6 >=sys-devel/gcc-apple-4.0 )
145 + dev-libs/re2
146 + >=dev-libs/protobuf-3.8
147 + net-libs/rpcsvc-proto
148 + virtual/yacc
149 + test? (
150 + acct-group/mysql acct-user/mysql
151 + dev-perl/JSON
152 + )
153 +"
154 +RDEPEND="${COMMON_DEPEND}
155 + !dev-db/mariadb !dev-db/mariadb-galera !dev-db/percona-server !dev-db/mysql-cluster
156 + selinux? ( sec-policy/selinux-mysql )
157 + !prefix? (
158 + acct-group/mysql acct-user/mysql
159 + dev-db/mysql-init-scripts
160 + )
161 +"
162 +# For other stuff to bring us in
163 +# dev-perl/DBD-mysql is needed by some scripts installed by MySQL
164 +PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
165 +
166 +CHECKREQS_DISK_BUILD="8G"
167 +
168 +mysql_init_vars() {
169 + : ${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
170 + : ${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
171 + : ${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
172 + : ${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
173 + MY_DATADIR="${MY_LOCALSTATEDIR}"
174 +
175 + export MY_SHAREDSTATEDIR MY_SYSCONFDIR
176 + export MY_LOCALSTATEDIR MY_LOGDIR
177 + export MY_DATADIR
178 +}
179 +
180 +pkg_pretend() {
181 + [[ ${MERGE_TYPE} == binary ]] && return
182 + use server && check-reqs_pkg_pretend
183 +}
184 +
185 +pkg_setup() {
186 + [[ ${MERGE_TYPE} == binary ]] && return
187 +
188 + if has test ${FEATURES} ; then
189 + # Bug #213475 - MySQL _will_ object strenuously if your machine is named
190 + # localhost. Also causes weird failures.
191 + [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
192 +
193 + if ! has userpriv ${FEATURES} ; then
194 + die "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
195 + fi
196 +
197 + local aio_max_nr=$(sysctl -n fs.aio-max-nr 2>/dev/null)
198 + [[ -z "${aio_max_nr}" || ${aio_max_nr} -lt 250000 ]] \
199 + && die "FEATURES=test will require fs.aio-max-nr=250000 at minimum!"
200 +
201 + if use latin1 ; then
202 + # Upstream only supports tests with default charset
203 + die "Testing with USE=latin1 is not supported."
204 + fi
205 + fi
206 +
207 + if use kernel_linux ; then
208 + if use numa ; then
209 + linux-info_get_any_version
210 +
211 + local CONFIG_CHECK="~NUMA"
212 +
213 + local WARNING_NUMA="This package expects NUMA support in kernel which this system does not have at the moment;"
214 + WARNING_NUMA+=" Either expect runtime errors, enable NUMA support in kernel or rebuild the package without NUMA support"
215 +
216 + check_extra_config
217 + fi
218 + fi
219 +
220 + use server && check-reqs_pkg_setup
221 +}
222 +
223 +src_unpack() {
224 + unpack ${A}
225 +
226 + # Grab the patches
227 + [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-r3_src_unpack
228 +
229 + mv -f "${WORKDIR}/${MY_P}" "${S}" || die
230 +}
231 +
232 +src_prepare() {
233 + # Avoid rpm call which would trigger sandbox, #692368
234 + sed -i \
235 + -e 's/MY_RPM rpm/MY_RPM rpmNOTEXISTENT/' \
236 + CMakeLists.txt || die
237 +
238 + if use jemalloc ; then
239 + echo "TARGET_LINK_LIBRARIES(mysqld jemalloc)" >> "${S}/sql/CMakeLists.txt" || die
240 + fi
241 +
242 + if use tcmalloc ; then
243 + echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt" || die
244 + fi
245 +
246 + # Remove the centos and rhel selinux policies to support mysqld_safe under SELinux
247 + if [[ -d "${S}/support-files/SELinux" ]] ; then
248 + echo > "${S}/support-files/SELinux/CMakeLists.txt" || die
249 + fi
250 +
251 + # Remove man pages for client-lib tools we don't install
252 + rm \
253 + man/my_print_defaults.1 \
254 + man/perror.1 \
255 + man/zlib_decompress.1 \
256 + || die
257 +
258 + cmake-utils_src_prepare
259 +}
260 +
261 +src_configure(){
262 + # Bug #114895, bug #110149
263 + filter-flags "-O" "-O[01]"
264 +
265 + append-cxxflags -felide-constructors
266 +
267 + # bug #283926, with GCC4.4, this is required to get correct behavior.
268 + append-flags -fno-strict-aliasing
269 +
270 + CMAKE_BUILD_TYPE="RelWithDebInfo"
271 +
272 + # debug hack wrt #497532
273 + mycmakeargs=(
274 + -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
275 + -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
276 + -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr"
277 + -DMYSQL_DATADIR="${EPREFIX}/var/lib/mysql"
278 + -DSYSCONFDIR="${EPREFIX}/etc/mysql"
279 + -DINSTALL_BINDIR=bin
280 + -DINSTALL_DOCDIR=share/doc/${PF}
281 + -DINSTALL_DOCREADMEDIR=share/doc/${PF}
282 + -DINSTALL_INCLUDEDIR=include/mysql
283 + -DINSTALL_INFODIR=share/info
284 + -DINSTALL_LIBDIR=$(get_libdir)
285 + -DINSTALL_MANDIR=share/man
286 + -DINSTALL_MYSQLSHAREDIR=share/mysql
287 + -DINSTALL_PLUGINDIR=$(get_libdir)/mysql/plugin
288 + -DINSTALL_MYSQLDATADIR="${EPREFIX}/var/lib/mysql"
289 + -DINSTALL_SBINDIR=sbin
290 + -DINSTALL_SUPPORTFILESDIR="${EPREFIX}/usr/share/mysql"
291 + -DCOMPILATION_COMMENT="Gentoo Linux ${PF}"
292 + -DWITH_UNIT_TESTS=$(usex test ON OFF)
293 + -DWITH_EDITLINE=system
294 + -DWITH_ZLIB=system
295 + -DWITH_SSL=system
296 + -DWITH_LIBWRAP=0
297 + -DENABLED_LOCAL_INFILE=1
298 + -DMYSQL_UNIX_ADDR="${EPREFIX}/var/run/mysqld/mysqld.sock"
299 + -DWITH_DEFAULT_COMPILER_OPTIONS=0
300 + -DWITH_DEFAULT_FEATURE_SET=0
301 + # The build forces this to be defined when cross-compiling. We pass it
302 + # all the time for simplicity and to make sure it is actually correct.
303 + -DSTACK_DIRECTION=$(tc-stack-grows-down && echo -1 || echo 1)
304 + -DCMAKE_POSITION_INDEPENDENT_CODE=ON
305 + -DWITH_CURL=system
306 + -DWITH_BOOST="${WORKDIR}/boost_$(ver_rs 1- _ ${MY_BOOST_VERSION})"
307 + -DWITH_ROUTER=$(usex router ON OFF)
308 + )
309 + if use test ; then
310 + mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test )
311 + else
312 + mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
313 + fi
314 +
315 + mycmakeargs+=( -DWITHOUT_CLIENTLIBS=YES )
316 +
317 + # client/mysql.cc:1131:16: error: redefinition of ‘struct _hist_entry’
318 + mycmakeargs+=(
319 + -DUSE_LIBEDIT_INTERFACE=0
320 + -DUSE_NEW_EDITLINE_INTERFACE=1
321 + -DHAVE_HIST_ENTRY=1
322 + )
323 +
324 + mycmakeargs+=(
325 + -DWITH_ICU=system
326 + -DWITH_RE2=system
327 + -DWITH_LIBEVENT=system
328 + -DWITH_LZ4=system
329 + -DWITH_PROTOBUF=system
330 + -DWITH_MECAB=$(usex cjk system OFF)
331 + -DWITH_NUMA=$(usex numa ON OFF)
332 + # Our dev-libs/rapidjson doesn't carry necessary fixes for std::regex
333 + -DWITH_RAPIDJSON=bundled
334 + )
335 +
336 + if [[ -n "${MYSQL_DEFAULT_CHARSET}" && -n "${MYSQL_DEFAULT_COLLATION}" ]] ; then
337 + ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
338 + ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
339 + ewarn "You MUST file bugs without these variables set."
340 + ewarn "Tests will probably fail!"
341 +
342 + mycmakeargs+=(
343 + -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
344 + -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
345 + )
346 + elif use latin1 ; then
347 + mycmakeargs+=(
348 + -DDEFAULT_CHARSET=latin1
349 + -DDEFAULT_COLLATION=latin1_swedish_ci
350 + )
351 + else
352 + mycmakeargs+=(
353 + -DDEFAULT_CHARSET=utf8mb4
354 + -DDEFAULT_COLLATION=utf8mb4_0900_ai_ci
355 + )
356 + fi
357 +
358 + if use server ; then
359 + mycmakeargs+=(
360 + -DWITH_EXTRA_CHARSETS=all
361 + -DWITH_DEBUG=$(usex debug)
362 + )
363 +
364 + if use profiling ; then
365 + # Setting to OFF doesn't work: Once set, profiling options will be added
366 + # to `mysqld --help` output via sql/sys_vars.cc causing
367 + # "main.mysqld--help-notwin" test to fail
368 + mycmakeargs+=( -DENABLED_PROFILING=ON )
369 + fi
370 +
371 + # Storage engines
372 + mycmakeargs+=(
373 + -DWITH_EXAMPLE_STORAGE_ENGINE=0
374 + -DWITH_ARCHIVE_STORAGE_ENGINE=1
375 + -DWITH_BLACKHOLE_STORAGE_ENGINE=1
376 + -DWITH_CSV_STORAGE_ENGINE=1
377 + -DWITH_FEDERATED_STORAGE_ENGINE=1
378 + -DWITH_HEAP_STORAGE_ENGINE=1
379 + -DWITH_INNOBASE_STORAGE_ENGINE=1
380 + -DWITH_INNODB_MEMCACHED=0
381 + -DWITH_MYISAMMRG_STORAGE_ENGINE=1
382 + -DWITH_MYISAM_STORAGE_ENGINE=1
383 + -DWITH_ROCKSDB=$(usex rocksdb 1 0)
384 + -DWITH_TOKUDB=$(usex tokudb 1 0)
385 + )
386 + else
387 + mycmakeargs+=(
388 + -DWITHOUT_SERVER=1
389 + -DWITH_SYSTEMD=no
390 + )
391 + fi
392 +
393 + cmake-utils_src_configure
394 +}
395 +
396 +# Official test instructions:
397 +# ulimit -n 16500 && \
398 +# USE='perl server' \
399 +# FEATURES='test userpriv' \
400 +# ebuild mysql-X.X.XX.ebuild \
401 +# digest clean package
402 +src_test() {
403 + _disable_test() {
404 + local rawtestname bug reason
405 + rawtestname="${1}" ; shift
406 + bug="${1}" ; shift
407 + reason="${@}"
408 + ewarn "test '${rawtestname}' disabled: '${reason}' (BUG#${bug})"
409 + echo ${rawtestname} : BUG#${bug} ${reason} >> "${T}/disabled.def"
410 + }
411 +
412 + local TESTDIR="${BUILD_DIR}/mysql-test"
413 + local retstatus_unit
414 + local retstatus_tests
415 +
416 + # Run CTest (test-units)
417 + cmake-utils_src_test
418 + retstatus_unit=$?
419 +
420 + # Ensure that parallel runs don't die
421 + export MTR_BUILD_THREAD="$((${RANDOM} % 100))"
422 +
423 + if [[ -z "${MTR_PARALLEL}" ]] ; then
424 + local -x MTR_PARALLEL=$(makeopts_jobs)
425 +
426 + if [[ ${MTR_PARALLEL} -gt 4 ]] ; then
427 + # Running multiple tests in parallel usually require higher ulimit
428 + # and fs.aio-max-nr setting. In addition, tests like main.multi_update
429 + # are known to hit timeout when system is busy.
430 + # To avoid test failure we will limit MTR_PARALLEL to 4 instead of
431 + # using "auto".
432 + local info_msg="Parallel MySQL test suite jobs limited to 4 (MAKEOPTS=${MTR_PARALLEL})"
433 + info_msg+=" to avoid test failures. Set MTR_PARALLEL if you know what you are doing!"
434 + einfo "${info_msg}"
435 + unset info_msg
436 + MTR_PARALLEL=4
437 + fi
438 + else
439 + einfo "MTR_PARALLEL is set to '${MTR_PARALLEL}'"
440 + fi
441 +
442 + # create directories because mysqladmin might run out of order
443 + mkdir -p "${T}"/var-tests{,/log} || die
444 +
445 + # Run mysql tests
446 + pushd "${TESTDIR}" &>/dev/null || die
447 +
448 + touch "${T}/disabled.def"
449 +
450 + local -a disabled_tests
451 + disabled_tests+=( "auth_sec.keyring_file_data_qa;0;Won't work with user privileges")
452 + disabled_tests+=( "gis.spatial_analysis_functions_buffer;5452;Known rounding error with latest AMD processors (PS)")
453 + disabled_tests+=( "gis.gis_bugs_crashes;5452;Known rounding error with latest AMD processors (PS)")
454 + disabled_tests+=( "gis.geometry_class_attri_prop;5452;Known rounding error with latest AMD processors (PS)")
455 + disabled_tests+=( "gis.spatial_utility_function_distance_sphere;5452;Known rounding error with latest AMD processors (PS)")
456 + disabled_tests+=( "gis.geometry_property_function_issimple;5452;Known rounding error with latest AMD processors (PS)")
457 + disabled_tests+=( "gis.spatial_analysis_functions_centroid;5452;Known rounding error with latest AMD processors (PS)")
458 + disabled_tests+=( "gis.spatial_operators_intersection;5452;Known rounding error with latest AMD processors (PS)")
459 + disabled_tests+=( "gis.spatial_utility_function_simplify;5452;Known rounding error with latest AMD processors (PS)")
460 + disabled_tests+=( "gis.spatial_op_testingfunc_mix;5452;Known rounding error with latest AMD processors (PS)")
461 + disabled_tests+=( "gis.spatial_analysis_functions_distance;5452;Known rounding error with latest AMD processors (PS)")
462 + disabled_tests+=( "main.window_std_var;0;Known rounding error with latest AMD processors -- no upstream bug yet")
463 + disabled_tests+=( "main.window_std_var_optimized;0;Known rounding error with latest AMD processors -- no upstream bug yet")
464 + disabled_tests+=( "rpl_gtid.rpl_gtid_stm_drop_table;90612;Known test failure" )
465 + disabled_tests+=( "rpl_gtid.rpl_multi_source_mtr_includes;0;Know failure - no upstream bug yet" )
466 + disabled_tests+=( "sys_vars.myisam_data_pointer_size_func;87935;Test will fail on slow hardware")
467 + disabled_tests+=( "main.mysqlpump_basic_lz4;6042;Extra tool output causes false positive" )
468 + disabled_tests+=( "main.ssl_bug75311;5996;Known test failure" )
469 +
470 + local test_ds
471 + for test_infos_str in "${disabled_tests[@]}" ; do
472 + IFS=';' read -r -a test_infos_arr <<< "${test_infos_str}"
473 +
474 + if [[ ${#test_infos_arr[@]} != 3 ]] ; then
475 + die "Invalid test data set, not matching format: ${test_infos_str}"
476 + fi
477 +
478 + _disable_test "${test_infos_arr[0]}" "${test_infos_arr[1]}" "${test_infos_arr[2]}"
479 + done
480 + unset test_ds test_infos_str test_infos_arr
481 +
482 + # Try to increase file limits to increase test coverage
483 + if ! ulimit -n 16500 1>/dev/null 2>&1 ; then
484 + # Upper limit comes from parts.partition_* tests
485 + ewarn "For maximum test coverage please raise open file limit to 16500 (ulimit -n 16500) before calling the package manager."
486 +
487 + if ! ulimit -n 4162 1>/dev/null 2>&1 ; then
488 + # Medium limit comes from '[Warning] Buffered warning: Could not increase number of max_open_files to more than 3000 (request: 4162)'
489 + ewarn "For medium test coverage please raise open file limit to 4162 (ulimit -n 4162) before calling the package manager."
490 +
491 + if ! ulimit -n 3000 1>/dev/null 2>&1 ; then
492 + ewarn "For minimum test coverage please raise open file limit to 3000 (ulimit -n 3000) before calling the package manager."
493 + else
494 + einfo "Will run test suite with open file limit set to 3000 (minimum test coverage)."
495 + fi
496 + else
497 + einfo "Will run test suite with open file limit set to 4162 (medium test coverage)."
498 + fi
499 + else
500 + einfo "Will run test suite with open file limit set to 16500 (best test coverage)."
501 + fi
502 +
503 + # run mysql-test tests
504 + perl mysql-test-run.pl --force --vardir="${T}/var-tests" --reorder --skip-test=tokudb --skip-test-list="${T}/disabled.def"
505 + retstatus_tests=$?
506 +
507 + popd &>/dev/null || die
508 +
509 + # Cleanup is important for these testcases.
510 + pkill -9 -f "${S}/ndb" 2>/dev/null
511 + pkill -9 -f "${S}/sql" 2>/dev/null
512 +
513 + local failures=""
514 + [[ $retstatus_unit -eq 0 ]] || failures="${failures} test-unit"
515 + [[ $retstatus_tests -eq 0 ]] || failures="${failures} tests"
516 +
517 + [[ -z "$failures" ]] || die "Test failures: $failures"
518 + einfo "Tests successfully completed"
519 +}
520 +
521 +src_install() {
522 + cmake-utils_src_install
523 +
524 + # Make sure the vars are correctly initialized
525 + mysql_init_vars
526 +
527 + # Convenience links
528 + einfo "Making Convenience links for mysqlcheck multi-call binary"
529 + dosym "mysqlcheck" "/usr/bin/mysqlanalyze"
530 + dosym "mysqlcheck" "/usr/bin/mysqlrepair"
531 + dosym "mysqlcheck" "/usr/bin/mysqloptimize"
532 +
533 + # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
534 + if [[ -d "${ED}/usr/data" ]] ; then
535 + rm -Rf "${ED}/usr/data" || die
536 + fi
537 +
538 + # Unless they explicitly specific USE=test, then do not install the
539 + # testsuite. It DOES have a use to be installed, esp. when you want to do a
540 + # validation of your database configuration after tuning it.
541 + if ! use test ; then
542 + rm -rf "${ED}/${MY_SHAREDSTATEDIR#${EPREFIX}}/mysql-test"
543 + fi
544 +
545 + # Configuration stuff
546 + einfo "Building default configuration ..."
547 + insinto "${MY_SYSCONFDIR#${EPREFIX}}"
548 + [[ -f "${S}/scripts/mysqlaccess.conf" ]] && doins "${S}"/scripts/mysqlaccess.conf
549 + cp "${FILESDIR}/my.cnf-5.7" "${TMPDIR}/my.cnf" || die
550 + eprefixify "${TMPDIR}/my.cnf"
551 + doins "${TMPDIR}/my.cnf"
552 + insinto "${MY_SYSCONFDIR#${EPREFIX}}/mysql.d"
553 + cp "${FILESDIR}/my.cnf-8.0.distro-client" "${TMPDIR}/50-distro-client.cnf" || die
554 + eprefixify "${TMPDIR}/50-distro-client.cnf"
555 + doins "${TMPDIR}/50-distro-client.cnf"
556 +
557 + mycnf_src="my.cnf-8.0.distro-server"
558 + sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
559 + "${FILESDIR}/${mycnf_src}" \
560 + > "${TMPDIR}/my.cnf.ok" || die
561 +
562 + if use prefix ; then
563 + sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' \
564 + "${TMPDIR}/my.cnf.ok" || die
565 + fi
566 +
567 + if use latin1 ; then
568 + sed -i \
569 + -e "/character-set/s|utf8mb4|latin1|g" \
570 + "${TMPDIR}/my.cnf.ok" || die
571 + fi
572 +
573 + eprefixify "${TMPDIR}/my.cnf.ok"
574 +
575 + newins "${TMPDIR}/my.cnf.ok" 50-distro-server.cnf
576 +
577 + #Remove mytop if perl is not selected
578 + [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
579 +
580 + if use router ; then
581 + rm -rf \
582 + "${ED}/usr/LICENSE.router" \
583 + "${ED}/usr/README.router" \
584 + "${ED}/usr/run" \
585 + "${ED}/usr/var" \
586 + || die
587 + fi
588 +
589 + # Kill old libmysqclient_r symlinks if they exist. Time to fix what depends on them.
590 + find "${D}" -name 'libmysqlclient_r.*' -type l -delete || die
591 +}
592 +
593 +pkg_postinst() {
594 + # Make sure the vars are correctly initialized
595 + mysql_init_vars
596 +
597 + # Create log directory securely if it does not exist
598 + # NOTE: $MY_LOGDIR contains $EPREFIX by default
599 + [[ -d "${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${MY_LOGDIR}"
600 +
601 + # Note about configuration change
602 + einfo
603 + elog "This version of ${PN} reorganizes the configuration from a single my.cnf"
604 + elog "to several files in /etc/mysql/mysql.d."
605 + elog "Please backup any changes you made to /etc/mysql/my.cnf"
606 + elog "and add them as a new file under /etc/mysql/mysql.d with a .cnf extension."
607 + elog "You may have as many files as needed and they are read alphabetically."
608 + elog "Be sure the options have the appropriate section headers, i.e. [mysqld]."
609 + einfo
610 +
611 + if [[ -z "${REPLACING_VERSIONS}" ]] ; then
612 + einfo
613 + elog "You might want to run:"
614 + elog " \"emerge --config =${CATEGORY}/${PF}\""
615 + elog "if this is a new install."
616 + einfo
617 + else
618 + einfo
619 + elog "Upgrade process for ${PN}-8.x has changed. Please read"
620 + elog "https://dev.mysql.com/doc/refman/8.0/en/upgrade-binary-package.html"
621 + einfo
622 + fi
623 +}
624 +
625 +pkg_config() {
626 + local mysqld_binary="${EROOT}/usr/sbin/mysqld"
627 + if [[ ! -x "${mysqld_binary}" ]] ; then
628 + die "'${mysqld_binary}' not found! Please re-install ${CATEGORY}/${PN}!"
629 + fi
630 +
631 + local mysql_binary="${EROOT}/usr/bin/mysql"
632 + if [[ ! -x "${mysql_binary}" ]] ; then
633 + die "'${mysql_binary}' not found! Please re-install ${CATEGORY}/${PN}!"
634 + fi
635 +
636 + local my_print_defaults_binary="${EROOT}/usr/bin/my_print_defaults"
637 + if [[ ! -x "${my_print_defaults_binary}" ]] ; then
638 + die "'${my_print_defaults_binary}' not found! Please re-install dev-db/mysql-connector-c!"
639 + fi
640 +
641 + if [[ -z "${MYSQL_USER}" ]] ; then
642 + MYSQL_USER=mysql
643 + if use prefix ; then
644 + MYSQL_USER=$(id -u -n 2>/dev/null)
645 + if [[ -z "${MYSQL_USER}" ]] ; then
646 + die "Failed to determine current username!"
647 + fi
648 + fi
649 + fi
650 +
651 + if [[ -z "${MYSQL_GROUP}" ]] ; then
652 + MYSQL_GROUP=mysql
653 + if use prefix ; then
654 + MYSQL_GROUP=$(id -g -n 2>/dev/null)
655 + if [[ -z "${MYSQL_GROUP}" ]] ; then
656 + die "Failed to determine current user groupname!"
657 + fi
658 + fi
659 + fi
660 +
661 + einfo "Will use username '${MYSQL_USER}' and group '${MYSQL_GROUP}' ..."
662 +
663 + _getoptval() {
664 + local section="$1"
665 + local flag="--${2}="
666 + local extra_options="${3}"
667 + local cmd=(
668 + "${my_print_defaults_binary}"
669 + "${extra_options}"
670 + "${section}"
671 + )
672 + local results=( $(eval "${cmd[@]}" 2>/dev/null | sed -n "/^${flag}/s,${flag},,gp") )
673 +
674 + if [[ ${#results[@]} -gt 0 ]] ; then
675 + # When option is set multiple times only return last value
676 + echo "${results[-1]}"
677 + fi
678 + }
679 +
680 + _mktemp_dry() {
681 + # emktemp has no --dry-run option
682 + local template="${1}"
683 +
684 + if [[ -z "${template}" ]] ; then
685 + if [[ -z "${T}" ]] ; then
686 + template="/tmp/XXXXXXX"
687 + else
688 + template="${T}/XXXXXXX"
689 + fi
690 + fi
691 +
692 + local template_wo_X=${template//X/}
693 + local n_X
694 + let n_X=${#template}-${#template_wo_X}
695 + if [[ ${n_X} -lt 3 ]] ; then
696 + echo "${FUNCNAME[0]}: too few X's in template ‘${template}’" >&2
697 + return
698 + fi
699 +
700 + local attempts=0
701 + local character tmpfile
702 + while [[ true ]] ; do
703 + let attempts=attempts+1
704 +
705 + new_file=
706 + while read -n1 character ; do
707 + if [[ "${character}" == "X" ]] ; then
708 + tmpfile+="${RANDOM:0:1}"
709 + else
710 + tmpfile+="${character}"
711 + fi
712 + done < <(echo -n "${template}")
713 +
714 + if [[ ! -f "${tmpfile}" ]]
715 + then
716 + echo "${tmpfile}"
717 + return
718 + fi
719 +
720 + if [[ ${attempts} -ge 100 ]] ; then
721 + echo "${FUNCNAME[0]}: Cannot create temporary file after 100 attempts." >&2
722 + return
723 + fi
724 + done
725 + }
726 +
727 + # my_print_defaults needs to read stuff in $HOME/.my.cnf
728 + local -x HOME="${EROOT}/root"
729 +
730 + # Make sure the vars are correctly initialized
731 + mysql_init_vars
732 +
733 + # Read currently set data directory
734 + MY_DATADIR="$(_getoptval mysqld datadir "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
735 +
736 + # Bug #213475 - MySQL _will_ object strenously if your machine is named
737 + # localhost. Also causes weird failures.
738 + [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
739 +
740 + if [[ -z "${MY_DATADIR}" ]] ; then
741 + die "Sorry, unable to find MY_DATADIR!"
742 + elif [[ -d "${MY_DATADIR}/mysql" ]] ; then
743 + ewarn "Looks like your data directory '${MY_DATADIR}' is already initialized!"
744 + ewarn "Please rename or delete its content if you wish to initialize a new data directory."
745 + die "${PN} data directory at '${MY_DATADIR}' looks already initialized!"
746 + else
747 + einfo "${PN} data directory detected as '${MY_DATADIR}' ..."
748 + fi
749 +
750 + MYSQL_TMPDIR="$(_getoptval mysqld tmpdir "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
751 + # These are dir+prefix
752 + MYSQL_LOG_BIN="$(_getoptval mysqld log-bin "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
753 + MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
754 + MYSQL_RELAY_LOG="$(_getoptval mysqld relay-log "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
755 + MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
756 +
757 + # Create missing directories.
758 + # Always check if mysql user can write to directory even if we just
759 + # created directory because a parent directory might be not
760 + # accessible for that user.
761 + PID_DIR="${EROOT}/run/mysqld"
762 + if [[ ! -d "${PID_DIR}" ]] ; then
763 + einfo "Creating ${PN} PID directory '${PID_DIR}' ..."
764 + install -d -m 755 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${PID_DIR}" \
765 + || die "Failed to create PID directory '${PID_DIR}'!"
766 + fi
767 +
768 + local _pid_dir_testfile="$(_mktemp_dry "${PID_DIR}/.pkg_config-access-test.XXXXXXXXX")"
769 + [[ -z "${_pid_dir_testfile}" ]] \
770 + && die "_mktemp_dry() for '${PID_DIR}/.pkg_config-access-test.XXXXXXXXX' failed!"
771 +
772 + if use prefix ; then
773 + touch "${_pid_dir_testfile}" &>/dev/null
774 + else
775 + su -s /bin/sh -c "touch ${_pid_dir_testfile}" ${MYSQL_USER} &>/dev/null
776 + fi
777 +
778 + if [[ $? -ne 0 ]] ; then
779 + die "${MYSQL_USER} user cannot write into PID dir '${PID_DIR}'!"
780 + else
781 + rm "${_pid_dir_testfile}" || die
782 + unset _pid_dir_testfile
783 + fi
784 +
785 + if [[ ! -d "${MY_DATADIR}" ]] ; then
786 + einfo "Creating ${PN} data directory '${MY_DATADIR}' ..."
787 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MY_DATADIR}" \
788 + || die "Failed to create ${PN} data directory '${MY_DATADIR}'!"
789 + fi
790 +
791 + local _my_datadir_testfile="$(_mktemp_dry "${MY_DATADIR}/.pkg_config-access-test.XXXXXXXXX")"
792 + [[ -z "${_my_datadir_testfile}" ]] \
793 + && die "_mktemp_dry() for '${MY_DATADIR}/.pkg_config-access-test.XXXXXXXXX' failed!"
794 +
795 + if use prefix ; then
796 + touch "${_my_datadir_testfile}" &>/dev/null
797 + else
798 + su -s /bin/sh -c "touch ${_my_datadir_testfile}" ${MYSQL_USER} &>/dev/null
799 + fi
800 +
801 + if [[ $? -ne 0 ]]; then
802 + die "${MYSQL_USER} user cannot write into data directory '${MY_DATADIR}'!"
803 + else
804 + rm "${_my_datadir_testfile}" || die
805 + unset _my_datadir_testfile
806 + fi
807 +
808 + if [[ -n "${MYSQL_TMPDIR}" && ! -d "${MYSQL_TMPDIR}" ]] ; then
809 + einfo "Creating ${PN} tmpdir '${MYSQL_TMPDIR}' ..."
810 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MYSQL_TMPDIR}" \
811 + || die "Failed to create ${PN} tmpdir '${MYSQL_TMPDIR}'!"
812 + fi
813 +
814 + if [[ -n "${MYSQL_TMPDIR}" ]] ; then
815 + local _my_tmpdir_testfile="$(_mktemp_dry "${MYSQL_TMPDIR}/.pkg_config-access-test.XXXXXXXXX")"
816 + [[ -z "${_my_tmpdir_testfile}" ]] \
817 + && die "_mktemp_dry() for '${MYSQL_TMPDIR}/.pkg_config-access-test.XXXXXXXXX' failed!"
818 +
819 + if use prefix ; then
820 + touch "${_my_tmpdir_testfile}" &>/dev/null
821 + else
822 + su -s /bin/sh -c "touch ${_my_tmpdir_testfile}" ${MYSQL_USER} &>/dev/null
823 + fi
824 +
825 + if [[ $? -ne 0 ]]; then
826 + die "${MYSQL_USER} user cannot write into data directory '${MYSQL_TMPDIR}'!"
827 + else
828 + rm "${_my_tmpdir_testfile}" || die
829 + unset _my_tmpdir_testfile
830 + fi
831 + else
832 + # If no tmpdir is set, mysqld will use default system tmpdir.
833 + # However, we are using tmpdir from package manager at the
834 + # moment which maybe isn't writeable for $MYSQL_USER...
835 + MYSQL_TMPDIR="$(_mktemp_dry "${T}/mysqld-tmp.XXXXXXXXX")"
836 + [[ -z "${MYSQL_TMPDIR}" ]] \
837 + && die "_mktemp_dry() for '${MYSQL_TMPDIR}' failed!"
838 +
839 + mkdir "${MYSQL_TMPDIR}" || die
840 + chown ${MYSQL_USER} "${MYSQL_TMPDIR}" || die
841 + fi
842 +
843 + if [[ -n "${MYSQL_LOG_BIN}" && ! -d "${MYSQL_LOG_BIN}" ]] ; then
844 + einfo "Creating ${PN} log-bin directory '${MYSQL_LOG_BIN}' ..."
845 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MYSQL_LOG_BIN}" \
846 + || die "Failed to create ${PN} log-bin directory '${MYSQL_LOG_BIN}'"
847 + fi
848 +
849 + if [[ -n "${MYSQL_LOG_BIN}" ]] ; then
850 + local _my_logbin_testfile="$(_mktemp_dry "${MYSQL_LOG_BIN}/.pkg_config-access-test.XXXXXXXXX")"
851 + [[ -z "${_my_logbin_testfile}" ]] \
852 + && die "_mktemp_dry() for '${MYSQL_LOG_BIN}/.pkg_config-access-test.XXXXXXXXX' failed!"
853 +
854 + if use prefix ; then
855 + touch "${_my_logbin_testfile}" &>/dev/null
856 + else
857 + su -s /bin/sh -c "touch ${_my_logbin_testfile}" ${MYSQL_USER} &>/dev/null
858 + fi
859 +
860 + if [[ $? -ne 0 ]]; then
861 + die "${MYSQL_USER} user cannot write into log-bin directory '${MYSQL_LOG_BIN}'!"
862 + else
863 + rm "${_my_logbin_testfile}" || die
864 + unset _my_logbin_testfile
865 + fi
866 + fi
867 +
868 + if [[ -n "${MYSQL_RELAY_LOG}" && ! -d "${MYSQL_RELAY_LOG}" ]] ; then
869 + einfo "Creating ${PN} relay-log directory '${MYSQL_RELAY_LOG}' ..."
870 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MYSQL_RELAY_LOG}" \
871 + || die "Failed to create ${PN} relay-log directory '${MYSQL_RELAY_LOG}'!"
872 + fi
873 +
874 + if [[ -n "${MYSQL_RELAY_LOG}" ]] ; then
875 + local _my_relaylog_testfile="$(_mktemp_dry "${MYSQL_RELAY_LOG}/.pkg_config-access-test.XXXXXXXXX")"
876 + [[ -z "${_my_relaylog_testfile}" ]] \
877 + && die "_mktemp_dry() for '${MYSQL_RELAY_LOG}/.pkg_config-access-test.XXXXXXXXX' failed!"
878 +
879 + if use prefix ; then
880 + touch "${_my_relaylog_testfile}" &>/dev/null
881 + else
882 + su -s /bin/sh -c "touch ${_my_relaylog_testfile}" ${MYSQL_USER} &>/dev/null
883 + fi
884 +
885 + if [[ $? -ne 0 ]]; then
886 + die "${MYSQL_USER} user cannot write into relay-log directory '${MYSQL_RELAY_LOG}'!"
887 + else
888 + rm "${_my_relaylog_testfile}" || die
889 + unset _my_relaylog_testfile
890 + fi
891 + fi
892 +
893 + local -a config_files
894 +
895 + local config_file="${EROOT}/etc/mysql/mysql.d/50-distro-client.cnf"
896 + if [[ -f "${config_file}" ]] ; then
897 + config_files+=( "${config_file}" )
898 + else
899 + ewarn "Client configuration '${config_file}' not found; Skipping configuration of default authentication plugin for client ..."
900 + fi
901 +
902 + config_file="${EROOT}/etc/mysql/mysql.d/50-distro-server.cnf"
903 + if [[ -f "${config_file}" ]] ; then
904 + config_files+=( "${config_file}" )
905 + else
906 + ewarn "Server configuration '${config_file}' not found; Skipping configuration of default authentication plugin for mysqld ..."
907 + fi
908 +
909 + if [[ ${#config_files[@]} -gt 0 ]] ; then
910 + if [[ -z "${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}" ]] ; then
911 + local user_answer
912 +
913 + echo
914 + einfo "Please select default authentication plugin (enter number or plugin name):"
915 + einfo "1) caching_sha2_password [MySQL 8.0 default]"
916 + einfo "2) mysql_native_password [MySQL 5.7 default]"
917 + einfo
918 + einfo "For details see:"
919 + einfo "https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password"
920 + read -p " >" user_answer
921 + echo
922 +
923 + case "${user_answer}" in
924 + 1|caching_sha2_password)
925 + MYSQL_DEFAULT_AUTHENTICATION_PLUGIN=caching_sha2_password
926 + ;;
927 + 2|mysql_native_password)
928 + MYSQL_DEFAULT_AUTHENTICATION_PLUGIN=mysql_native_password
929 + ;;
930 + '')
931 + die "No authentication plugin selected!"
932 + ;;
933 + *)
934 + die "Authentication plugin '${user_answer}' is unknown/unsupported!"
935 + ;;
936 + esac
937 +
938 + unset user_answer
939 + fi
940 +
941 + local cfg_option cfg_option_tabs cfg_section
942 + for config_file in "${config_files[@]}" ; do
943 + cfg_option="default-authentication-plugin"
944 + cfg_section="mysqld"
945 + cfg_option_tabs="\t\t"
946 + if [[ "${config_file}" == *client.cnf ]] ; then
947 + cfg_option="default-auth"
948 + cfg_section="client"
949 + cfg_option_tabs="\t\t\t\t"
950 + fi
951 +
952 + if grep -qE "^(loose-)?${cfg_option}\b.*=" "${config_file}" 2>/dev/null ; then
953 + einfo "Ensuring that ${cfg_option} is set to '${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}' in '${config_file}' ..."
954 + sed -i \
955 + -e "s/^\(loose-\)\?${cfg_option}\b.*=.*/loose-${cfg_option}${cfg_option_tabs}= ${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}/" \
956 + "${config_file}" || die "Failed to change ${cfg_option} in '${config_file}'!"
957 + else
958 + einfo "Setting ${cfg_option} to '${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}' in '${config_file}' ..."
959 + sed -i \
960 + -e "/^\[${cfg_section}\]$/a loose-${cfg_option}${cfg_option_tabs}= ${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}" \
961 + "${config_file}" || die "Failed to add ${cfg_option} to '${config_file}'!"
962 + fi
963 + done
964 + unset cfg_option cfg_option_tabs cfg_section
965 + fi
966 + unset config_files config_file
967 +
968 + echo
969 +
970 + if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
971 + local tmp_mysqld_password_source=
972 +
973 + for tmp_mysqld_password_source in mysql client ; do
974 + einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
975 + MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password)"
976 + if [[ -n "${MYSQL_ROOT_PASSWORD}" ]] ; then
977 + if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]] ; then
978 + ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
979 + MYSQL_ROOT_PASSWORD=
980 + continue
981 + fi
982 +
983 + einfo "Found password in '${tmp_mysqld_password_source}' section!"
984 + break
985 + fi
986 + done
987 +
988 + # Sometimes --show is required to display passwords in some implementations of my_print_defaults
989 + if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]] ; then
990 + MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password --show)"
991 + fi
992 +
993 + unset tmp_mysqld_password_source
994 + fi
995 +
996 + if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
997 + local pwd1="a"
998 + local pwd2="b"
999 +
1000 + echo
1001 + einfo "No password for mysql 'root' user was specified via environment"
1002 + einfo "variable MYSQL_ROOT_PASSWORD and no password was found in config"
1003 + einfo "file like '${HOME}/.my.cnf'."
1004 + einfo "To continue please provide a password for the mysql 'root' user"
1005 + einfo "now on console:"
1006 + ewarn "NOTE: Please avoid [\"'\\_%] characters in the password!"
1007 + read -rsp " >" pwd1 ; echo
1008 +
1009 + einfo "Retype the password"
1010 + read -rsp " >" pwd2 ; echo
1011 +
1012 + if [[ "x$pwd1" != "x$pwd2" ]] ; then
1013 + die "Passwords are not the same!"
1014 + fi
1015 +
1016 + MYSQL_ROOT_PASSWORD="${pwd1}"
1017 + unset pwd1 pwd2
1018 +
1019 + echo
1020 + fi
1021 +
1022 + local -a mysqld_options
1023 +
1024 + # Fix bug 446200. Don't reference host my.cnf, needs to come first,
1025 + # see http://bugs.mysql.com/bug.php?id=31312
1026 + use prefix && mysqld_options+=( "--defaults-file='${MY_SYSCONFDIR}/my.cnf'" )
1027 +
1028 + # Figure out which options we need to disable to do the setup
1029 + local helpfile="${TMPDIR}/mysqld-help"
1030 + "${EROOT}/usr/sbin/mysqld" --verbose --help >"${helpfile}" 2>/dev/null
1031 +
1032 + local opt optexp optfull
1033 + for opt in host-cache name-resolve networking slave-start \
1034 + federated ssl log-bin relay-log slow-query-log external-locking \
1035 + log-slave-updates \
1036 + ; do
1037 + optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
1038 + egrep -sq -- "${optexp}" "${helpfile}" && mysqld_options+=( "${optfull}" )
1039 + done
1040 +
1041 + # Prepare timezones, see
1042 + # https://dev.mysql.com/doc/mysql/en/time-zone-support.html
1043 + local tz_sql="${TMPDIR}/tz.sql"
1044 + echo "USE mysql;" >"${tz_sql}"
1045 + "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" >> "${tz_sql}" 2>/dev/null
1046 + if [[ $? -ne 0 ]] ; then
1047 + die "mysql_tzinfo_to_sql failed!"
1048 + fi
1049 +
1050 + chown ${MYSQL_USER} "${tz_sql}" || die
1051 +
1052 + local mysql_install_log="${TMPDIR}/mysql_install_db.log"
1053 + touch "${mysql_install_log}" || die
1054 + chown ${MYSQL_USER} "${mysql_install_log}" || die
1055 +
1056 + # --initialize-insecure will not set root password
1057 + # --initialize would set a random one in the log which we don't need as we set it ourselves
1058 + local cmd=(
1059 + "${mysqld_binary}"
1060 + "${mysqld_options[@]}"
1061 + "--initialize-insecure"
1062 + "--init-file='${tz_sql}'"
1063 + "--basedir='${EROOT}/usr'"
1064 + "--datadir='${MY_DATADIR}'"
1065 + "--tmpdir='${MYSQL_TMPDIR}'"
1066 + "--log-error='${mysql_install_log}'"
1067 + "--user=${MYSQL_USER}"
1068 + )
1069 +
1070 + einfo "Initializing ${PN} data directory: ${cmd[@]}"
1071 + eval "${cmd[@]}" >>"${mysql_install_log}" 2>&1
1072 +
1073 + if [[ $? -ne 0 || ! -f "${MY_DATADIR}/mysql.ibd" ]] ; then
1074 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysql_install_log}" 1>&2
1075 + die "Failed to initialize ${PN} data directory. Please review '${mysql_install_log}'!"
1076 + fi
1077 +
1078 + local x=${RANDOM}
1079 + local socket="${EROOT}/run/mysqld/mysqld${x}.sock"
1080 + local pidfile="${EROOT}/run/mysqld/mysqld${x}.pid"
1081 + unset x
1082 +
1083 + local mysqld_logfile="${TMPDIR}/mysqld.log"
1084 + touch "${mysqld_logfile}" || die
1085 + chown ${MYSQL_USER} "${mysqld_logfile}" || die
1086 +
1087 + cmd=(
1088 + "${mysqld_binary}"
1089 + "${mysqld_options[@]}"
1090 + "--basedir='${EROOT}/usr'"
1091 + "--datadir='${MY_DATADIR}'"
1092 + "--tmpdir='${MYSQL_TMPDIR}'"
1093 + --max_allowed_packet=8M
1094 + --net_buffer_length=16K
1095 + "--socket='${socket}'"
1096 + "--pid-file='${pidfile}'"
1097 + "--log-error='${mysqld_logfile}'"
1098 + "--user=${MYSQL_USER}"
1099 + )
1100 +
1101 + einfo "Starting mysqld to finalize initialization: ${cmd[@]}"
1102 + eval "${cmd[@]}" >>"${mysqld_logfile}" 2>&1 &
1103 +
1104 + echo -n "Waiting for mysqld to accept connections "
1105 + local maxtry=15
1106 + while [[ ! -S "${socket}" && "${maxtry}" -gt 1 ]] ; do
1107 + maxtry=$((${maxtry}-1))
1108 + echo -n "."
1109 + sleep 1
1110 + done
1111 +
1112 + if [[ -S "${socket}" ]] ; then
1113 + # Even with a socket we don't know if mysqld will abort
1114 + # start due to an error so just wait a little bit more...
1115 + maxtry=5
1116 + while [[ -S "${socket}" && "${maxtry}" -gt 1 ]] ; do
1117 + maxtry=$((${maxtry}-1))
1118 + echo -n "."
1119 + sleep 1
1120 + done
1121 + fi
1122 +
1123 + echo
1124 +
1125 + if [[ ! -S "${socket}" ]] ; then
1126 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysqld_logfile}" 1>&2
1127 + die "mysqld was unable to start from initialized data directory. Please review '${mysqld_logfile}'!"
1128 + fi
1129 +
1130 + local mysql_logfile="${TMPDIR}/set_root_pw.log"
1131 + touch "${mysql_logfile}" || die
1132 +
1133 + ebegin "Setting root password"
1134 + # Do this from memory, as we don't want clear text passwords in temp files
1135 + local sql="ALTER USER 'root'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}'"
1136 + cmd=(
1137 + "${mysql_binary}"
1138 + --no-defaults
1139 + "--socket='${socket}'"
1140 + -hlocalhost
1141 + "-e \"${sql}\""
1142 + )
1143 + eval "${cmd[@]}" >"${mysql_logfile}" 2>&1
1144 + local rc=$?
1145 + eend ${rc}
1146 +
1147 + if [[ ${rc} -ne 0 ]] ; then
1148 + # Poor man's solution which tries to avoid having password
1149 + # in log. NOTE: sed can fail if user didn't follow advice
1150 + # and included character which will require escaping...
1151 + sed -i -e "s/${MYSQL_ROOT_PASSWORD}/*****/" "${mysql_logfile}" 2>/dev/null
1152 +
1153 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysql_logfile}"
1154 + die "Failed to set ${PN} root password. Please review '${mysql_logfile}'!"
1155 + fi
1156 +
1157 + # Stop the server
1158 + if [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; then
1159 + echo -n "Stopping the server "
1160 + pkill -F "${pidfile}" &>/dev/null
1161 +
1162 + maxtry=10
1163 + while [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; do
1164 + maxtry=$((${maxtry}-1))
1165 + echo -n "."
1166 + sleep 1
1167 + done
1168 +
1169 + echo
1170 +
1171 + if [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; then
1172 + # We somehow failed to stop server.
1173 + # However, not a fatal error. Just warn the user.
1174 + ewarn "WARNING: mysqld[$(cat "${pidfile}")] is still running!"
1175 + fi
1176 + fi
1177 +
1178 + einfo "${PN} data directory at '${MY_DATADIR}' successfully initialized!"
1179 +}