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