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