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