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: Tue, 22 Jun 2021 23:49:34
Message-Id: 1624405481.700b729873e986802aa8ab6da9901c02ce7961c7.whissi@gentoo
1 commit: 700b729873e986802aa8ab6da9901c02ce7961c7
2 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
3 AuthorDate: Tue Jun 22 23:38:53 2021 +0000
4 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
5 CommitDate: Tue Jun 22 23:44:41 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=700b7298
7
8 dev-db/mysql: add OpenSSL 3.0.0 support
9
10 Package-Manager: Portage-3.0.20, Repoman-3.0.3
11 Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>
12
13 dev-db/mysql/Manifest | 2 +
14 dev-db/mysql/mysql-5.7.34-r1.ebuild | 1262 +++++++++++++++++++++++++++++++++++
15 dev-db/mysql/mysql-8.0.25-r1.ebuild | 1192 +++++++++++++++++++++++++++++++++
16 3 files changed, 2456 insertions(+)
17
18 diff --git a/dev-db/mysql/Manifest b/dev-db/mysql/Manifest
19 index 6abf9ac439c..03aa6353eda 100644
20 --- a/dev-db/mysql/Manifest
21 +++ b/dev-db/mysql/Manifest
22 @@ -3,11 +3,13 @@ DIST mysql-5.7.31-patches-01.tar.xz 6664 BLAKE2B 8225f286f0090653f9714545daa95cc
23 DIST mysql-5.7.32-patches-01.tar.xz 6660 BLAKE2B 5c63158615398bdcc4480a0e1b058f491b39ffc7ee33767b425f3b254555411031f64d865e1924afe8aa3926e4cba18049f1219a0a8acc702bc5e011c94fa947 SHA512 bf5e0d27af81e599005268ee243af4cd93f6df95c32cccb268a749322b4e5f73a2ce5d51f0ad1b0e1f2cf4702b8a05e4b2e0b73110fd4aac61f2a0f51bf4952e
24 DIST mysql-5.7.33-patches-01.tar.xz 6672 BLAKE2B cfa410f9ba5a4ba7e43923e7b5940c2dc6a9356b49230ebaea24bd7eef8a9639fc746e917c22241e19c830b81252e95f38e2c9d6054494de700bae46011fb2f4 SHA512 b16bb9531c44f1c5ec9c08aee6c1f5f5d2e3fe59a0039a54f6c050660a18f7c78b955e7eea7bef4e7dccfcdaa81464e0d8e47ac7d0e40ecb90187865a8a0412e
25 DIST mysql-5.7.34-patches-01.tar.xz 6676 BLAKE2B b925880bfbb991fcba81964ff658a2ecab38da637a6093270a724ab8e405ab092d5fb9684f53f44d001e34287366df234b841d9ebcae62d49becdb93a3c3e324 SHA512 80a89f4b4a7ecc04f3115c6aaa0b0013e38c2813fa6dea095e826ef3944298715a48e0deacb691d23526b1524b207c83176290faea2461d3fcd94edabe3d8943
26 +DIST mysql-5.7.34-patches-02.tar.xz 6408 BLAKE2B fdb36247832b6282af94ce2f61b5dd77f6b45f9efca4b438ecd5fed8d810d9d51547d0ae3de085e7f5dcc8795b4bc4f1210902495b92859e1d5aec3048256ef3 SHA512 f0513eb7f0c9e415aa972a53af668939934ea4f4fa438f468f32a46ccc2aa3b84ba8edd999e4786256ada34851ad64c81e9dd0e36c2a21da641987dfd18635c3
27 DIST mysql-8.0.20-patches-01.tar.xz 7176 BLAKE2B 2fc51986c0a4da60521d0e64b9f8705caf8ec3869af930c9729359c3710059fc78aae176523fdf17d10173b404431f31f9bb23ee5c82fba7cbbb4cb39881c005 SHA512 bf8211cf3873f8672b9d3d1dc42b68a1c635690ffdc2d3393eafa83f060ada9f2eaa63f859bf8eecc24976a733d8c7c3b9632ac70f28b5facf48eae921c7ceeb
28 DIST mysql-8.0.21-patches-01.tar.xz 7212 BLAKE2B 2f1b38b3f84a124e3636cb726f3fcef82d71d933e90429dc78be44afeb4f456a37104359c5fd58ab50f0c03c1698e6c79f9b1e07640f0411c0024f558b4e9595 SHA512 3edcbb529b0623adaed30150d88c9b54d1a3e402faf5c7cff4ed626bbf4e5f50838d8f3c79bd2173439d748ded13412ff7fe37e3742c55879ff28907b9eb5660
29 DIST mysql-8.0.22-patches-02.tar.xz 7580 BLAKE2B a50704c3c58b1f67ca86edb233544137927b0ae5fdf302687b48f6fd30fbbd26798e8ef8282662586b25a7240b47278b44f944a8ca59f1a198bc228dd74459c9 SHA512 59f864452e9fdebe4d3990eff8b756e9bbfad58da216b74fa8b7e8391cb0d9d543ca2828591b9ed1ee276c1dec9e1851a8c2683507f0a326c85054e31cc3f950
30 DIST mysql-8.0.23-patches-01.tar.xz 7568 BLAKE2B 222120dcb5556457f382eefbb10f66f46fe1673c64730c8c8a5566942031bc98bab1f1182f747e79e23fccfb6b09197d5c2874aa2087104b6f1eaa25ea9fd60c SHA512 54222c420d57c1b206d920f22738746925ed1e0d78683f01c97cac5bd1d3450f70f784a7f603304b8595fb58120e691f94e28fa1d1884a7cc8bea1d7b177470f
31 DIST mysql-8.0.25-patches-01.tar.xz 3604 BLAKE2B 09cccab204c30d16bdc374bcd01d4a8e6298955f86f479b8e287aab74fb6bd9857547e360be725dfc66acb56e1bb5665277d340761d0110a8823763ad4d2d1f4 SHA512 6d90a34a20e9cbc7e7a9b5b63a1408f33ac8523f2be6c9ab6d9ad7589c3ded83c87e460d782d4d8c33f11b337151fd8db994099e371260ecf204933e844eb50e
32 +DIST mysql-8.0.25-patches-02.tar.xz 6456 BLAKE2B c9c1020a505ebcee836f8dc3bbe540ff924a0174daf36c37b852df267a81919d37581d1c9be037d52cdcd34c27c5c34d3f0af6160857b22d8ab4d8ece37798e0 SHA512 3c3726b397f3a6fb1d84396bb571b4903a167c9a47273b9d5996949e1d3febc96d3528bfa8dfaeea073a245051ae10c983f2ad258268babc91649563ce3cfc00
33 DIST mysql-boost-5.7.27.tar.gz 51436383 BLAKE2B 6db64ab5fa659aae9baa3725a0de9465e48c37618ffd69f34809880c06a00ce55dce77f507810c6fa52d86901facfa42d3d1bd8db1914a779fbc88a69be82497 SHA512 573f4555f3d62bcd3dc2228bcfba023518d462bb6689114a3505ccf7c7c3061d2775a8e7a37ec3c8b9dea6e8fbc56ba599610f237abc38cedff58e75799bdc52
34 DIST mysql-boost-5.7.29.tar.gz 51417554 BLAKE2B 652ce9f99419387e9bcc37afeb1b46438784752e963c3aa1877f17650c31d8b058b4052da97c3a7e9454e758c259d6c311e0518f9a75909fce9741150b82164c SHA512 38acf7c2a10b20c59230ad05cd2cd6996c4c582233c1be573ead08e5c6684275790da07a036570363f89b4d61547b306589b0b98ed5fca70723a3f2cbc21fe11
35 DIST mysql-boost-5.7.30.tar.gz 51363998 BLAKE2B 7897ad74b685c3b30e7ecdf132fdfa72f3416c05e8d0086cb8f7674b6c4f377fff9abc51ed258cc4dfeab50a2cb393af9076d9c1f9a83a26521facbaf223afa1 SHA512 b75d41d0c72d16c6f8d5393dab6e476b7993d296eb5683c12417ce2da3db2052fdab2a152f6e7c545315d21bfa35f26a247cb6cdab83d3418b5d34ed7f5f9560
36
37 diff --git a/dev-db/mysql/mysql-5.7.34-r1.ebuild b/dev-db/mysql/mysql-5.7.34-r1.ebuild
38 new file mode 100644
39 index 00000000000..239a883dba6
40 --- /dev/null
41 +++ b/dev-db/mysql/mysql-5.7.34-r1.ebuild
42 @@ -0,0 +1,1262 @@
43 +# Copyright 1999-2021 Gentoo Authors
44 +# Distributed under the terms of the GNU General Public License v2
45 +
46 +EAPI="7"
47 +
48 +CMAKE_MAKEFILE_GENERATOR=emake
49 +
50 +inherit check-reqs cmake flag-o-matic linux-info \
51 + multiprocessing prefix toolchain-funcs multilib-minimal
52 +
53 +# Patch version
54 +PATCH_SET="https://dev.gentoo.org/~whissi/dist/mysql/${PN}-5.7.34-patches-02.tar.xz"
55 +
56 +SRC_URI="https://cdn.mysql.com/Downloads/MySQL-5.7/${PN}-boost-${PV}.tar.gz
57 + https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-${PV}.tar.gz
58 + http://downloads.mysql.com/archives/MySQL-5.7/${PN}-boost-${PV}.tar.gz
59 + ${PATCH_SET}"
60 +
61 +HOMEPAGE="https://www.mysql.com/"
62 +DESCRIPTION="A fast, multi-threaded, multi-user SQL database server"
63 +LICENSE="GPL-2"
64 +SLOT="5.7/18"
65 +IUSE="cjk client-libs cracklib debug experimental jemalloc latin1 numa +perl profiling
66 + selinux +server static static-libs systemtap tcmalloc test"
67 +
68 +RESTRICT="!test? ( test )"
69 +
70 +REQUIRED_USE="?? ( tcmalloc jemalloc )"
71 +
72 +KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~x64-macos ~x64-solaris ~x86-solaris"
73 +
74 +# Shorten the path because the socket path length must be shorter than 107 chars
75 +# and we will run a mysql server during test phase
76 +S="${WORKDIR}/mysql"
77 +
78 +# Be warned, *DEPEND are version-dependant
79 +# These are used for both runtime and compiletime
80 +# MULTILIB_USEDEP only set for libraries used by the client library
81 +COMMON_DEPEND="
82 + sys-libs/ncurses:0=
83 + client-libs? (
84 + >=sys-libs/zlib-1.2.3:0=[${MULTILIB_USEDEP},static-libs?]
85 + >=dev-libs/openssl-1.0.0:0=[${MULTILIB_USEDEP},static-libs?]
86 + )
87 + !client-libs? (
88 + dev-db/mysql-connector-c[${MULTILIB_USEDEP},static-libs?]
89 + >=sys-libs/zlib-1.2.3:0=
90 + >=dev-libs/openssl-1.0.0:0=
91 + )
92 + server? (
93 + >=app-arch/lz4-0_p131:=
94 + cjk? ( app-text/mecab:= )
95 + experimental? (
96 + dev-libs/libevent:=[ssl]
97 + dev-libs/protobuf:=
98 + net-libs/libtirpc:=
99 + )
100 + jemalloc? ( dev-libs/jemalloc:0= )
101 + kernel_linux? (
102 + dev-libs/libaio:0=
103 + sys-process/procps:0=
104 + )
105 + numa? ( sys-process/numactl )
106 + )
107 + systemtap? ( >=dev-util/systemtap-1.3:0= )
108 + tcmalloc? ( dev-util/google-perftools:0= )
109 +"
110 +
111 +DEPEND="
112 + ${COMMON_DEPEND}
113 + || ( >=sys-devel/gcc-3.4.6 >=sys-devel/gcc-apple-4.0 )
114 + dev-libs/protobuf
115 + virtual/yacc
116 + server? (
117 + dev-libs/libevent:=[ssl]
118 + experimental? ( net-libs/rpcsvc-proto )
119 + )
120 + static? ( sys-libs/ncurses[static-libs] )
121 + test? (
122 + acct-group/mysql acct-user/mysql
123 + dev-perl/JSON
124 + )
125 +"
126 +
127 +RDEPEND="
128 + ${COMMON_DEPEND}
129 + !dev-db/mariadb !dev-db/mariadb-galera !dev-db/percona-server !dev-db/mysql-cluster
130 + !dev-db/mysql:0
131 + !dev-db/mysql:8.0
132 + client-libs? ( !dev-db/mariadb-connector-c[mysqlcompat] !dev-db/mysql-connector-c dev-libs/protobuf:= )
133 + selinux? ( sec-policy/selinux-mysql )
134 + server? (
135 + !prefix? (
136 + acct-group/mysql acct-user/mysql
137 + dev-db/mysql-init-scripts
138 + )
139 + )
140 +"
141 +
142 +# For other stuff to bring us in
143 +# dev-perl/DBD-mysql is needed by some scripts installed by MySQL
144 +PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
145 +
146 +mysql_init_vars() {
147 + : ${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
148 + : ${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
149 + : ${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
150 + : ${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
151 + MY_DATADIR="${MY_LOCALSTATEDIR}"
152 +
153 + export MY_SHAREDSTATEDIR MY_SYSCONFDIR
154 + export MY_LOCALSTATEDIR MY_LOGDIR
155 + export MY_DATADIR
156 +}
157 +
158 +pkg_pretend() {
159 + if [[ ${MERGE_TYPE} != binary ]] ; then
160 + if use server ; then
161 + CHECKREQS_DISK_BUILD="3G"
162 +
163 + if has test $FEATURES ; then
164 + CHECKREQS_DISK_BUILD="9G"
165 + fi
166 +
167 + check-reqs_pkg_pretend
168 + fi
169 + fi
170 +}
171 +
172 +pkg_setup() {
173 + if [[ ${MERGE_TYPE} != binary ]] ; then
174 + CHECKREQS_DISK_BUILD="3G"
175 +
176 + if has test ${FEATURES} ; then
177 + CHECKREQS_DISK_BUILD="9G"
178 +
179 + # Bug #213475 - MySQL _will_ object strenuously if your machine is named
180 + # localhost. Also causes weird failures.
181 + [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
182 +
183 + if ! has userpriv ${FEATURES} ; then
184 + die "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
185 + fi
186 +
187 + local aio_max_nr=$(sysctl -n fs.aio-max-nr 2>/dev/null)
188 + [[ -z "${aio_max_nr}" || ${aio_max_nr} -lt 250000 ]] \
189 + && die "FEATURES=test will require fs.aio-max-nr=250000 at minimum!"
190 +
191 + if use latin1 ; then
192 + # Upstream only supports tests with default charset
193 + die "Testing with USE=latin1 is not supported."
194 + fi
195 + fi
196 +
197 + if use kernel_linux ; then
198 + if use numa ; then
199 + linux-info_get_any_version
200 +
201 + local CONFIG_CHECK="~NUMA"
202 +
203 + local WARNING_NUMA="This package expects NUMA support in kernel which this system does not have at the moment;"
204 + WARNING_NUMA+=" Either expect runtime errors, enable NUMA support in kernel or rebuild the package without NUMA support"
205 +
206 + check_extra_config
207 + fi
208 + fi
209 +
210 + use server && check-reqs_pkg_setup
211 + fi
212 +}
213 +
214 +pkg_preinst() {
215 + # Here we need to see if the implementation switched client libraries
216 + # We check if this is a new instance of the package and a client library already exists
217 + local SHOW_ABI_MESSAGE libpath
218 + if use client-libs && [[ -z ${REPLACING_VERSIONS} && -e "${EROOT}/usr/$(get_libdir)/libmysqlclient.so" ]] ; then
219 + libpath=$(readlink "${EROOT}/usr/$(get_libdir)/libmysqlclient.so")
220 + elog "Due to ABI changes when switching between different client libraries,"
221 + elog "revdep-rebuild must find and rebuild all packages linking to libmysqlclient."
222 + elog "Please run: revdep-rebuild --library ${libpath}"
223 + ewarn "Failure to run revdep-rebuild may cause issues with other programs or libraries"
224 + fi
225 +}
226 +
227 +pkg_postinst() {
228 + # Make sure the vars are correctly initialized
229 + mysql_init_vars
230 +
231 + # Create log directory securely if it does not exist
232 + [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
233 +
234 + if use server ; then
235 + if [[ -z "${REPLACING_VERSIONS}" ]] ; then
236 + einfo
237 + elog "You might want to run:"
238 + elog "\"emerge --config =${CATEGORY}/${PF}\""
239 + elog "if this is a new install."
240 + elog
241 + elog "If you are switching server implentations, you should run the"
242 + elog "mysql_upgrade tool."
243 + einfo
244 + else
245 + einfo
246 + elog "If you are upgrading major versions, you should run the"
247 + elog "mysql_upgrade tool."
248 + einfo
249 + fi
250 + fi
251 +
252 + # Note about configuration change
253 + einfo
254 + elog "This version of ${PN} reorganizes the configuration from a single my.cnf"
255 + elog "to several files in /etc/mysql/mysql.d."
256 + elog "Please backup any changes you made to /etc/mysql/my.cnf"
257 + elog "and add them as a new file under /etc/mysql/mysql.d with a .cnf extension."
258 + elog "You may have as many files as needed and they are read alphabetically."
259 + elog "Be sure the options have the appropriate section headers, i.e. [mysqld]."
260 + einfo
261 +}
262 +
263 +src_unpack() {
264 + unpack ${A}
265 +
266 + mv -f "${WORKDIR}/${P}" "${S}" || die
267 +}
268 +
269 +src_prepare() {
270 + eapply "${WORKDIR}"/mysql-patches
271 +
272 + if use jemalloc ; then
273 + echo "TARGET_LINK_LIBRARIES(mysqld jemalloc)" >> "${S}/sql/CMakeLists.txt" || die
274 + fi
275 +
276 + if use tcmalloc ; then
277 + echo "TARGET_LINK_LIBRARIES(mysqld tcmalloc)" >> "${S}/sql/CMakeLists.txt" || die
278 + fi
279 +
280 + # Remove the centos and rhel selinux policies to support mysqld_safe under SELinux
281 + if [[ -d "${S}/support-files/SELinux" ]] ; then
282 + echo > "${S}/support-files/SELinux/CMakeLists.txt" || die
283 + fi
284 +
285 + # Remove bundled libs so we cannot accidentally use them
286 + # We keep extra/lz4 directory because we use extra/lz4/xxhash.c via sql/CMakeLists.txt:394
287 + rm -rv \
288 + "${S}"/extra/protobuf \
289 + "${S}"/extra/libevent \
290 + "${S}"/zlib \
291 + || die
292 +
293 + # Don't clash with dev-db/mysql-connector-c
294 + rm \
295 + man/my_print_defaults.1 \
296 + man/perror.1 \
297 + man/zlib_decompress.1 \
298 + || die
299 +
300 + sed -i 's~ADD_SUBDIRECTORY(storage/ndb)~~' CMakeLists.txt || die
301 +
302 + cmake_src_prepare
303 +}
304 +
305 +src_configure() {
306 + # Bug #114895, bug #110149
307 + filter-flags "-O" "-O[01]"
308 +
309 + append-cxxflags -felide-constructors
310 +
311 + # code is not C++17 ready, bug #786402
312 + append-cxxflags -std=c++14
313 +
314 + # bug #283926, with GCC4.4, this is required to get correct behavior.
315 + append-flags -fno-strict-aliasing
316 +
317 + if use client-libs ; then
318 + multilib-minimal_src_configure
319 + else
320 + multilib_src_configure
321 + fi
322 +}
323 +
324 +multilib_src_configure() {
325 + debug-print-function ${FUNCNAME} "$@"
326 +
327 + if ! multilib_is_native_abi && ! use client-libs ; then
328 + return
329 + fi
330 +
331 + CMAKE_BUILD_TYPE="RelWithDebInfo"
332 +
333 + # debug hack wrt #497532
334 + mycmakeargs=(
335 + -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
336 + -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
337 + -DMYSQL_DATADIR="${EPREFIX}/var/lib/mysql"
338 + -DSYSCONFDIR="${EPREFIX}/etc/mysql"
339 + -DINSTALL_BINDIR=bin
340 + -DINSTALL_DOCDIR=share/doc/${PF}
341 + -DINSTALL_DOCREADMEDIR=share/doc/${PF}
342 + -DINSTALL_INCLUDEDIR=include/mysql
343 + -DINSTALL_INFODIR=share/info
344 + -DINSTALL_LIBDIR=$(get_libdir)
345 + -DINSTALL_MANDIR=share/man
346 + -DINSTALL_MYSQLSHAREDIR=share/mysql
347 + -DINSTALL_PLUGINDIR=$(get_libdir)/mysql/plugin
348 + -DINSTALL_SCRIPTDIR=share/mysql/scripts
349 + -DINSTALL_MYSQLDATADIR="${EPREFIX}/var/lib/mysql"
350 + -DINSTALL_SBINDIR=sbin
351 + -DINSTALL_SUPPORTFILESDIR="${EPREFIX}/usr/share/mysql"
352 + -DCOMPILATION_COMMENT="Gentoo Linux ${PF}"
353 + -DWITH_UNIT_TESTS=$(usex test ON OFF)
354 + ### TODO: make this system but issues with UTF-8 prevent it
355 + -DWITH_EDITLINE=bundled
356 + -DWITH_ZLIB=system
357 + -DWITH_SSL=system
358 + -DWITH_LIBWRAP=0
359 + -DENABLED_LOCAL_INFILE=1
360 + -DMYSQL_UNIX_ADDR="${EPREFIX}/var/run/mysqld/mysqld.sock"
361 + -DWITH_DEFAULT_COMPILER_OPTIONS=0
362 + -DWITH_DEFAULT_FEATURE_SET=0
363 + # The build forces this to be defined when cross-compiling. We pass it
364 + # all the time for simplicity and to make sure it is actually correct.
365 + -DSTACK_DIRECTION=$(tc-stack-grows-down && echo -1 || echo 1)
366 + -DWITH_CURL=system
367 + -DWITH_BOOST="${S}/boost"
368 + )
369 + if use test ; then
370 + mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test )
371 + else
372 + mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
373 + fi
374 +
375 + if ! use client-libs ; then
376 + mycmakeargs+=( -DWITHOUT_CLIENTLIBS=YES )
377 + fi
378 +
379 + # bfd.h is only used starting with 10.1 and can be controlled by NOT_FOR_DISTRIBUTION
380 + # systemtap only works on native ABI, bug 530132
381 + if multilib_is_native_abi ; then
382 + mycmakeargs+=(
383 + -DENABLE_DTRACE=$(usex systemtap)
384 + )
385 + else
386 + mycmakeargs+=(
387 + -DWITHOUT_TOOLS=1
388 + -DWITH_READLINE=1
389 + -DENABLE_DTRACE=0
390 + )
391 + fi
392 +
393 + if multilib_is_native_abi && use server ; then
394 + mycmakeargs+=(
395 + -DWITH_LIBEVENT=system
396 + -DWITH_LZ4=system
397 + -DWITH_PROTOBUF=system
398 + -DWITH_MECAB=$(usex cjk system OFF)
399 + -DWITH_NUMA=$(usex numa ON OFF)
400 + -DWITH_RAPID=$(usex experimental ON OFF)
401 + )
402 +
403 + if [[ ( -n ${MYSQL_DEFAULT_CHARSET} ) && ( -n ${MYSQL_DEFAULT_COLLATION} ) ]] ; then
404 + ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
405 + ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
406 + ewarn "You MUST file bugs without these variables set."
407 +
408 + mycmakeargs+=(
409 + -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
410 + -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
411 + )
412 + elif ! use latin1 ; then
413 + mycmakeargs+=(
414 + -DDEFAULT_CHARSET=utf8
415 + -DDEFAULT_COLLATION=utf8_general_ci
416 + )
417 + else
418 + mycmakeargs+=(
419 + -DDEFAULT_CHARSET=latin1
420 + -DDEFAULT_COLLATION=latin1_swedish_ci
421 + )
422 + fi
423 +
424 + mycmakeargs+=(
425 + -DEXTRA_CHARSETS=all
426 + -DDISABLE_SHARED=$(usex static YES NO)
427 + -DWITH_DEBUG=$(usex debug)
428 + -DWITH_EMBEDDED_SERVER=OFF
429 + )
430 +
431 + if use profiling ; then
432 + # Setting to OFF doesn't work: Once set, profiling options will be added
433 + # to `mysqld --help` output via sql/sys_vars.cc causing
434 + # "main.mysqld--help-notwin" test to fail
435 + mycmakeargs+=( -DENABLED_PROFILING=ON )
436 + fi
437 +
438 + if use static ; then
439 + mycmakeargs+=( -DWITH_PIC=1 )
440 + fi
441 +
442 + # Storage engines
443 + mycmakeargs+=(
444 + -DWITH_EXAMPLE_STORAGE_ENGINE=0
445 + -DWITH_ARCHIVE_STORAGE_ENGINE=1
446 + -DWITH_BLACKHOLE_STORAGE_ENGINE=1
447 + -DWITH_CSV_STORAGE_ENGINE=1
448 + -DWITH_FEDERATED_STORAGE_ENGINE=1
449 + -DWITH_HEAP_STORAGE_ENGINE=1
450 + -DWITH_INNOBASE_STORAGE_ENGINE=1
451 + -DWITH_INNODB_MEMCACHED=0
452 + -DWITH_MYISAMMRG_STORAGE_ENGINE=1
453 + -DWITH_MYISAM_STORAGE_ENGINE=1
454 + -DWITH_PARTITION_STORAGE_ENGINE=1
455 + )
456 +
457 + else
458 + mycmakeargs+=(
459 + -DWITHOUT_SERVER=1
460 + -DWITH_EMBEDDED_SERVER=OFF
461 + -DEXTRA_CHARSETS=none
462 + )
463 + fi
464 +
465 + cmake_src_configure
466 +}
467 +
468 +src_compile() {
469 + if use client-libs ; then
470 + multilib-minimal_src_compile
471 + else
472 + multilib_src_compile
473 + fi
474 +}
475 +
476 +multilib_src_compile() {
477 + cmake_src_compile
478 +}
479 +
480 +# Official test instructions:
481 +# ulimit -n 16500 && \
482 +# USE='latin1 perl server' \
483 +# FEATURES='test userpriv -usersandbox' \
484 +# ebuild mysql-X.X.XX.ebuild \
485 +# digest clean package
486 +src_test() {
487 + _disable_test() {
488 + local rawtestname reason
489 + rawtestname="${1}" ; shift
490 + reason="${@}"
491 + ewarn "test '${rawtestname}' disabled: '${reason}'"
492 + echo ${rawtestname} : ${reason} >> "${T}/disabled.def"
493 + }
494 +
495 + local TESTDIR="${BUILD_DIR}/mysql-test"
496 + local retstatus_unit
497 + local retstatus_tests
498 +
499 + if ! use server ; then
500 + einfo "Skipping server tests due to minimal build."
501 + return 0
502 + fi
503 +
504 + einfo ">>> Test phase [test]: ${CATEGORY}/${PF}"
505 +
506 + # Run CTest (test-units)
507 + cmake_src_test
508 + retstatus_unit=$?
509 +
510 + # Ensure that parallel runs don't die
511 + export MTR_BUILD_THREAD="$((${RANDOM} % 100))"
512 +
513 + if [[ -z "${MTR_PARALLEL}" ]] ; then
514 + local -x MTR_PARALLEL=$(makeopts_jobs)
515 +
516 + if [[ ${MTR_PARALLEL} -gt 4 ]] ; then
517 + # Running multiple tests in parallel usually require higher ulimit
518 + # and fs.aio-max-nr setting. In addition, tests like main.multi_update
519 + # are known to hit timeout when system is busy.
520 + # To avoid test failure we will limit MTR_PARALLEL to 4 instead of
521 + # using "auto".
522 + local info_msg="Parallel MySQL test suite jobs limited to 4 (MAKEOPTS=${MTR_PARALLEL})"
523 + info_msg+=" to avoid test failures. Set MTR_PARALLEL if you know what you are doing!"
524 + einfo "${info_msg}"
525 + unset info_msg
526 + MTR_PARALLEL=4
527 + fi
528 + else
529 + einfo "MTR_PARALLEL is set to '${MTR_PARALLEL}'"
530 + fi
531 +
532 + # >=dev-libs/openssl-3 defaults to security level 1 which disallow
533 + # TLSv1/1.1 but tests will require TLSv1/1.1.
534 + einfo "Set OpenSSL configuration for test suite ..."
535 + cat > "${T}/openssl_tlsv1.cnf" <<- EOF || die
536 + openssl_conf = default_conf
537 +
538 + [default_conf]
539 + ssl_conf = ssl_sect
540 +
541 + [ssl_sect]
542 + system_default = system_default_sect
543 +
544 + [system_default_sect]
545 + CipherString = DEFAULT@SECLEVEL=0
546 + EOF
547 +
548 + local -x OPENSSL_CONF="${T}/openssl_tlsv1.cnf"
549 +
550 + # create directories because mysqladmin might run out of order
551 + mkdir -p "${T}"/var-tests{,/log} || die
552 +
553 + # Run mysql tests
554 + pushd "${TESTDIR}" &>/dev/null || die
555 +
556 + touch "${T}/disabled.def"
557 + # These are failing in MySQL 5.7 for now and are believed to be
558 + # false positives:
559 + #
560 + local t
561 +
562 + for t in \
563 + auth_sec.keyring_udf \
564 + innodb.import_compress_encrypt \
565 + perfschema.privilege_table_io \
566 + ; do
567 + _disable_test "$t" "False positives in Gentoo"
568 + done
569 +
570 + # Unstable tests
571 + # - main.xa_prepared_binlog_off: https://bugs.mysql.com/bug.php?id=83340
572 + # - rpl.rpl_innodb_info_tbl_slave_tmp_tbl_mismatch: https://bugs.mysql.com/bug.php?id=89223
573 + # - rpl.rpl_non_direct_stm_mixing_engines: MDEV-14489
574 + for t in \
575 + main.xa_prepared_binlog_off \
576 + rpl.rpl_innodb_info_tbl_slave_tmp_tbl_mismatch \
577 + rpl.rpl_non_direct_stm_mixing_engines \
578 + ; do
579 + _disable_test "$t" "Unstable test"
580 + done
581 +
582 + for t in \
583 + gis.geometry_class_attri_prop \
584 + gis.geometry_property_function_issimple \
585 + gis.gis_bugs_crashes \
586 + gis.spatial_op_testingfunc_mix \
587 + gis.spatial_analysis_functions_buffer \
588 + gis.spatial_analysis_functions_distance \
589 + gis.spatial_utility_function_distance_sphere \
590 + gis.spatial_utility_function_simplify \
591 + gis.spatial_analysis_functions_centroid \
592 + main.with_recursive \
593 + ; do
594 + _disable_test "$t" "Known rounding error with latest AMD processors"
595 + done
596 +
597 + if ! hash zip 1>/dev/null 2>&1 ; then
598 + # no need to force dep app-arch/zip for one test
599 + _disable_test "innodb.partition_upgrade_create" "Requires app-arch/zip"
600 + fi
601 +
602 + if use numa && use kernel_linux ; then
603 + # bug 584880
604 + if ! linux_config_exists || ! linux_chkconfig_present NUMA ; then
605 + for t in sys_vars.innodb_numa_interleave_basic ; do
606 + _disable_test "$t" "Test $t requires system with NUMA support"
607 + done
608 + fi
609 + fi
610 +
611 + if ! use latin1 ; then
612 + # The following tests will fail if DEFAULT_CHARSET
613 + # isn't set to latin1:
614 + for t in \
615 + binlog.binlog_mysqlbinlog_filter \
616 + binlog.binlog_xa_prepared_disconnect \
617 + funcs_1.is_columns_mysql \
618 + funcs_1.is_tables_mysql \
619 + funcs_1.is_triggers \
620 + innodb.innodb_pagesize_max_recordsize \
621 + innodb.innodb-system-table-view \
622 + innodb.mysqldump_max_recordsize \
623 + main.mysql_client_test \
624 + main.mysqld--help-notwin \
625 + main.mysqldump_bugs \
626 + main.type_string \
627 + main.information_schema \
628 + perfschema.binlog_edge_mix \
629 + perfschema.binlog_edge_stmt \
630 + rpl.rpl_xa_survive_disconnect \
631 + rpl.rpl_xa_survive_disconnect_lsu_off \
632 + rpl.rpl_xa_survive_disconnect_table \
633 + ; do
634 + _disable_test "$t" "Requires DEFAULT_CHARSET=latin1 but USE=-latin1 is set"
635 + done
636 + fi
637 +
638 + if has_version '>=dev-libs/openssl-1.1.1' ; then
639 + # Tests are expecting <openssl-1.1.1 default cipher
640 + for t in \
641 + auth_sec.cert_verify \
642 + auth_sec.mysql_ssl_connection \
643 + auth_sec.openssl_cert_generation \
644 + auth_sec.ssl_auto_detect \
645 + auth_sec.ssl_mode \
646 + auth_sec.tls \
647 + binlog.binlog_grant_alter_user \
648 + encryption.innodb_onlinealter_encryption \
649 + main.grant_alter_user_qa \
650 + main.grant_user_lock_qa \
651 + main.mysql_ssl_default \
652 + main.openssl_1 \
653 + main.plugin_auth_sha256 \
654 + main.plugin_auth_sha256_2 \
655 + main.plugin_auth_sha256_server_default \
656 + main.plugin_auth_sha256_server_default_tls \
657 + main.plugin_auth_sha256_tls \
658 + main.ssl \
659 + main.ssl_8k_key \
660 + main.ssl_bug75311 \
661 + main.ssl_ca \
662 + main.ssl_cipher \
663 + main.ssl_compress \
664 + main.ssl_crl \
665 + main.ssl_ecdh \
666 + main.ssl_verify_identity \
667 + x.connection_tls_version \
668 + x.connection_openssl \
669 + ; do
670 + _disable_test "$t" "Requires <dev-libs/openssl-1.1.1"
671 + done
672 + fi
673 +
674 + # Try to increase file limits to increase test coverage
675 + if ! ulimit -n 16500 1>/dev/null 2>&1 ; then
676 + # Upper limit comes from parts.partition_* tests
677 + ewarn "For maximum test coverage please raise open file limit to 16500 (ulimit -n 16500) before calling the package manager."
678 +
679 + if ! ulimit -n 4162 1>/dev/null 2>&1 ; then
680 + # Medium limit comes from '[Warning] Buffered warning: Could not increase number of max_open_files to more than 3000 (request: 4162)'
681 + ewarn "For medium test coverage please raise open file limit to 4162 (ulimit -n 4162) before calling the package manager."
682 +
683 + if ! ulimit -n 3000 1>/dev/null 2>&1 ; then
684 + ewarn "For minimum test coverage please raise open file limit to 3000 (ulimit -n 3000) before calling the package manager."
685 + else
686 + einfo "Will run test suite with open file limit set to 3000 (minimum test coverage)."
687 + fi
688 + else
689 + einfo "Will run test suite with open file limit set to 4162 (medium test coverage)."
690 + fi
691 + else
692 + einfo "Will run test suite with open file limit set to 16500 (best test coverage)."
693 + fi
694 +
695 + # run mysql-test tests
696 + perl mysql-test-run.pl --force --vardir="${T}/var-tests" --reorder --skip-test=tokudb --skip-test-list="${T}/disabled.def"
697 + retstatus_tests=$?
698 +
699 + popd &>/dev/null || die
700 +
701 + # Cleanup is important for these testcases.
702 + pkill -9 -f "${S}/ndb" 2>/dev/null
703 + pkill -9 -f "${S}/sql" 2>/dev/null
704 +
705 + local failures=""
706 + [[ $retstatus_unit -eq 0 ]] || failures="${failures} test-unit"
707 + [[ $retstatus_tests -eq 0 ]] || failures="${failures} tests"
708 +
709 + [[ -z "$failures" ]] || die "Test failures: $failures"
710 + einfo "Tests successfully completed"
711 +}
712 +
713 +src_install() {
714 + local MULTILIB_WRAPPED_HEADERS
715 + local MULTILIB_CHOST_TOOLS
716 + if use client-libs ; then
717 + # headers with ABI specific data
718 + MULTILIB_WRAPPED_HEADERS=(
719 + /usr/include/mysql/server/my_config.h
720 + /usr/include/mysql/server/mysql_version.h )
721 +
722 + # wrap the config scripts
723 + MULTILIB_CHOST_TOOLS=( /usr/bin/mysql_config )
724 + multilib-minimal_src_install
725 + else
726 + multilib_src_install
727 + multilib_src_install_all
728 + fi
729 +}
730 +
731 +# Intentionally override eclass function
732 +multilib_src_install() {
733 + cmake_src_install
734 +
735 + # Kill old libmysqclient_r symlinks if they exist. Time to fix what depends on them.
736 + find "${D}" -name 'libmysqlclient_r.*' -type l -delete || die
737 +}
738 +
739 +multilib_src_install_all() {
740 + # Make sure the vars are correctly initialized
741 + mysql_init_vars
742 +
743 + # Convenience links
744 + einfo "Making Convenience links for mysqlcheck multi-call binary"
745 + dosym "mysqlcheck" "/usr/bin/mysqlanalyze"
746 + dosym "mysqlcheck" "/usr/bin/mysqlrepair"
747 + dosym "mysqlcheck" "/usr/bin/mysqloptimize"
748 +
749 + # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
750 + if [[ -d "${ED}/usr/data" ]] ; then
751 + rm -Rf "${ED}/usr/data" || die
752 + fi
753 +
754 + # Unless they explicitly specific USE=test, then do not install the
755 + # testsuite. It DOES have a use to be installed, esp. when you want to do a
756 + # validation of your database configuration after tuning it.
757 + if ! use test ; then
758 + rm -rf "${D}/${MY_SHAREDSTATEDIR}/mysql-test"
759 + fi
760 +
761 + # Configuration stuff
762 + einfo "Building default configuration ..."
763 + insinto "${MY_SYSCONFDIR#${EPREFIX}}"
764 + [[ -f "${S}/scripts/mysqlaccess.conf" ]] && doins "${S}"/scripts/mysqlaccess.conf
765 + cp "${FILESDIR}/my.cnf-5.7" "${TMPDIR}/my.cnf" || die
766 + eprefixify "${TMPDIR}/my.cnf"
767 + doins "${TMPDIR}/my.cnf"
768 + insinto "${MY_SYSCONFDIR#${EPREFIX}}/mysql.d"
769 + cp "${FILESDIR}/my.cnf.distro-client" "${TMPDIR}/50-distro-client.cnf" || die
770 + eprefixify "${TMPDIR}/50-distro-client.cnf"
771 + doins "${TMPDIR}/50-distro-client.cnf"
772 +
773 + if use server ; then
774 + mycnf_src="my.cnf.distro-server"
775 + sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
776 + "${FILESDIR}/${mycnf_src}" \
777 + > "${TMPDIR}/my.cnf.ok" || die
778 +
779 + if use prefix ; then
780 + sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' \
781 + "${TMPDIR}/my.cnf.ok" || die
782 + fi
783 +
784 + if use latin1 ; then
785 + sed -i \
786 + -e "/character-set/s|utf8|latin1|g" \
787 + "${TMPDIR}/my.cnf.ok" || die
788 + fi
789 +
790 + eprefixify "${TMPDIR}/my.cnf.ok"
791 +
792 + newins "${TMPDIR}/my.cnf.ok" 50-distro-server.cnf
793 + fi
794 +
795 + #Remove mytop if perl is not selected
796 + [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
797 +}
798 +
799 +pkg_config() {
800 + _getoptval() {
801 + local section="$1"
802 + local flag="--${2}="
803 + local extra_options="${3}"
804 + local cmd=(
805 + "${my_print_defaults_binary}"
806 + "${extra_options}"
807 + "${section}"
808 + )
809 + local results=( $(eval "${cmd[@]}" 2>/dev/null | sed -n "/^${flag}/s,${flag},,gp") )
810 +
811 + if [[ ${#results[@]} -gt 0 ]] ; then
812 + # When option is set multiple times only return last value
813 + echo "${results[-1]}"
814 + fi
815 + }
816 +
817 + _mktemp_dry() {
818 + # emktemp has no --dry-run option
819 + local template="${1}"
820 +
821 + if [[ -z "${template}" ]] ; then
822 + if [[ -z "${T}" ]] ; then
823 + template="/tmp/XXXXXXX"
824 + else
825 + template="${T}/XXXXXXX"
826 + fi
827 + fi
828 +
829 + local template_wo_X=${template//X/}
830 + local n_X
831 + let n_X=${#template}-${#template_wo_X}
832 + if [[ ${n_X} -lt 3 ]] ; then
833 + echo "${FUNCNAME[0]}: too few X's in template ‘${template}’" >&2
834 + return
835 + fi
836 +
837 + local attempts=0
838 + local character tmpfile
839 + while [[ true ]] ; do
840 + let attempts=attempts+1
841 +
842 + new_file=
843 + while read -n1 character ; do
844 + if [[ "${character}" == "X" ]] ; then
845 + tmpfile+="${RANDOM:0:1}"
846 + else
847 + tmpfile+="${character}"
848 + fi
849 + done < <(echo -n "${template}")
850 +
851 + if [[ ! -f "${tmpfile}" ]]
852 + then
853 + echo "${tmpfile}"
854 + return
855 + fi
856 +
857 + if [[ ${attempts} -ge 100 ]] ; then
858 + echo "${FUNCNAME[0]}: Cannot create temporary file after 100 attempts." >&2
859 + return
860 + fi
861 + done
862 + }
863 +
864 + local mysqld_binary="${EROOT}/usr/sbin/mysqld"
865 + if [[ ! -x "${mysqld_binary}" ]] ; then
866 + die "'${mysqld_binary}' not found! Please re-install ${CATEGORY}/${PN}!"
867 + fi
868 +
869 + local mysql_binary="${EROOT}/usr/bin/mysql"
870 + if [[ ! -x "${mysql_binary}" ]] ; then
871 + die "'${mysql_binary}' not found! Please re-install ${CATEGORY}/${PN}!"
872 + fi
873 +
874 + local my_print_defaults_binary="${EROOT}/usr/bin/my_print_defaults"
875 + if [[ ! -x "${my_print_defaults_binary}" ]] ; then
876 + die "'${my_print_defaults_binary}' not found! Please re-install dev-db/mysql-connector-c!"
877 + fi
878 +
879 + if [[ -z "${MYSQL_USER}" ]] ; then
880 + MYSQL_USER=mysql
881 + if use prefix ; then
882 + MYSQL_USER=$(id -u -n 2>/dev/null)
883 + if [[ -z "${MYSQL_USER}" ]] ; then
884 + die "Failed to determine current username!"
885 + fi
886 + fi
887 + fi
888 +
889 + if [[ -z "${MYSQL_GROUP}" ]] ; then
890 + MYSQL_GROUP=mysql
891 + if use prefix ; then
892 + MYSQL_GROUP=$(id -g -n 2>/dev/null)
893 + if [[ -z "${MYSQL_GROUP}" ]] ; then
894 + die "Failed to determine current user groupname!"
895 + fi
896 + fi
897 + fi
898 +
899 + # my_print_defaults needs to read stuff in $HOME/.my.cnf
900 + local -x HOME="${EROOT}/root"
901 +
902 + # Make sure the vars are correctly initialized
903 + mysql_init_vars
904 +
905 + # Read currently set data directory
906 + MY_DATADIR="$(_getoptval mysqld datadir "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
907 +
908 + # Bug #213475 - MySQL _will_ object strenously if your machine is named
909 + # localhost. Also causes weird failures.
910 + [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
911 +
912 + if [[ -z "${MY_DATADIR}" ]] ; then
913 + die "Sorry, unable to find MY_DATADIR!"
914 + elif [[ -d "${MY_DATADIR}/mysql" ]] ; then
915 + ewarn "Looks like your data directory '${MY_DATADIR}' is already initialized!"
916 + ewarn "Please rename or delete its content if you wish to initialize a new data directory."
917 + die "${PN} data directory at '${MY_DATADIR}' looks already initialized!"
918 + fi
919 +
920 + MYSQL_TMPDIR="$(_getoptval mysqld tmpdir "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
921 + MYSQL_TMPDIR=${MYSQL_TMPDIR%/}
922 + # These are dir+prefix
923 + MYSQL_LOG_BIN="$(_getoptval mysqld log-bin "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
924 + MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
925 + MYSQL_RELAY_LOG="$(_getoptval mysqld relay-log "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
926 + MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
927 +
928 + # Create missing directories.
929 + # Always check if mysql user can write to directory even if we just
930 + # created directory because a parent directory might be not
931 + # accessible for that user.
932 + PID_DIR="${EROOT}/run/mysqld"
933 + if [[ ! -d "${PID_DIR}" ]] ; then
934 + einfo "Creating ${PN} PID directory '${PID_DIR}' ..."
935 + install -d -m 755 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${PID_DIR}" \
936 + || die "Failed to create PID directory '${PID_DIR}'!"
937 + fi
938 +
939 + local _pid_dir_testfile="$(_mktemp_dry "${PID_DIR}/.pkg_config-access-test.XXXXXXXXX")"
940 + [[ -z "${_pid_dir_testfile}" ]] \
941 + && die "_mktemp_dry() for '${PID_DIR}/.pkg_config-access-test.XXXXXXXXX' failed!"
942 +
943 + if use prefix ; then
944 + touch "${_pid_dir_testfile}" &>/dev/null
945 + else
946 + su -s /bin/sh -c "touch ${_pid_dir_testfile}" ${MYSQL_USER} &>/dev/null
947 + fi
948 +
949 + if [[ $? -ne 0 ]] ; then
950 + die "${MYSQL_USER} user cannot write into PID dir '${PID_DIR}'!"
951 + else
952 + rm "${_pid_dir_testfile}" || die
953 + unset _pid_dir_testfile
954 + fi
955 +
956 + if [[ ! -d "${MY_DATADIR}" ]] ; then
957 + einfo "Creating ${PN} data directory '${MY_DATADIR}' ..."
958 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MY_DATADIR}" \
959 + || die "Failed to create ${PN} data directory '${MY_DATADIR}'!"
960 + fi
961 +
962 + local _my_datadir_testfile="$(_mktemp_dry "${MY_DATADIR}/.pkg_config-access-test.XXXXXXXXX")"
963 + [[ -z "${_my_datadir_testfile}" ]] \
964 + && die "_mktemp_dry() for '${MY_DATADIR}/.pkg_config-access-test.XXXXXXXXX' failed!"
965 +
966 + if use prefix ; then
967 + touch "${_my_datadir_testfile}" &>/dev/null
968 + else
969 + su -s /bin/sh -c "touch ${_my_datadir_testfile}" ${MYSQL_USER} &>/dev/null
970 + fi
971 +
972 + if [[ $? -ne 0 ]] ; then
973 + die "${MYSQL_USER} user cannot write into data directory '${MY_DATADIR}'!"
974 + else
975 + rm "${_my_datadir_testfile}" || die
976 + unset _my_datadir_testfile
977 + fi
978 +
979 + if [[ -n "${MYSQL_TMPDIR}" && ! -d "${MYSQL_TMPDIR}" ]] ; then
980 + einfo "Creating ${PN} tmpdir '${MYSQL_TMPDIR}' ..."
981 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MYSQL_TMPDIR}" \
982 + || die "Failed to create ${PN} tmpdir '${MYSQL_TMPDIR}'!"
983 + fi
984 +
985 + if [[ -z "${MYSQL_TMPDIR}" ]] ; then
986 + MYSQL_TMPDIR="$(_mktemp_dry "${EROOT}/tmp/mysqld-tmp.XXXXXXXXX")"
987 + [[ -z "${MYSQL_TMPDIR}" ]] \
988 + && die "_mktemp_dry() for '${MYSQL_TMPDIR}' failed!"
989 +
990 + mkdir "${MYSQL_TMPDIR}" || die
991 + chown ${MYSQL_USER} "${MYSQL_TMPDIR}" || die
992 + fi
993 +
994 + # Now we need to test MYSQL_TMPDIR...
995 + local _my_tmpdir_testfile="$(_mktemp_dry "${MYSQL_TMPDIR}/.pkg_config-access-test.XXXXXXXXX")"
996 + [[ -z "${_my_tmpdir_testfile}" ]] \
997 + && die "_mktemp_dry() for '${MYSQL_TMPDIR}/.pkg_config-access-test.XXXXXXXXX' failed!"
998 +
999 + if use prefix ; then
1000 + touch "${_my_tmpdir_testfile}" &>/dev/null
1001 + else
1002 + su -s /bin/sh -c "touch ${_my_tmpdir_testfile}" ${MYSQL_USER} &>/dev/null
1003 + fi
1004 +
1005 + if [[ $? -ne 0 ]] ; then
1006 + die "${MYSQL_USER} user cannot write into tmpdir '${MYSQL_TMPDIR}'!"
1007 + else
1008 + rm "${_my_tmpdir_testfile}" || die
1009 + unset _my_tmpdir_testfile
1010 + fi
1011 +
1012 + if [[ -n "${MYSQL_LOG_BIN}" && ! -d "${MYSQL_LOG_BIN}" ]] ; then
1013 + einfo "Creating ${PN} log-bin directory '${MYSQL_LOG_BIN}' ..."
1014 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MYSQL_LOG_BIN}" \
1015 + || die "Failed to create ${PN} log-bin directory '${MYSQL_LOG_BIN}'"
1016 + fi
1017 +
1018 + if [[ -n "${MYSQL_LOG_BIN}" ]] ; then
1019 + local _my_logbin_testfile="$(_mktemp_dry "${MYSQL_LOG_BIN}/.pkg_config-access-test.XXXXXXXXX")"
1020 + [[ -z "${_my_logbin_testfile}" ]] \
1021 + && die "_mktemp_dry() for '${MYSQL_LOG_BIN}/.pkg_config-access-test.XXXXXXXXX' failed!"
1022 +
1023 + if use prefix ; then
1024 + touch "${_my_logbin_testfile}" &>/dev/null
1025 + else
1026 + su -s /bin/sh -c "touch ${_my_logbin_testfile}" ${MYSQL_USER} &>/dev/null
1027 + fi
1028 +
1029 + if [[ $? -ne 0 ]] ; then
1030 + die "${MYSQL_USER} user cannot write into log-bin directory '${MYSQL_LOG_BIN}'!"
1031 + else
1032 + rm "${_my_logbin_testfile}" || die
1033 + unset _my_logbin_testfile
1034 + fi
1035 + fi
1036 +
1037 + if [[ -n "${MYSQL_RELAY_LOG}" && ! -d "${MYSQL_RELAY_LOG}" ]] ; then
1038 + einfo "Creating ${PN} relay-log directory '${MYSQL_RELAY_LOG}' ..."
1039 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MYSQL_RELAY_LOG}" \
1040 + || die "Failed to create ${PN} relay-log directory '${MYSQL_RELAY_LOG}'!"
1041 + fi
1042 +
1043 + if [[ -n "${MYSQL_RELAY_LOG}" ]] ; then
1044 + local _my_relaylog_testfile="$(_mktemp_dry "${MYSQL_RELAY_LOG}/.pkg_config-access-test.XXXXXXXXX")"
1045 + [[ -z "${_my_relaylog_testfile}" ]] \
1046 + && die "_mktemp_dry() for '${MYSQL_RELAY_LOG}/.pkg_config-access-test.XXXXXXXXX' failed!"
1047 +
1048 + if use prefix ; then
1049 + touch "${_my_relaylog_testfile}" &>/dev/null
1050 + else
1051 + su -s /bin/sh -c "touch ${_my_relaylog_testfile}" ${MYSQL_USER} &>/dev/null
1052 + fi
1053 +
1054 + if [[ $? -ne 0 ]] ; then
1055 + die "${MYSQL_USER} user cannot write into relay-log directory '${MYSQL_RELAY_LOG}'!"
1056 + else
1057 + rm "${_my_relaylog_testfile}" || die
1058 + unset _my_relaylog_testfile
1059 + fi
1060 + fi
1061 +
1062 + local mysql_install_log="$(_mktemp_dry "${MYSQL_TMPDIR}/install_db.XXXXXXXXX.log")"
1063 + if [[ -z "${mysql_install_log}" ]] ; then
1064 + die "_mktemp_dry() for '${MYSQL_TMPDIR}/install_db.XXXXXXXXX.log' failed!"
1065 + else
1066 + # make sure file is writable for MYSQL_USER...
1067 + touch "${mysql_install_log}" || die
1068 + chown ${MYSQL_USER} "${mysql_install_log}" || die
1069 + fi
1070 +
1071 + local mysqld_logfile="$(_mktemp_dry "${MYSQL_TMPDIR}/install_mysqld.XXXXXXXXX.log")"
1072 + if [[ -z "${mysqld_logfile}" ]] ; then
1073 + die "_mktemp_dry() for '${MYSQL_TMPDIR}/install_mysqld.XXXXXXXXX.log' failed!"
1074 + else
1075 + # make sure file is writable for MYSQL_USER...
1076 + touch "${mysqld_logfile}" || die
1077 + chown ${MYSQL_USER} "${mysqld_logfile}" || die
1078 + fi
1079 +
1080 + echo ""
1081 + einfo "Detected settings:"
1082 + einfo "=================="
1083 + einfo "MySQL User:\t\t\t\t${MYSQL_USER}"
1084 + einfo "MySQL Group:\t\t\t\t${MYSQL_GROUP}"
1085 + einfo "MySQL DATA directory:\t\t${MY_DATADIR}"
1086 + einfo "MySQL TMP directory:\t\t\t${MYSQL_TMPDIR}"
1087 +
1088 + if [[ -n "${MYSQL_LOG_BIN}" ]] ; then
1089 + einfo "MySQL Binary Log File location:\t${MYSQL_LOG_BIN}"
1090 + fi
1091 +
1092 + if [[ -n "${MYSQL_RELAY_LOG}" ]] ; then
1093 + einfo "MySQL Relay Log File location:\t${MYSQL_RELAY_LOG}"
1094 + fi
1095 +
1096 + einfo "PID DIR:\t\t\t\t${PID_DIR}"
1097 + einfo "Install db log:\t\t\t${mysql_install_log}"
1098 + einfo "Install server log:\t\t\t${mysqld_logfile}"
1099 +
1100 + if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
1101 + local tmp_mysqld_password_source=
1102 +
1103 + for tmp_mysqld_password_source in mysql client ; do
1104 + einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
1105 + MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password)"
1106 + if [[ -n "${MYSQL_ROOT_PASSWORD}" ]] ; then
1107 + if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]] ; then
1108 + ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
1109 + MYSQL_ROOT_PASSWORD=
1110 + continue
1111 + fi
1112 +
1113 + einfo "Found password in '${tmp_mysqld_password_source}' section!"
1114 + break
1115 + fi
1116 + done
1117 +
1118 + # Sometimes --show is required to display passwords in some implementations of my_print_defaults
1119 + if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]] ; then
1120 + MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password --show)"
1121 + fi
1122 +
1123 + unset tmp_mysqld_password_source
1124 + fi
1125 +
1126 + if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
1127 + local pwd1="a"
1128 + local pwd2="b"
1129 +
1130 + echo
1131 + einfo "No password for mysql 'root' user was specified via environment"
1132 + einfo "variable MYSQL_ROOT_PASSWORD and no password was found in config"
1133 + einfo "file like '${HOME}/.my.cnf'."
1134 + einfo "To continue please provide a password for the mysql 'root' user"
1135 + einfo "now on console:"
1136 + ewarn "NOTE: Please avoid [\"'\\_%] characters in the password!"
1137 + read -rsp " >" pwd1 ; echo
1138 +
1139 + einfo "Retype the password"
1140 + read -rsp " >" pwd2 ; echo
1141 +
1142 + if [[ "x$pwd1" != "x$pwd2" ]] ; then
1143 + die "Passwords are not the same!"
1144 + fi
1145 +
1146 + MYSQL_ROOT_PASSWORD="${pwd1}"
1147 + unset pwd1 pwd2
1148 +
1149 + echo
1150 + fi
1151 +
1152 + local -a mysqld_options
1153 +
1154 + # Fix bug 446200. Don't reference host my.cnf, needs to come first,
1155 + # see http://bugs.mysql.com/bug.php?id=31312
1156 + use prefix && mysqld_options+=( "--defaults-file='${MY_SYSCONFDIR}/my.cnf'" )
1157 +
1158 + # Figure out which options we need to disable to do the setup
1159 + local helpfile="${TMPDIR}/mysqld-help"
1160 + "${EROOT}/usr/sbin/mysqld" --verbose --help >"${helpfile}" 2>/dev/null
1161 +
1162 + local opt optexp optfull
1163 + for opt in host-cache name-resolve networking slave-start \
1164 + federated ssl log-bin relay-log slow-query-log external-locking \
1165 + log-slave-updates \
1166 + ; do
1167 + optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
1168 + egrep -sq -- "${optexp}" "${helpfile}" && mysqld_options+=( "${optfull}" )
1169 + done
1170 +
1171 + # Prepare timezones, see
1172 + # https://dev.mysql.com/doc/mysql/en/time-zone-support.html
1173 + local tz_sql="$(_mktemp_dry "${MYSQL_TMPDIR}/tz.XXXXXXXXX.sql")"
1174 + [[ -z "${tz_sql}" ]] \
1175 + && die "_mktemp_dry() for '${MYSQL_TMPDIR}/tz.XXXXXXXXX.sql' failed!"
1176 +
1177 + echo "USE mysql;" >"${tz_sql}"
1178 + "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" >> "${tz_sql}" 2>/dev/null
1179 + if [[ $? -ne 0 ]] ; then
1180 + die "mysql_tzinfo_to_sql failed!"
1181 + fi
1182 +
1183 + # --initialize-insecure will not set root password
1184 + # --initialize would set a random one in the log which we don't need as we set it ourselves
1185 + local cmd=(
1186 + "${mysqld_binary}"
1187 + "${mysqld_options[@]}"
1188 + "--initialize-insecure"
1189 + "--init-file='${tz_sql}'"
1190 + "--basedir='${EROOT}/usr'"
1191 + "--datadir='${MY_DATADIR}'"
1192 + "--tmpdir='${MYSQL_TMPDIR}'"
1193 + "--log-error='${mysql_install_log}'"
1194 + "--user=${MYSQL_USER}"
1195 + )
1196 +
1197 + einfo "Initializing ${PN} data directory: ${cmd[@]}"
1198 + eval "${cmd[@]}" >>"${mysql_install_log}" 2>&1
1199 +
1200 + if [[ $? -ne 0 ]] ; then
1201 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysql_install_log}" 1>&2
1202 + die "Failed to initialize ${PN} data directory. Please review '${mysql_install_log}'!"
1203 + fi
1204 +
1205 + rm "${tz_sql}" || die
1206 +
1207 + local x=${RANDOM}
1208 + local socket="${EROOT}${PID_DIR}/mysqld${x}.sock"
1209 + local pidfile="${EROOT}${PID_DIR}/mysqld${x}.pid"
1210 + unset x
1211 +
1212 + cmd=(
1213 + "${mysqld_binary}"
1214 + "${mysqld_options[@]}"
1215 + "--basedir='${EROOT}/usr'"
1216 + "--datadir='${MY_DATADIR}'"
1217 + "--tmpdir='${MYSQL_TMPDIR}'"
1218 + --max_allowed_packet=8M
1219 + --net_buffer_length=16K
1220 + "--socket='${socket}'"
1221 + "--pid-file='${pidfile}'"
1222 + "--log-error='${mysqld_logfile}'"
1223 + "--user=${MYSQL_USER}"
1224 + )
1225 +
1226 + einfo "Starting mysqld to finalize initialization: ${cmd[@]}"
1227 + eval "${cmd[@]}" >>"${mysqld_logfile}" 2>&1 &
1228 +
1229 + echo -n "Waiting for mysqld to accept connections "
1230 + local maxtry=15
1231 + while [[ ! -S "${socket}" && "${maxtry}" -gt 1 ]] ; do
1232 + maxtry=$((${maxtry}-1))
1233 + echo -n "."
1234 + sleep 1
1235 + done
1236 +
1237 + if [[ -S "${socket}" ]] ; then
1238 + # Even with a socket we don't know if mysqld will abort
1239 + # start due to an error so just wait a little bit more...
1240 + maxtry=5
1241 + while [[ -S "${socket}" && "${maxtry}" -gt 1 ]] ; do
1242 + maxtry=$((${maxtry}-1))
1243 + echo -n "."
1244 + sleep 1
1245 + done
1246 + fi
1247 +
1248 + echo
1249 +
1250 + if [[ ! -S "${socket}" ]] ; then
1251 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysqld_logfile}" 1>&2
1252 + die "mysqld was unable to start from initialized data directory. Please review '${mysqld_logfile}'!"
1253 + fi
1254 +
1255 + local mysql_logfile="${TMPDIR}/set_root_pw.log"
1256 + touch "${mysql_logfile}" || die
1257 +
1258 + ebegin "Setting root password"
1259 + # Do this from memory, as we don't want clear text passwords in temp files
1260 + local sql="ALTER USER 'root'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}'"
1261 + cmd=(
1262 + "${mysql_binary}"
1263 + --no-defaults
1264 + "--socket='${socket}'"
1265 + -hlocalhost
1266 + "-e \"${sql}\""
1267 + )
1268 + eval "${cmd[@]}" >"${mysql_logfile}" 2>&1
1269 + local rc=$?
1270 + eend ${rc}
1271 +
1272 + if [[ ${rc} -ne 0 ]] ; then
1273 + # Poor man's solution which tries to avoid having password
1274 + # in log. NOTE: sed can fail if user didn't follow advice
1275 + # and included character which will require escaping...
1276 + sed -i -e "s/${MYSQL_ROOT_PASSWORD}/*****/" "${mysql_logfile}" 2>/dev/null
1277 +
1278 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysql_logfile}"
1279 + die "Failed to set ${PN} root password. Please review '${mysql_logfile}'!"
1280 + fi
1281 +
1282 + # Stop the server
1283 + if [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; then
1284 + echo -n "Stopping the server "
1285 + pkill -F "${pidfile}" &>/dev/null
1286 +
1287 + maxtry=10
1288 + while [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; do
1289 + maxtry=$((${maxtry}-1))
1290 + echo -n "."
1291 + sleep 1
1292 + done
1293 +
1294 + echo
1295 +
1296 + if [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; then
1297 + # We somehow failed to stop server.
1298 + # However, not a fatal error. Just warn the user.
1299 + ewarn "WARNING: mysqld[$(cat "${pidfile}")] is still running!"
1300 + fi
1301 + fi
1302 +
1303 + einfo "${PN} data directory at '${MY_DATADIR}' successfully initialized!"
1304 +}
1305
1306 diff --git a/dev-db/mysql/mysql-8.0.25-r1.ebuild b/dev-db/mysql/mysql-8.0.25-r1.ebuild
1307 new file mode 100644
1308 index 00000000000..a3ee94b3523
1309 --- /dev/null
1310 +++ b/dev-db/mysql/mysql-8.0.25-r1.ebuild
1311 @@ -0,0 +1,1192 @@
1312 +# Copyright 1999-2021 Gentoo Authors
1313 +# Distributed under the terms of the GNU General Public License v2
1314 +
1315 +EAPI="7"
1316 +
1317 +CMAKE_MAKEFILE_GENERATOR=emake
1318 +
1319 +inherit check-reqs cmake flag-o-matic linux-info \
1320 + multiprocessing prefix toolchain-funcs
1321 +
1322 +MY_PV="${PV//_pre*}"
1323 +MY_P="${PN}-${MY_PV}"
1324 +
1325 +# Patch version
1326 +PATCH_SET="https://dev.gentoo.org/~whissi/dist/mysql/${PN}-8.0.25-patches-02.tar.xz"
1327 +
1328 +SRC_URI="https://cdn.mysql.com/Downloads/MySQL-8.0/mysql-boost-${MY_PV}.tar.gz
1329 + https://cdn.mysql.com/archives/mysql-8.0/mysql-boost-${MY_PV}.tar.gz
1330 + http://downloads.mysql.com/archives/MySQL-8.0/${PN}-boost-${MY_PV}.tar.gz
1331 + ${PATCH_SET}"
1332 +
1333 +HOMEPAGE="https://www.mysql.com/"
1334 +DESCRIPTION="A fast, multi-threaded, multi-user SQL database server"
1335 +LICENSE="GPL-2"
1336 +SLOT="8.0"
1337 +IUSE="cjk cracklib debug jemalloc latin1 numa +perl profiling
1338 + router selinux +server tcmalloc test"
1339 +
1340 +RESTRICT="!test? ( test )"
1341 +
1342 +REQUIRED_USE="?? ( tcmalloc jemalloc )
1343 + cjk? ( server )
1344 + jemalloc? ( server )
1345 + numa? ( server )
1346 + profiling? ( server )
1347 + router? ( server )
1348 + tcmalloc? ( server )"
1349 +
1350 +KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~x64-macos ~x64-solaris ~x86-solaris"
1351 +
1352 +# Shorten the path because the socket path length must be shorter than 107 chars
1353 +# and we will run a mysql server during test phase
1354 +S="${WORKDIR}/mysql"
1355 +
1356 +# Be warned, *DEPEND are version-dependant
1357 +# These are used for both runtime and compiletime
1358 +COMMON_DEPEND="
1359 + >=app-arch/lz4-0_p131:=
1360 + app-arch/zstd:=
1361 + sys-libs/ncurses:0=
1362 + >=sys-libs/zlib-1.2.3:0=
1363 + >=dev-libs/openssl-1.0.0:0=
1364 + server? (
1365 + dev-libs/icu:=
1366 + dev-libs/libevent:=[ssl,threads]
1367 + >=dev-libs/protobuf-3.8:=
1368 + net-libs/libtirpc:=
1369 + cjk? ( app-text/mecab:= )
1370 + jemalloc? ( dev-libs/jemalloc:0= )
1371 + kernel_linux? (
1372 + dev-libs/libaio:0=
1373 + sys-process/procps:0=
1374 + )
1375 + numa? ( sys-process/numactl )
1376 + tcmalloc? ( dev-util/google-perftools:0= )
1377 + )
1378 +"
1379 +
1380 +DEPEND="
1381 + ${COMMON_DEPEND}
1382 + || ( >=sys-devel/gcc-3.4.6 >=sys-devel/gcc-apple-4.0 )
1383 + virtual/yacc
1384 + server? ( net-libs/rpcsvc-proto )
1385 + test? (
1386 + acct-group/mysql acct-user/mysql
1387 + dev-perl/JSON
1388 + )
1389 +"
1390 +
1391 +RDEPEND="
1392 + ${COMMON_DEPEND}
1393 + !dev-db/mariadb !dev-db/mariadb-galera !dev-db/percona-server !dev-db/mysql-cluster
1394 + !dev-db/mysql:0
1395 + !dev-db/mysql:5.7
1396 + selinux? ( sec-policy/selinux-mysql )
1397 + !prefix? (
1398 + acct-group/mysql acct-user/mysql
1399 + dev-db/mysql-init-scripts
1400 + )
1401 +"
1402 +
1403 +# For other stuff to bring us in
1404 +# dev-perl/DBD-mysql is needed by some scripts installed by MySQL
1405 +PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
1406 +
1407 +mysql_init_vars() {
1408 + : ${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
1409 + : ${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
1410 + : ${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
1411 + : ${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
1412 + MY_DATADIR="${MY_LOCALSTATEDIR}"
1413 +
1414 + export MY_SHAREDSTATEDIR MY_SYSCONFDIR
1415 + export MY_LOCALSTATEDIR MY_LOGDIR
1416 + export MY_DATADIR
1417 +}
1418 +
1419 +pkg_pretend() {
1420 + if [[ ${MERGE_TYPE} != binary ]] ; then
1421 + if use server ; then
1422 + CHECKREQS_DISK_BUILD="2G"
1423 +
1424 + if has test $FEATURES ; then
1425 + CHECKREQS_DISK_BUILD="9G"
1426 + fi
1427 +
1428 + check-reqs_pkg_pretend
1429 + fi
1430 + fi
1431 +}
1432 +
1433 +pkg_setup() {
1434 + if [[ ${MERGE_TYPE} != binary ]] ; then
1435 + CHECKREQS_DISK_BUILD="2G"
1436 +
1437 + if has test ${FEATURES} ; then
1438 + CHECKREQS_DISK_BUILD="9G"
1439 +
1440 + # Bug #213475 - MySQL _will_ object strenuously if your machine is named
1441 + # localhost. Also causes weird failures.
1442 + [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
1443 +
1444 + if ! has userpriv ${FEATURES} ; then
1445 + die "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
1446 + fi
1447 +
1448 + local aio_max_nr=$(sysctl -n fs.aio-max-nr 2>/dev/null)
1449 + [[ -z "${aio_max_nr}" || ${aio_max_nr} -lt 250000 ]] \
1450 + && die "FEATURES=test will require fs.aio-max-nr=250000 at minimum!"
1451 +
1452 + if use latin1 ; then
1453 + # Upstream only supports tests with default charset
1454 + die "Testing with USE=latin1 is not supported."
1455 + fi
1456 + fi
1457 +
1458 + if use kernel_linux ; then
1459 + if use numa ; then
1460 + linux-info_get_any_version
1461 +
1462 + local CONFIG_CHECK="~NUMA"
1463 +
1464 + local WARNING_NUMA="This package expects NUMA support in kernel which this system does not have at the moment;"
1465 + WARNING_NUMA+=" Either expect runtime errors, enable NUMA support in kernel or rebuild the package without NUMA support"
1466 +
1467 + check_extra_config
1468 + fi
1469 + fi
1470 +
1471 + use server && check-reqs_pkg_setup
1472 + fi
1473 +}
1474 +
1475 +src_unpack() {
1476 + unpack ${A}
1477 +
1478 + mv -f "${WORKDIR}/${MY_P}" "${S}" || die
1479 +}
1480 +
1481 +src_prepare() {
1482 + eapply "${WORKDIR}"/mysql-patches
1483 +
1484 + # Avoid rpm call which would trigger sandbox, #692368
1485 + sed -i \
1486 + -e 's/MY_RPM rpm/MY_RPM rpmNOTEXISTENT/' \
1487 + CMakeLists.txt || die
1488 +
1489 + # Remove the centos and rhel selinux policies to support mysqld_safe under SELinux
1490 + if [[ -d "${S}/support-files/SELinux" ]] ; then
1491 + echo > "${S}/support-files/SELinux/CMakeLists.txt" || die
1492 + fi
1493 +
1494 + # Remove man pages for client-lib tools we don't install
1495 + rm \
1496 + man/my_print_defaults.1 \
1497 + man/perror.1 \
1498 + man/zlib_decompress.1 \
1499 + || die
1500 +
1501 + cmake_src_prepare
1502 +}
1503 +
1504 +src_configure() {
1505 + # Bug #114895, bug #110149
1506 + filter-flags "-O" "-O[01]"
1507 +
1508 + append-cxxflags -felide-constructors
1509 +
1510 + # code is not C++17 ready, bug #786402
1511 + append-cxxflags -std=c++14
1512 +
1513 + # bug #283926, with GCC4.4, this is required to get correct behavior.
1514 + append-flags -fno-strict-aliasing
1515 +
1516 + CMAKE_BUILD_TYPE="RelWithDebInfo"
1517 +
1518 + # debug hack wrt #497532
1519 + mycmakeargs=(
1520 + -DCMAKE_C_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
1521 + -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="$(usex debug '' '-DNDEBUG')"
1522 + -DMYSQL_DATADIR="${EPREFIX}/var/lib/mysql"
1523 + -DSYSCONFDIR="${EPREFIX}/etc/mysql"
1524 + -DINSTALL_BINDIR=bin
1525 + -DINSTALL_DOCDIR=share/doc/${PF}
1526 + -DINSTALL_DOCREADMEDIR=share/doc/${PF}
1527 + -DINSTALL_INCLUDEDIR=include/mysql
1528 + -DINSTALL_INFODIR=share/info
1529 + -DINSTALL_LIBDIR=$(get_libdir)
1530 + -DINSTALL_MANDIR=share/man
1531 + -DINSTALL_MYSQLSHAREDIR=share/mysql
1532 + -DINSTALL_PLUGINDIR=$(get_libdir)/mysql/plugin
1533 + -DINSTALL_MYSQLDATADIR="${EPREFIX}/var/lib/mysql"
1534 + -DINSTALL_SBINDIR=sbin
1535 + -DINSTALL_SUPPORTFILESDIR="${EPREFIX}/usr/share/mysql"
1536 + -DCOMPILATION_COMMENT="Gentoo Linux ${PF}"
1537 + -DWITH_UNIT_TESTS=$(usex test ON OFF)
1538 + # Using bundled editline to get CTRL+C working
1539 + -DWITH_EDITLINE=bundled
1540 + -DWITH_ZLIB=system
1541 + -DWITH_SSL=system
1542 + -DWITH_LIBWRAP=0
1543 + -DENABLED_LOCAL_INFILE=1
1544 + -DMYSQL_UNIX_ADDR="${EPREFIX}/var/run/mysqld/mysqld.sock"
1545 + -DWITH_DEFAULT_COMPILER_OPTIONS=0
1546 + # The build forces this to be defined when cross-compiling. We pass it
1547 + # all the time for simplicity and to make sure it is actually correct.
1548 + -DSTACK_DIRECTION=$(tc-stack-grows-down && echo -1 || echo 1)
1549 + -DCMAKE_POSITION_INDEPENDENT_CODE=ON
1550 + -DWITH_CURL=system
1551 + -DWITH_BOOST="${S}/boost"
1552 + -DWITH_ROUTER=$(usex router ON OFF)
1553 + )
1554 +
1555 + if is-flagq -fno-lto ; then
1556 + einfo "LTO disabled via {C,CXX,F,FC}FLAGS"
1557 + mycmakeargs+=( -DWITH_LTO=OFF )
1558 + elif is-flagq -flto ; then
1559 + einfo "LTO forced via {C,CXX,F,FC}FLAGS"
1560 + myconf+=( -DWITH_LTO=ON )
1561 + else
1562 + # Disable automagic
1563 + myconf+=( -DWITH_LTO=OFF )
1564 + fi
1565 +
1566 + if use test ; then
1567 + mycmakeargs+=( -DINSTALL_MYSQLTESTDIR=share/mysql/mysql-test )
1568 + else
1569 + mycmakeargs+=( -DINSTALL_MYSQLTESTDIR='' )
1570 + fi
1571 +
1572 + mycmakeargs+=( -DWITHOUT_CLIENTLIBS=YES )
1573 +
1574 + mycmakeargs+=(
1575 + -DWITH_ICU=system
1576 + -DWITH_LZ4=system
1577 + # Our dev-libs/rapidjson doesn't carry necessary fixes for std::regex
1578 + -DWITH_RAPIDJSON=bundled
1579 + -DWITH_ZSTD=system
1580 + )
1581 +
1582 + if [[ -n "${MYSQL_DEFAULT_CHARSET}" && -n "${MYSQL_DEFAULT_COLLATION}" ]] ; then
1583 + ewarn "You are using a custom charset of ${MYSQL_DEFAULT_CHARSET}"
1584 + ewarn "and a collation of ${MYSQL_DEFAULT_COLLATION}."
1585 + ewarn "You MUST file bugs without these variables set."
1586 + ewarn "Tests will probably fail!"
1587 +
1588 + mycmakeargs+=(
1589 + -DDEFAULT_CHARSET=${MYSQL_DEFAULT_CHARSET}
1590 + -DDEFAULT_COLLATION=${MYSQL_DEFAULT_COLLATION}
1591 + )
1592 + elif use latin1 ; then
1593 + mycmakeargs+=(
1594 + -DDEFAULT_CHARSET=latin1
1595 + -DDEFAULT_COLLATION=latin1_swedish_ci
1596 + )
1597 + else
1598 + mycmakeargs+=(
1599 + -DDEFAULT_CHARSET=utf8mb4
1600 + -DDEFAULT_COLLATION=utf8mb4_0900_ai_ci
1601 + )
1602 + fi
1603 +
1604 + if use server ; then
1605 + mycmakeargs+=(
1606 + -DWITH_EXTRA_CHARSETS=all
1607 + -DWITH_DEBUG=$(usex debug)
1608 + -DWITH_MECAB=$(usex cjk system OFF)
1609 + -DWITH_LIBEVENT=system
1610 + -DWITH_PROTOBUF=system
1611 + -DWITH_NUMA=$(usex numa ON OFF)
1612 + )
1613 +
1614 + if use jemalloc ; then
1615 + mycmakeargs+=( -DWITH_JEMALLOC=ON )
1616 + elif use tcmalloc ; then
1617 + mycmakeargs+=( -DWITH_TCMALLOC=ON )
1618 + fi
1619 +
1620 + if use profiling ; then
1621 + # Setting to OFF doesn't work: Once set, profiling options will be added
1622 + # to `mysqld --help` output via sql/sys_vars.cc causing
1623 + # "main.mysqld--help-notwin" test to fail
1624 + mycmakeargs+=( -DENABLED_PROFILING=ON )
1625 + fi
1626 +
1627 + # Storage engines
1628 + mycmakeargs+=(
1629 + -DWITH_EXAMPLE_STORAGE_ENGINE=0
1630 + -DWITH_ARCHIVE_STORAGE_ENGINE=1
1631 + -DWITH_BLACKHOLE_STORAGE_ENGINE=1
1632 + -DWITH_CSV_STORAGE_ENGINE=1
1633 + -DWITH_FEDERATED_STORAGE_ENGINE=1
1634 + -DWITH_HEAP_STORAGE_ENGINE=1
1635 + -DWITH_INNOBASE_STORAGE_ENGINE=1
1636 + -DWITH_INNODB_MEMCACHED=0
1637 + -DWITH_MYISAMMRG_STORAGE_ENGINE=1
1638 + -DWITH_MYISAM_STORAGE_ENGINE=1
1639 + )
1640 + else
1641 + mycmakeargs+=(
1642 + -DWITHOUT_SERVER=1
1643 + -DWITH_SYSTEMD=no
1644 + )
1645 + fi
1646 +
1647 + cmake_src_configure
1648 +}
1649 +
1650 +# Official test instructions:
1651 +# ulimit -n 16500 && \
1652 +# USE='perl server' \
1653 +# FEATURES='test userpriv' \
1654 +# ebuild mysql-X.X.XX.ebuild \
1655 +# digest clean package
1656 +src_test() {
1657 + _disable_test() {
1658 + local rawtestname bug reason
1659 + rawtestname="${1}" ; shift
1660 + bug="${1}" ; shift
1661 + reason="${@}"
1662 + ewarn "test '${rawtestname}' disabled: '${reason}' (BUG#${bug})"
1663 + echo ${rawtestname} : BUG#${bug} ${reason} >> "${T}/disabled.def"
1664 + }
1665 +
1666 + local TESTDIR="${BUILD_DIR}/mysql-test"
1667 + local retstatus_unit
1668 + local retstatus_tests
1669 +
1670 + # Run CTest (test-units)
1671 + cmake_src_test
1672 + retstatus_unit=$?
1673 +
1674 + # Ensure that parallel runs don't die
1675 + export MTR_BUILD_THREAD="$((${RANDOM} % 100))"
1676 +
1677 + if [[ -z "${MTR_PARALLEL}" ]] ; then
1678 + local -x MTR_PARALLEL=$(makeopts_jobs)
1679 +
1680 + if [[ ${MTR_PARALLEL} -gt 4 ]] ; then
1681 + # Running multiple tests in parallel usually require higher ulimit
1682 + # and fs.aio-max-nr setting. In addition, tests like main.multi_update
1683 + # are known to hit timeout when system is busy.
1684 + # To avoid test failure we will limit MTR_PARALLEL to 4 instead of
1685 + # using "auto".
1686 + local info_msg="Parallel MySQL test suite jobs limited to 4 (MAKEOPTS=${MTR_PARALLEL})"
1687 + info_msg+=" to avoid test failures. Set MTR_PARALLEL if you know what you are doing!"
1688 + einfo "${info_msg}"
1689 + unset info_msg
1690 + MTR_PARALLEL=4
1691 + fi
1692 + else
1693 + einfo "MTR_PARALLEL is set to '${MTR_PARALLEL}'"
1694 + fi
1695 +
1696 + # >=dev-libs/openssl-3 defaults to security level 1 which disallow
1697 + # TLSv1/1.1 but tests will require TLSv1/1.1.
1698 + einfo "Set OpenSSL configuration for test suite ..."
1699 + cat > "${T}/openssl_tlsv1.cnf" <<- EOF || die
1700 + openssl_conf = default_conf
1701 +
1702 + [default_conf]
1703 + ssl_conf = ssl_sect
1704 +
1705 + [ssl_sect]
1706 + system_default = system_default_sect
1707 +
1708 + [system_default_sect]
1709 + CipherString = DEFAULT@SECLEVEL=0
1710 + EOF
1711 +
1712 + local -x OPENSSL_CONF="${T}/openssl_tlsv1.cnf"
1713 +
1714 + # create directories because mysqladmin might run out of order
1715 + mkdir -p "${T}"/var-tests{,/log} || die
1716 +
1717 + # Run mysql tests
1718 + pushd "${TESTDIR}" &>/dev/null || die
1719 +
1720 + touch "${T}/disabled.def"
1721 +
1722 + local -a disabled_tests
1723 + disabled_tests+=( "auth_sec.atomic_rename_user;103512;Depends on user running test" )
1724 + disabled_tests+=( "auth_sec.keyring_file_data_qa;0;Won't work with user privileges" )
1725 + disabled_tests+=( "gis.spatial_analysis_functions_buffer;5452;Known rounding error with latest AMD processors (PS)" )
1726 + disabled_tests+=( "gis.gis_bugs_crashes;5452;Known rounding error with latest AMD processors (PS)" )
1727 + disabled_tests+=( "gis.geometry_class_attri_prop;5452;Known rounding error with latest AMD processors (PS)" )
1728 + disabled_tests+=( "gis.spatial_utility_function_distance_sphere;5452;Known rounding error with latest AMD processors (PS)" )
1729 + disabled_tests+=( "gis.geometry_property_function_issimple;5452;Known rounding error with latest AMD processors (PS)" )
1730 + disabled_tests+=( "gis.spatial_analysis_functions_centroid;5452;Known rounding error with latest AMD processors (PS)" )
1731 + disabled_tests+=( "gis.spatial_operators_intersection;5452;Known rounding error with latest AMD processors (PS)" )
1732 + disabled_tests+=( "gis.spatial_utility_function_simplify;5452;Known rounding error with latest AMD processors (PS)" )
1733 + disabled_tests+=( "gis.spatial_op_testingfunc_mix;5452;Known rounding error with latest AMD processors (PS)" )
1734 + disabled_tests+=( "gis.spatial_analysis_functions_distance;5452;Known rounding error with latest AMD processors (PS)" )
1735 + disabled_tests+=( "main.explain_tree;0;Known rounding error with latest AMD processors -- no upstream bug yet" )
1736 + disabled_tests+=( "main.derived_limit;0;Known rounding error with latest AMD processors -- no upstream bug yet" )
1737 + disabled_tests+=( "main.mysql_load_data_local_dir;0;Known test failure - no upstream bug yet" )
1738 + disabled_tests+=( "main.subquery_bugs;0;Known rounding error with latest AMD processors -- no upstream bug yet" )
1739 + disabled_tests+=( "main.subquery_sj_mat_bka_nobnl;0;Known rounding error with latest AMD processors -- no upstream bug yet" )
1740 + disabled_tests+=( "main.window_std_var;0;Known rounding error with latest AMD processors -- no upstream bug yet" )
1741 + disabled_tests+=( "main.window_std_var_optimized;0;Known rounding error with latest AMD processors -- no upstream bug yet" )
1742 + disabled_tests+=( "main.with_recursive;0;Known rounding error with latest AMD processors -- no upstream bug yet" )
1743 + disabled_tests+=( "perfschema.statement_digest_query_sample;0;Test will fail on slow hardware")
1744 + disabled_tests+=( "rpl_gtid.rpl_gtid_stm_drop_table;90612;Known test failure" )
1745 + disabled_tests+=( "rpl_gtid.rpl_multi_source_mtr_includes;0;Known failure - no upstream bug yet" )
1746 + disabled_tests+=( "rpl.rpl_innodb_info_tbl_slave_tmp_tbl_mismatch;0;Unstable test" )
1747 + disabled_tests+=( "sys_vars.myisam_data_pointer_size_func;87935;Test will fail on slow hardware")
1748 + disabled_tests+=( "x.connection;0;Known failure - no upstream bug yet" )
1749 + disabled_tests+=( "main.mysqlpump_basic_lz4;0;Extra tool output causes false positive" )
1750 + disabled_tests+=( "x.message_compressed_payload;0;False positive caused by protobuff-3.11+" )
1751 + disabled_tests+=( "x.message_protobuf_nested;0;False positive caused by protobuff-3.11+" )
1752 +
1753 + if ! hash zip 1>/dev/null 2>&1 ; then
1754 + # no need to force dep app-arch/zip for one test
1755 + disabled_tests+=( "innodb.discarded_partition_create;0;Requires app-arch/zip" )
1756 + disabled_tests+=( "innodb.partition_upgrade_create;0;Requires app-arch/zip" )
1757 + fi
1758 +
1759 + if has_version ">=dev-libs/openssl-3" ; then
1760 + # no need to force dep app-arch/zip for one test
1761 + disabled_tests+=( "x.connection_tls_version;0;Not compatible with OpenSSL 3.x error messages" )
1762 + fi
1763 +
1764 + local test_infos_str test_infos_arr
1765 + for test_infos_str in "${disabled_tests[@]}" ; do
1766 + IFS=';' read -r -a test_infos_arr <<< "${test_infos_str}"
1767 +
1768 + if [[ ${#test_infos_arr[@]} != 3 ]] ; then
1769 + die "Invalid test data set, not matching format: ${test_infos_str}"
1770 + fi
1771 +
1772 + _disable_test "${test_infos_arr[0]}" "${test_infos_arr[1]}" "${test_infos_arr[2]}"
1773 + done
1774 + unset test_infos_str test_infos_arr
1775 +
1776 + # Try to increase file limits to increase test coverage
1777 + if ! ulimit -n 16500 1>/dev/null 2>&1 ; then
1778 + # Upper limit comes from parts.partition_* tests
1779 + ewarn "For maximum test coverage please raise open file limit to 16500 (ulimit -n 16500) before calling the package manager."
1780 +
1781 + if ! ulimit -n 4162 1>/dev/null 2>&1 ; then
1782 + # Medium limit comes from '[Warning] Buffered warning: Could not increase number of max_open_files to more than 3000 (request: 4162)'
1783 + ewarn "For medium test coverage please raise open file limit to 4162 (ulimit -n 4162) before calling the package manager."
1784 +
1785 + if ! ulimit -n 3000 1>/dev/null 2>&1 ; then
1786 + ewarn "For minimum test coverage please raise open file limit to 3000 (ulimit -n 3000) before calling the package manager."
1787 + else
1788 + einfo "Will run test suite with open file limit set to 3000 (minimum test coverage)."
1789 + fi
1790 + else
1791 + einfo "Will run test suite with open file limit set to 4162 (medium test coverage)."
1792 + fi
1793 + else
1794 + einfo "Will run test suite with open file limit set to 16500 (best test coverage)."
1795 + fi
1796 +
1797 + # run mysql-test tests
1798 + perl mysql-test-run.pl --force --vardir="${T}/var-tests" --reorder --skip-test=tokudb --skip-test-list="${T}/disabled.def"
1799 + retstatus_tests=$?
1800 +
1801 + popd &>/dev/null || die
1802 +
1803 + # Cleanup is important for these testcases.
1804 + pkill -9 -f "${S}/ndb" 2>/dev/null
1805 + pkill -9 -f "${S}/sql" 2>/dev/null
1806 +
1807 + local failures=""
1808 + [[ $retstatus_unit -eq 0 ]] || failures="${failures} test-unit"
1809 + [[ $retstatus_tests -eq 0 ]] || failures="${failures} tests"
1810 +
1811 + [[ -z "$failures" ]] || die "Test failures: $failures"
1812 + einfo "Tests successfully completed"
1813 +}
1814 +
1815 +src_install() {
1816 + cmake_src_install
1817 +
1818 + # Make sure the vars are correctly initialized
1819 + mysql_init_vars
1820 +
1821 + # Convenience links
1822 + einfo "Making Convenience links for mysqlcheck multi-call binary"
1823 + dosym "mysqlcheck" "/usr/bin/mysqlanalyze"
1824 + dosym "mysqlcheck" "/usr/bin/mysqlrepair"
1825 + dosym "mysqlcheck" "/usr/bin/mysqloptimize"
1826 +
1827 + # INSTALL_LAYOUT=STANDALONE causes cmake to create a /usr/data dir
1828 + if [[ -d "${ED}/usr/data" ]] ; then
1829 + rm -Rf "${ED}/usr/data" || die
1830 + fi
1831 +
1832 + # Unless they explicitly specific USE=test, then do not install the
1833 + # testsuite. It DOES have a use to be installed, esp. when you want to do a
1834 + # validation of your database configuration after tuning it.
1835 + if ! use test ; then
1836 + rm -rf "${ED}/${MY_SHAREDSTATEDIR#${EPREFIX}}/mysql-test"
1837 + fi
1838 +
1839 + # Configuration stuff
1840 + einfo "Building default configuration ..."
1841 + insinto "${MY_SYSCONFDIR#${EPREFIX}}"
1842 + [[ -f "${S}/scripts/mysqlaccess.conf" ]] && doins "${S}"/scripts/mysqlaccess.conf
1843 + cp "${FILESDIR}/my.cnf-5.7" "${TMPDIR}/my.cnf" || die
1844 + eprefixify "${TMPDIR}/my.cnf"
1845 + doins "${TMPDIR}/my.cnf"
1846 + insinto "${MY_SYSCONFDIR#${EPREFIX}}/mysql.d"
1847 + cp "${FILESDIR}/my.cnf-8.0.distro-client" "${TMPDIR}/50-distro-client.cnf" || die
1848 + eprefixify "${TMPDIR}/50-distro-client.cnf"
1849 + doins "${TMPDIR}/50-distro-client.cnf"
1850 +
1851 + mycnf_src="my.cnf-8.0.distro-server"
1852 + sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
1853 + "${FILESDIR}/${mycnf_src}" \
1854 + > "${TMPDIR}/my.cnf.ok" || die
1855 +
1856 + if use prefix ; then
1857 + sed -i -r -e '/^user[[:space:]]*=[[:space:]]*mysql$/d' \
1858 + "${TMPDIR}/my.cnf.ok" || die
1859 + fi
1860 +
1861 + if use latin1 ; then
1862 + sed -i \
1863 + -e "/character-set/s|utf8mb4|latin1|g" \
1864 + "${TMPDIR}/my.cnf.ok" || die
1865 + fi
1866 +
1867 + eprefixify "${TMPDIR}/my.cnf.ok"
1868 +
1869 + newins "${TMPDIR}/my.cnf.ok" 50-distro-server.cnf
1870 +
1871 + #Remove mytop if perl is not selected
1872 + [[ -e "${ED}/usr/bin/mytop" ]] && ! use perl && rm -f "${ED}/usr/bin/mytop"
1873 +
1874 + if use router ; then
1875 + rm -rf \
1876 + "${ED}/usr/LICENSE.router" \
1877 + "${ED}/usr/README.router" \
1878 + "${ED}/usr/run" \
1879 + "${ED}/usr/var" \
1880 + || die
1881 + fi
1882 +
1883 + # Kill old libmysqclient_r symlinks if they exist. Time to fix what depends on them.
1884 + find "${D}" -name 'libmysqlclient_r.*' -type l -delete || die
1885 +}
1886 +
1887 +pkg_postinst() {
1888 + # Make sure the vars are correctly initialized
1889 + mysql_init_vars
1890 +
1891 + # Create log directory securely if it does not exist
1892 + # NOTE: $MY_LOGDIR contains $EPREFIX by default
1893 + [[ -d "${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${MY_LOGDIR}"
1894 +
1895 + # Note about configuration change
1896 + einfo
1897 + elog "This version of ${PN} reorganizes the configuration from a single my.cnf"
1898 + elog "to several files in /etc/mysql/mysql.d."
1899 + elog "Please backup any changes you made to /etc/mysql/my.cnf"
1900 + elog "and add them as a new file under /etc/mysql/mysql.d with a .cnf extension."
1901 + elog "You may have as many files as needed and they are read alphabetically."
1902 + elog "Be sure the options have the appropriate section headers, i.e. [mysqld]."
1903 + einfo
1904 +
1905 + if [[ -z "${REPLACING_VERSIONS}" ]] ; then
1906 + einfo
1907 + elog "You might want to run:"
1908 + elog " \"emerge --config =${CATEGORY}/${PF}\""
1909 + elog "if this is a new install."
1910 + einfo
1911 + else
1912 + einfo
1913 + elog "Upgrade process for ${PN}-8.x has changed. Please read"
1914 + elog "https://dev.mysql.com/doc/refman/8.0/en/upgrade-binary-package.html"
1915 + einfo
1916 + fi
1917 +}
1918 +
1919 +pkg_config() {
1920 + _getoptval() {
1921 + local section="$1"
1922 + local flag="--${2}="
1923 + local extra_options="${3}"
1924 + local cmd=(
1925 + "${my_print_defaults_binary}"
1926 + "${extra_options}"
1927 + "${section}"
1928 + )
1929 + local results=( $(eval "${cmd[@]}" 2>/dev/null | sed -n "/^${flag}/s,${flag},,gp") )
1930 +
1931 + if [[ ${#results[@]} -gt 0 ]] ; then
1932 + # When option is set multiple times only return last value
1933 + echo "${results[-1]}"
1934 + fi
1935 + }
1936 +
1937 + _mktemp_dry() {
1938 + # emktemp has no --dry-run option
1939 + local template="${1}"
1940 +
1941 + if [[ -z "${template}" ]] ; then
1942 + if [[ -z "${T}" ]] ; then
1943 + template="/tmp/XXXXXXX"
1944 + else
1945 + template="${T}/XXXXXXX"
1946 + fi
1947 + fi
1948 +
1949 + local template_wo_X=${template//X/}
1950 + local n_X
1951 + let n_X=${#template}-${#template_wo_X}
1952 + if [[ ${n_X} -lt 3 ]] ; then
1953 + echo "${FUNCNAME[0]}: too few X's in template ‘${template}’" >&2
1954 + return
1955 + fi
1956 +
1957 + local attempts=0
1958 + local character tmpfile
1959 + while [[ true ]] ; do
1960 + let attempts=attempts+1
1961 +
1962 + new_file=
1963 + while read -n1 character ; do
1964 + if [[ "${character}" == "X" ]] ; then
1965 + tmpfile+="${RANDOM:0:1}"
1966 + else
1967 + tmpfile+="${character}"
1968 + fi
1969 + done < <(echo -n "${template}")
1970 +
1971 + if [[ ! -f "${tmpfile}" ]]
1972 + then
1973 + echo "${tmpfile}"
1974 + return
1975 + fi
1976 +
1977 + if [[ ${attempts} -ge 100 ]] ; then
1978 + echo "${FUNCNAME[0]}: Cannot create temporary file after 100 attempts." >&2
1979 + return
1980 + fi
1981 + done
1982 + }
1983 +
1984 + local mysqld_binary="${EROOT}/usr/sbin/mysqld"
1985 + if [[ ! -x "${mysqld_binary}" ]] ; then
1986 + die "'${mysqld_binary}' not found! Please re-install ${CATEGORY}/${PN}!"
1987 + fi
1988 +
1989 + local mysql_binary="${EROOT}/usr/bin/mysql"
1990 + if [[ ! -x "${mysql_binary}" ]] ; then
1991 + die "'${mysql_binary}' not found! Please re-install ${CATEGORY}/${PN}!"
1992 + fi
1993 +
1994 + local my_print_defaults_binary="${EROOT}/usr/bin/my_print_defaults"
1995 + if [[ ! -x "${my_print_defaults_binary}" ]] ; then
1996 + die "'${my_print_defaults_binary}' not found! Please re-install dev-db/mysql-connector-c!"
1997 + fi
1998 +
1999 + if [[ -z "${MYSQL_USER}" ]] ; then
2000 + MYSQL_USER=mysql
2001 + if use prefix ; then
2002 + MYSQL_USER=$(id -u -n 2>/dev/null)
2003 + if [[ -z "${MYSQL_USER}" ]] ; then
2004 + die "Failed to determine current username!"
2005 + fi
2006 + fi
2007 + fi
2008 +
2009 + if [[ -z "${MYSQL_GROUP}" ]] ; then
2010 + MYSQL_GROUP=mysql
2011 + if use prefix ; then
2012 + MYSQL_GROUP=$(id -g -n 2>/dev/null)
2013 + if [[ -z "${MYSQL_GROUP}" ]] ; then
2014 + die "Failed to determine current user groupname!"
2015 + fi
2016 + fi
2017 + fi
2018 +
2019 + # my_print_defaults needs to read stuff in $HOME/.my.cnf
2020 + local -x HOME="${EROOT}/root"
2021 +
2022 + # Make sure the vars are correctly initialized
2023 + mysql_init_vars
2024 +
2025 + # Read currently set data directory
2026 + MY_DATADIR="$(_getoptval mysqld datadir "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
2027 +
2028 + # Bug #213475 - MySQL _will_ object strenously if your machine is named
2029 + # localhost. Also causes weird failures.
2030 + [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
2031 +
2032 + if [[ -z "${MY_DATADIR}" ]] ; then
2033 + die "Sorry, unable to find MY_DATADIR!"
2034 + elif [[ -d "${MY_DATADIR}/mysql" ]] ; then
2035 + ewarn "Looks like your data directory '${MY_DATADIR}' is already initialized!"
2036 + ewarn "Please rename or delete its content if you wish to initialize a new data directory."
2037 + die "${PN} data directory at '${MY_DATADIR}' looks already initialized!"
2038 + fi
2039 +
2040 + MYSQL_TMPDIR="$(_getoptval mysqld tmpdir "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
2041 + MYSQL_TMPDIR=${MYSQL_TMPDIR%/}
2042 + # These are dir+prefix
2043 + MYSQL_LOG_BIN="$(_getoptval mysqld log-bin "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
2044 + MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
2045 + MYSQL_RELAY_LOG="$(_getoptval mysqld relay-log "--defaults-file='${MY_SYSCONFDIR}/my.cnf'")"
2046 + MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
2047 +
2048 + # Create missing directories.
2049 + # Always check if mysql user can write to directory even if we just
2050 + # created directory because a parent directory might be not
2051 + # accessible for that user.
2052 + PID_DIR="${EROOT}/run/mysqld"
2053 + if [[ ! -d "${PID_DIR}" ]] ; then
2054 + einfo "Creating ${PN} PID directory '${PID_DIR}' ..."
2055 + install -d -m 755 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${PID_DIR}" \
2056 + || die "Failed to create PID directory '${PID_DIR}'!"
2057 + fi
2058 +
2059 + local _pid_dir_testfile="$(_mktemp_dry "${PID_DIR}/.pkg_config-access-test.XXXXXXXXX")"
2060 + [[ -z "${_pid_dir_testfile}" ]] \
2061 + && die "_mktemp_dry() for '${PID_DIR}/.pkg_config-access-test.XXXXXXXXX' failed!"
2062 +
2063 + if use prefix ; then
2064 + touch "${_pid_dir_testfile}" &>/dev/null
2065 + else
2066 + su -s /bin/sh -c "touch ${_pid_dir_testfile}" ${MYSQL_USER} &>/dev/null
2067 + fi
2068 +
2069 + if [[ $? -ne 0 ]] ; then
2070 + die "${MYSQL_USER} user cannot write into PID dir '${PID_DIR}'!"
2071 + else
2072 + rm "${_pid_dir_testfile}" || die
2073 + unset _pid_dir_testfile
2074 + fi
2075 +
2076 + if [[ ! -d "${MY_DATADIR}" ]] ; then
2077 + einfo "Creating ${PN} data directory '${MY_DATADIR}' ..."
2078 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MY_DATADIR}" \
2079 + || die "Failed to create ${PN} data directory '${MY_DATADIR}'!"
2080 + fi
2081 +
2082 + local _my_datadir_testfile="$(_mktemp_dry "${MY_DATADIR}/.pkg_config-access-test.XXXXXXXXX")"
2083 + [[ -z "${_my_datadir_testfile}" ]] \
2084 + && die "_mktemp_dry() for '${MY_DATADIR}/.pkg_config-access-test.XXXXXXXXX' failed!"
2085 +
2086 + if use prefix ; then
2087 + touch "${_my_datadir_testfile}" &>/dev/null
2088 + else
2089 + su -s /bin/sh -c "touch ${_my_datadir_testfile}" ${MYSQL_USER} &>/dev/null
2090 + fi
2091 +
2092 + if [[ $? -ne 0 ]] ; then
2093 + die "${MYSQL_USER} user cannot write into data directory '${MY_DATADIR}'!"
2094 + else
2095 + rm "${_my_datadir_testfile}" || die
2096 + unset _my_datadir_testfile
2097 + fi
2098 +
2099 + if [[ -n "${MYSQL_TMPDIR}" && ! -d "${MYSQL_TMPDIR}" ]] ; then
2100 + einfo "Creating ${PN} tmpdir '${MYSQL_TMPDIR}' ..."
2101 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MYSQL_TMPDIR}" \
2102 + || die "Failed to create ${PN} tmpdir '${MYSQL_TMPDIR}'!"
2103 + fi
2104 +
2105 + if [[ -z "${MYSQL_TMPDIR}" ]] ; then
2106 + MYSQL_TMPDIR="$(_mktemp_dry "${EROOT}/tmp/mysqld-tmp.XXXXXXXXX")"
2107 + [[ -z "${MYSQL_TMPDIR}" ]] \
2108 + && die "_mktemp_dry() for '${MYSQL_TMPDIR}' failed!"
2109 +
2110 + mkdir "${MYSQL_TMPDIR}" || die
2111 + chown ${MYSQL_USER} "${MYSQL_TMPDIR}" || die
2112 + fi
2113 +
2114 + # Now we need to test MYSQL_TMPDIR...
2115 + local _my_tmpdir_testfile="$(_mktemp_dry "${MYSQL_TMPDIR}/.pkg_config-access-test.XXXXXXXXX")"
2116 + [[ -z "${_my_tmpdir_testfile}" ]] \
2117 + && die "_mktemp_dry() for '${MYSQL_TMPDIR}/.pkg_config-access-test.XXXXXXXXX' failed!"
2118 +
2119 + if use prefix ; then
2120 + touch "${_my_tmpdir_testfile}" &>/dev/null
2121 + else
2122 + su -s /bin/sh -c "touch ${_my_tmpdir_testfile}" ${MYSQL_USER} &>/dev/null
2123 + fi
2124 +
2125 + if [[ $? -ne 0 ]] ; then
2126 + die "${MYSQL_USER} user cannot write into tmpdir '${MYSQL_TMPDIR}'!"
2127 + else
2128 + rm "${_my_tmpdir_testfile}" || die
2129 + unset _my_tmpdir_testfile
2130 + fi
2131 +
2132 + if [[ -n "${MYSQL_LOG_BIN}" && ! -d "${MYSQL_LOG_BIN}" ]] ; then
2133 + einfo "Creating ${PN} log-bin directory '${MYSQL_LOG_BIN}' ..."
2134 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MYSQL_LOG_BIN}" \
2135 + || die "Failed to create ${PN} log-bin directory '${MYSQL_LOG_BIN}'"
2136 + fi
2137 +
2138 + if [[ -n "${MYSQL_LOG_BIN}" ]] ; then
2139 + local _my_logbin_testfile="$(_mktemp_dry "${MYSQL_LOG_BIN}/.pkg_config-access-test.XXXXXXXXX")"
2140 + [[ -z "${_my_logbin_testfile}" ]] \
2141 + && die "_mktemp_dry() for '${MYSQL_LOG_BIN}/.pkg_config-access-test.XXXXXXXXX' failed!"
2142 +
2143 + if use prefix ; then
2144 + touch "${_my_logbin_testfile}" &>/dev/null
2145 + else
2146 + su -s /bin/sh -c "touch ${_my_logbin_testfile}" ${MYSQL_USER} &>/dev/null
2147 + fi
2148 +
2149 + if [[ $? -ne 0 ]] ; then
2150 + die "${MYSQL_USER} user cannot write into log-bin directory '${MYSQL_LOG_BIN}'!"
2151 + else
2152 + rm "${_my_logbin_testfile}" || die
2153 + unset _my_logbin_testfile
2154 + fi
2155 + fi
2156 +
2157 + if [[ -n "${MYSQL_RELAY_LOG}" && ! -d "${MYSQL_RELAY_LOG}" ]] ; then
2158 + einfo "Creating ${PN} relay-log directory '${MYSQL_RELAY_LOG}' ..."
2159 + install -d -m 770 -o ${MYSQL_USER} -g ${MYSQL_GROUP} "${MYSQL_RELAY_LOG}" \
2160 + || die "Failed to create ${PN} relay-log directory '${MYSQL_RELAY_LOG}'!"
2161 + fi
2162 +
2163 + if [[ -n "${MYSQL_RELAY_LOG}" ]] ; then
2164 + local _my_relaylog_testfile="$(_mktemp_dry "${MYSQL_RELAY_LOG}/.pkg_config-access-test.XXXXXXXXX")"
2165 + [[ -z "${_my_relaylog_testfile}" ]] \
2166 + && die "_mktemp_dry() for '${MYSQL_RELAY_LOG}/.pkg_config-access-test.XXXXXXXXX' failed!"
2167 +
2168 + if use prefix ; then
2169 + touch "${_my_relaylog_testfile}" &>/dev/null
2170 + else
2171 + su -s /bin/sh -c "touch ${_my_relaylog_testfile}" ${MYSQL_USER} &>/dev/null
2172 + fi
2173 +
2174 + if [[ $? -ne 0 ]] ; then
2175 + die "${MYSQL_USER} user cannot write into relay-log directory '${MYSQL_RELAY_LOG}'!"
2176 + else
2177 + rm "${_my_relaylog_testfile}" || die
2178 + unset _my_relaylog_testfile
2179 + fi
2180 + fi
2181 +
2182 + local mysql_install_log="$(_mktemp_dry "${MYSQL_TMPDIR}/install_db.XXXXXXXXX.log")"
2183 + if [[ -z "${mysql_install_log}" ]] ; then
2184 + die "_mktemp_dry() for '${MYSQL_TMPDIR}/install_db.XXXXXXXXX.log' failed!"
2185 + else
2186 + # make sure file is writable for MYSQL_USER...
2187 + touch "${mysql_install_log}" || die
2188 + chown ${MYSQL_USER} "${mysql_install_log}" || die
2189 + fi
2190 +
2191 + local mysqld_logfile="$(_mktemp_dry "${MYSQL_TMPDIR}/install_mysqld.XXXXXXXXX.log")"
2192 + if [[ -z "${mysqld_logfile}" ]] ; then
2193 + die "_mktemp_dry() for '${MYSQL_TMPDIR}/install_mysqld.XXXXXXXXX.log' failed!"
2194 + else
2195 + # make sure file is writable for MYSQL_USER...
2196 + touch "${mysqld_logfile}" || die
2197 + chown ${MYSQL_USER} "${mysqld_logfile}" || die
2198 + fi
2199 +
2200 + echo ""
2201 + einfo "Detected settings:"
2202 + einfo "=================="
2203 + einfo "MySQL User:\t\t\t\t${MYSQL_USER}"
2204 + einfo "MySQL Group:\t\t\t\t${MYSQL_GROUP}"
2205 + einfo "MySQL DATA directory:\t\t${MY_DATADIR}"
2206 + einfo "MySQL TMP directory:\t\t\t${MYSQL_TMPDIR}"
2207 +
2208 + if [[ -n "${MYSQL_LOG_BIN}" ]] ; then
2209 + einfo "MySQL Binary Log File location:\t${MYSQL_LOG_BIN}"
2210 + fi
2211 +
2212 + if [[ -n "${MYSQL_RELAY_LOG}" ]] ; then
2213 + einfo "MySQL Relay Log File location:\t${MYSQL_RELAY_LOG}"
2214 + fi
2215 +
2216 + einfo "PID DIR:\t\t\t\t${PID_DIR}"
2217 + einfo "Install db log:\t\t\t${mysql_install_log}"
2218 + einfo "Install server log:\t\t\t${mysqld_logfile}"
2219 +
2220 + local -a config_files
2221 +
2222 + local config_file="${EROOT}/etc/mysql/mysql.d/50-distro-client.cnf"
2223 + if [[ -f "${config_file}" ]] ; then
2224 + config_files+=( "${config_file}" )
2225 + else
2226 + ewarn "Client configuration '${config_file}' not found; Skipping configuration of default authentication plugin for client ..."
2227 + fi
2228 +
2229 + config_file="${EROOT}/etc/mysql/mysql.d/50-distro-server.cnf"
2230 + if [[ -f "${config_file}" ]] ; then
2231 + config_files+=( "${config_file}" )
2232 + else
2233 + ewarn "Server configuration '${config_file}' not found; Skipping configuration of default authentication plugin for mysqld ..."
2234 + fi
2235 +
2236 + if [[ ${#config_files[@]} -gt 0 ]] ; then
2237 + if [[ -z "${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}" ]] ; then
2238 + local user_answer
2239 +
2240 + echo
2241 + einfo "Please select default authentication plugin (enter number or plugin name):"
2242 + einfo "1) caching_sha2_password [MySQL 8.0 default]"
2243 + einfo "2) mysql_native_password [MySQL 5.7 default]"
2244 + einfo
2245 + einfo "For details see:"
2246 + einfo "https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password"
2247 + read -p " >" user_answer
2248 + echo
2249 +
2250 + case "${user_answer}" in
2251 + 1|caching_sha2_password)
2252 + MYSQL_DEFAULT_AUTHENTICATION_PLUGIN=caching_sha2_password
2253 + ;;
2254 + 2|mysql_native_password)
2255 + MYSQL_DEFAULT_AUTHENTICATION_PLUGIN=mysql_native_password
2256 + ;;
2257 + '')
2258 + die "No authentication plugin selected!"
2259 + ;;
2260 + *)
2261 + die "Authentication plugin '${user_answer}' is unknown/unsupported!"
2262 + ;;
2263 + esac
2264 +
2265 + echo "Selected authentication plugin: ${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}" >> "${mysql_install_log}"
2266 +
2267 + unset user_answer
2268 + fi
2269 +
2270 + local cfg_option cfg_option_tabs cfg_section
2271 + for config_file in "${config_files[@]}" ; do
2272 + cfg_option="default-authentication-plugin"
2273 + cfg_section="mysqld"
2274 + cfg_option_tabs="\t\t"
2275 + if [[ "${config_file}" == *client.cnf ]] ; then
2276 + cfg_option="default-auth"
2277 + cfg_section="client"
2278 + cfg_option_tabs="\t\t\t\t"
2279 + fi
2280 +
2281 + if grep -qE "^(loose-)?${cfg_option}\b.*=" "${config_file}" 2>/dev/null ; then
2282 + einfo "Ensuring that ${cfg_option} is set to '${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}' in '${config_file}' ..."
2283 + sed -i \
2284 + -e "s/^\(loose-\)\?${cfg_option}\b.*=.*/loose-${cfg_option}${cfg_option_tabs}= ${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}/" \
2285 + "${config_file}" || die "Failed to change ${cfg_option} in '${config_file}'!"
2286 + else
2287 + einfo "Setting ${cfg_option} to '${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}' in '${config_file}' ..."
2288 + sed -i \
2289 + -e "/^\[${cfg_section}\]$/a loose-${cfg_option}${cfg_option_tabs}= ${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}" \
2290 + "${config_file}" || die "Failed to add ${cfg_option} to '${config_file}'!"
2291 + fi
2292 + done
2293 + unset cfg_option cfg_option_tabs cfg_section
2294 + fi
2295 + unset config_files config_file
2296 +
2297 + echo
2298 +
2299 + if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
2300 + local tmp_mysqld_password_source=
2301 +
2302 + for tmp_mysqld_password_source in mysql client ; do
2303 + einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
2304 + MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password)"
2305 + if [[ -n "${MYSQL_ROOT_PASSWORD}" ]] ; then
2306 + if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]] ; then
2307 + ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
2308 + MYSQL_ROOT_PASSWORD=
2309 + continue
2310 + fi
2311 +
2312 + einfo "Found password in '${tmp_mysqld_password_source}' section!"
2313 + break
2314 + fi
2315 + done
2316 +
2317 + # Sometimes --show is required to display passwords in some implementations of my_print_defaults
2318 + if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]] ; then
2319 + MYSQL_ROOT_PASSWORD="$(_getoptval "${tmp_mysqld_password_source}" password --show)"
2320 + fi
2321 +
2322 + unset tmp_mysqld_password_source
2323 + fi
2324 +
2325 + if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
2326 + local pwd1="a"
2327 + local pwd2="b"
2328 +
2329 + echo
2330 + einfo "No password for mysql 'root' user was specified via environment"
2331 + einfo "variable MYSQL_ROOT_PASSWORD and no password was found in config"
2332 + einfo "file like '${HOME}/.my.cnf'."
2333 + einfo "To continue please provide a password for the mysql 'root' user"
2334 + einfo "now on console:"
2335 + ewarn "NOTE: Please avoid [\"'\\_%] characters in the password!"
2336 + read -rsp " >" pwd1 ; echo
2337 +
2338 + einfo "Retype the password"
2339 + read -rsp " >" pwd2 ; echo
2340 +
2341 + if [[ "x$pwd1" != "x$pwd2" ]] ; then
2342 + die "Passwords are not the same!"
2343 + fi
2344 +
2345 + MYSQL_ROOT_PASSWORD="${pwd1}"
2346 + unset pwd1 pwd2
2347 +
2348 + echo
2349 + fi
2350 +
2351 + local -a mysqld_options
2352 +
2353 + # Fix bug 446200. Don't reference host my.cnf, needs to come first,
2354 + # see http://bugs.mysql.com/bug.php?id=31312
2355 + use prefix && mysqld_options+=( "--defaults-file='${MY_SYSCONFDIR}/my.cnf'" )
2356 +
2357 + # Figure out which options we need to disable to do the setup
2358 + local helpfile="${TMPDIR}/mysqld-help"
2359 + "${EROOT}/usr/sbin/mysqld" --verbose --help >"${helpfile}" 2>/dev/null
2360 +
2361 + local opt optexp optfull
2362 + for opt in host-cache name-resolve networking slave-start \
2363 + federated ssl log-bin relay-log slow-query-log external-locking \
2364 + log-slave-updates \
2365 + ; do
2366 + optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
2367 + egrep -sq -- "${optexp}" "${helpfile}" && mysqld_options+=( "${optfull}" )
2368 + done
2369 +
2370 + # Prepare timezones, see
2371 + # https://dev.mysql.com/doc/mysql/en/time-zone-support.html
2372 + local tz_sql="$(_mktemp_dry "${MYSQL_TMPDIR}/tz.XXXXXXXXX.sql")"
2373 + [[ -z "${tz_sql}" ]] \
2374 + && die "_mktemp_dry() for '${MYSQL_TMPDIR}/tz.XXXXXXXXX.sql' failed!"
2375 +
2376 + echo "USE mysql;" >"${tz_sql}"
2377 + "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" >> "${tz_sql}" 2>/dev/null
2378 + if [[ $? -ne 0 ]] ; then
2379 + die "mysql_tzinfo_to_sql failed!"
2380 + fi
2381 +
2382 + # --initialize-insecure will not set root password
2383 + # --initialize would set a random one in the log which we don't need as we set it ourselves
2384 + local cmd=(
2385 + "${mysqld_binary}"
2386 + "${mysqld_options[@]}"
2387 + "--initialize-insecure"
2388 + "--init-file='${tz_sql}'"
2389 + "--basedir='${EROOT}/usr'"
2390 + "--datadir='${MY_DATADIR}'"
2391 + "--tmpdir='${MYSQL_TMPDIR}'"
2392 + "--log-error='${mysql_install_log}'"
2393 + "--user=${MYSQL_USER}"
2394 + )
2395 +
2396 + einfo "Initializing ${PN} data directory: ${cmd[@]}"
2397 + eval "${cmd[@]}" >>"${mysql_install_log}" 2>&1
2398 +
2399 + if [[ $? -ne 0 || ! -f "${MY_DATADIR}/mysql.ibd" ]] ; then
2400 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysql_install_log}" 1>&2
2401 + die "Failed to initialize ${PN} data directory. Please review '${mysql_install_log}'!"
2402 + fi
2403 +
2404 + rm "${tz_sql}" || die
2405 +
2406 + local x=${RANDOM}
2407 + local socket="${EROOT}${PID_DIR}/mysqld${x}.sock"
2408 + local pidfile="${EROOT}${PID_DIR}/mysqld${x}.pid"
2409 + unset x
2410 +
2411 + cmd=(
2412 + "${mysqld_binary}"
2413 + "${mysqld_options[@]}"
2414 + "--basedir='${EROOT}/usr'"
2415 + "--datadir='${MY_DATADIR}'"
2416 + "--tmpdir='${MYSQL_TMPDIR}'"
2417 + --max_allowed_packet=8M
2418 + --net_buffer_length=16K
2419 + "--socket='${socket}'"
2420 + "--pid-file='${pidfile}'"
2421 + "--log-error='${mysqld_logfile}'"
2422 + "--user=${MYSQL_USER}"
2423 + )
2424 +
2425 + einfo "Starting mysqld to finalize initialization: ${cmd[@]}"
2426 + eval "${cmd[@]}" >>"${mysqld_logfile}" 2>&1 &
2427 +
2428 + echo -n "Waiting for mysqld to accept connections "
2429 + local maxtry=15
2430 + while [[ ! -S "${socket}" && "${maxtry}" -gt 1 ]] ; do
2431 + maxtry=$((${maxtry}-1))
2432 + echo -n "."
2433 + sleep 1
2434 + done
2435 +
2436 + if [[ -S "${socket}" ]] ; then
2437 + # Even with a socket we don't know if mysqld will abort
2438 + # start due to an error so just wait a little bit more...
2439 + maxtry=5
2440 + while [[ -S "${socket}" && "${maxtry}" -gt 1 ]] ; do
2441 + maxtry=$((${maxtry}-1))
2442 + echo -n "."
2443 + sleep 1
2444 + done
2445 + fi
2446 +
2447 + echo
2448 +
2449 + if [[ ! -S "${socket}" ]] ; then
2450 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysqld_logfile}" 1>&2
2451 + die "mysqld was unable to start from initialized data directory. Please review '${mysqld_logfile}'!"
2452 + fi
2453 +
2454 + local mysql_logfile="${TMPDIR}/set_root_pw.log"
2455 + touch "${mysql_logfile}" || die
2456 +
2457 + ebegin "Setting root password"
2458 + # Do this from memory, as we don't want clear text passwords in temp files
2459 + local sql="ALTER USER 'root'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}'"
2460 + cmd=(
2461 + "${mysql_binary}"
2462 + --no-defaults
2463 + "--socket='${socket}'"
2464 + -hlocalhost
2465 + "-e \"${sql}\""
2466 + )
2467 + eval "${cmd[@]}" >"${mysql_logfile}" 2>&1
2468 + local rc=$?
2469 + eend ${rc}
2470 +
2471 + if [[ ${rc} -ne 0 ]] ; then
2472 + # Poor man's solution which tries to avoid having password
2473 + # in log. NOTE: sed can fail if user didn't follow advice
2474 + # and included character which will require escaping...
2475 + sed -i -e "s/${MYSQL_ROOT_PASSWORD}/*****/" "${mysql_logfile}" 2>/dev/null
2476 +
2477 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysql_logfile}"
2478 + die "Failed to set ${PN} root password. Please review '${mysql_logfile}'!"
2479 + fi
2480 +
2481 + # Stop the server
2482 + if [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; then
2483 + echo -n "Stopping the server "
2484 + pkill -F "${pidfile}" &>/dev/null
2485 +
2486 + maxtry=10
2487 + while [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; do
2488 + maxtry=$((${maxtry}-1))
2489 + echo -n "."
2490 + sleep 1
2491 + done
2492 +
2493 + echo
2494 +
2495 + if [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; then
2496 + # We somehow failed to stop server.
2497 + # However, not a fatal error. Just warn the user.
2498 + ewarn "WARNING: mysqld[$(cat "${pidfile}")] is still running!"
2499 + fi
2500 + fi
2501 +
2502 + einfo "${PN} data directory at '${MY_DATADIR}' successfully initialized!"
2503 +}