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/, dev-db/mysql/files/
Date: Tue, 13 Aug 2019 01:52:19
Message-Id: 1565661127.e78f784397d4a85130cd3e071ce8614b103f838e.whissi@gentoo
1 commit: e78f784397d4a85130cd3e071ce8614b103f838e
2 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
3 AuthorDate: Tue Aug 13 01:51:48 2019 +0000
4 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
5 CommitDate: Tue Aug 13 01:52:07 2019 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e78f7843
7
8 dev-db/mysql: bump
9
10 - Rewrite pkg_config()
11
12 - Update pkg_postinst()
13
14 - Set default-auth-plugin=mysql_native_password by default for
15 compatibility with Perl, PHP, Ruby...
16
17 Package-Manager: Portage-2.3.71, Repoman-2.3.17
18 Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>
19
20 dev-db/mysql/files/my.cnf-8.0.distro-client | 4 +-
21 dev-db/mysql/files/my.cnf-8.0.distro-server | 6 +-
22 ...8.0.17_pre2.ebuild => mysql-8.0.17_pre3.ebuild} | 560 ++++++++++++++-------
23 3 files changed, 383 insertions(+), 187 deletions(-)
24
25 diff --git a/dev-db/mysql/files/my.cnf-8.0.distro-client b/dev-db/mysql/files/my.cnf-8.0.distro-client
26 index 5325c1a6d8f..1c2ee7da1d9 100644
27 --- a/dev-db/mysql/files/my.cnf-8.0.distro-client
28 +++ b/dev-db/mysql/files/my.cnf-8.0.distro-client
29 @@ -1,7 +1,9 @@
30 -# @GENTOO_PORTAGE_EPREFIX@/etc/mysql/50-distro-client.cnf: The global mysql configuration file.
31 +# @GENTOO_PORTAGE_EPREFIX@/etc/mysql/mysql.d/50-distro-client.cnf: The global mysql configuration file.
32
33 # The following options will be passed to all MySQL clients
34 [client]
35 +# Should match default server to save a round trip
36 +loose-default-auth = mysql_native_password
37 socket = @GENTOO_PORTAGE_EPREFIX@/var/run/mysqld/mysqld.sock
38 character-sets-dir = @GENTOO_PORTAGE_EPREFIX@/usr/share/mysql/charsets
39 loose-default-character-set = utf8mb4
40
41 diff --git a/dev-db/mysql/files/my.cnf-8.0.distro-server b/dev-db/mysql/files/my.cnf-8.0.distro-server
42 index 248c68e393a..ac087963972 100644
43 --- a/dev-db/mysql/files/my.cnf-8.0.distro-server
44 +++ b/dev-db/mysql/files/my.cnf-8.0.distro-server
45 @@ -1,7 +1,9 @@
46 -# @GENTOO_PORTAGE_EPREFIX@/etc/mysql/50-distro-server.cnf: The global mysql configuration file.
47 +# @GENTOO_PORTAGE_EPREFIX@/etc/mysql/mysql.d/50-distro-server.cnf: The global mysql configuration file.
48
49 # add a section [mysqld-8.0] for specific configurations
50 [mysqld]
51 +# Using "mysql_native_password" for compatibility with Perl, PHP, Ruby...
52 +loose-default-authentication-plugin = mysql_native_password
53 character-set-server = utf8mb4
54 user = mysql
55 port = 3306
56 @@ -24,5 +26,5 @@ log-bin
57 server-id = 1
58
59 # point the following paths to different dedicated disks
60 -tmpdir = @GENTOO_PORTAGE_EPREFIX@/tmp/
61 +#tmpdir = @GENTOO_PORTAGE_EPREFIX@/tmp/
62 #log-update = @GENTOO_PORTAGE_EPREFIX@/path-to-dedicated-directory/hostname
63
64 diff --git a/dev-db/mysql/mysql-8.0.17_pre2.ebuild b/dev-db/mysql/mysql-8.0.17_pre3.ebuild
65 similarity index 64%
66 rename from dev-db/mysql/mysql-8.0.17_pre2.ebuild
67 rename to dev-db/mysql/mysql-8.0.17_pre3.ebuild
68 index c6e2674b422..5b23f974d76 100644
69 --- a/dev-db/mysql/mysql-8.0.17_pre2.ebuild
70 +++ b/dev-db/mysql/mysql-8.0.17_pre3.ebuild
71 @@ -115,15 +115,17 @@ mysql_init_vars() {
72 if [[ -z "${MY_DATADIR}" ]] ; then
73 MY_DATADIR=""
74 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
75 - MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
76 + MY_DATADIR=$(my_print_defaults mysqld 2>/dev/null \
77 | sed -ne '/datadir/s|^--datadir=||p' \
78 - | tail -n1`
79 + | tail -n1)
80 +
81 if [[ -z "${MY_DATADIR}" ]] ; then
82 - MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
83 + MY_DATADIR=$(grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
84 | sed -e 's/.*=\s*//' \
85 - | tail -n1`
86 + | tail -n1)
87 fi
88 fi
89 +
90 if [[ -z "${MY_DATADIR}" ]] ; then
91 MY_DATADIR="${MY_LOCALSTATEDIR}"
92 einfo "Using default MY_DATADIR"
93 @@ -143,17 +145,9 @@ mysql_init_vars() {
94 fi
95 else
96 if [[ ${EBUILD_PHASE} == "config" ]] ; then
97 - local new_MY_DATADIR
98 - new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
99 + MY_DATADIR=$(my_print_defaults mysqld 2>/dev/null \
100 | sed -ne '/datadir/s|^--datadir=||p' \
101 - | tail -n1`
102 -
103 - if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]] ; then
104 - ewarn "MySQL MY_DATADIR has changed"
105 - ewarn "from ${MY_DATADIR}"
106 - ewarn "to ${new_MY_DATADIR}"
107 - MY_DATADIR="${new_MY_DATADIR}"
108 - fi
109 + | tail -n1)
110 fi
111 fi
112
113 @@ -198,40 +192,6 @@ pkg_setup() {
114 fi
115 }
116
117 -pkg_postinst() {
118 - # Make sure the vars are correctly initialized
119 - mysql_init_vars
120 -
121 - # Create log directory securely if it does not exist
122 - [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
123 -
124 - if [[ -z "${REPLACING_VERSIONS}" ]] ; then
125 - einfo
126 - elog "You might want to run:"
127 - elog "\"emerge --config =${CATEGORY}/${PF}\""
128 - elog "if this is a new install."
129 - elog
130 - elog "If you are switching server implentations, you should run the"
131 - elog "mysql_upgrade tool."
132 - einfo
133 - else
134 - einfo
135 - elog "If you are upgrading major versions, you should run the"
136 - elog "mysql_upgrade tool."
137 - einfo
138 - fi
139 -
140 - # Note about configuration change
141 - einfo
142 - elog "This version of ${PN} reorganizes the configuration from a single my.cnf"
143 - elog "to several files in /etc/mysql/mysql.d."
144 - elog "Please backup any changes you made to /etc/mysql/my.cnf"
145 - elog "and add them as a new file under /etc/mysql/mysql.d with a .cnf extension."
146 - elog "You may have as many files as needed and they are read alphabetically."
147 - elog "Be sure the options have the appropriate section headers, i.e. [mysqld]."
148 - einfo
149 -}
150 -
151 src_unpack() {
152 unpack ${A}
153
154 @@ -591,56 +551,254 @@ src_install() {
155 find "${D}" -name 'libmysqlclient_r.*' -type l -delete || die
156 }
157
158 +pkg_postinst() {
159 + # Make sure the vars are correctly initialized
160 + mysql_init_vars
161 +
162 + # Create log directory securely if it does not exist
163 + [[ -d "${EROOT}/${MY_LOGDIR#/}" ]] || install -d -m0750 -o mysql -g mysql "${EROOT}/${MY_LOGDIR#/}"
164 +
165 + # Note about configuration change
166 + einfo
167 + elog "This version of ${PN} reorganizes the configuration from a single my.cnf"
168 + elog "to several files in /etc/mysql/mysql.d."
169 + elog "Please backup any changes you made to /etc/mysql/my.cnf"
170 + elog "and add them as a new file under /etc/mysql/mysql.d with a .cnf extension."
171 + elog "You may have as many files as needed and they are read alphabetically."
172 + elog "Be sure the options have the appropriate section headers, i.e. [mysqld]."
173 + einfo
174 +
175 + if [[ -z "${REPLACING_VERSIONS}" ]] ; then
176 + einfo
177 + elog "You might want to run:"
178 + elog " \"emerge --config =${CATEGORY}/${PF}\""
179 + elog "if this is a new install."
180 + einfo
181 + else
182 + einfo
183 + elog "Upgrade process for ${PN}-8.x has changed. Please read"
184 + elog "https://dev.mysql.com/doc/refman/8.0/en/upgrade-binary-package.html"
185 + einfo
186 + fi
187 +}
188 +
189 pkg_config() {
190 + local mysqld_binary="${EROOT}/usr/sbin/mysqld"
191 + if [[ ! -x "${mysqld_binary}" ]] ; then
192 + die "'${mysqld_binary}' not found! Please re-install ${CATEGORY}/${PN}!"
193 + fi
194 +
195 + local mysql_binary="${EROOT}/usr/bin/mysql"
196 + if [[ ! -x "${mysql_binary}" ]] ; then
197 + die "'${mysql_binary}' not found! Please re-install ${CATEGORY}/${PN}!"
198 + fi
199 +
200 + local my_print_defaults_binary="${EROOT}/usr/bin/my_print_defaults"
201 + if [[ ! -x "${my_print_defaults_binary}" ]] ; then
202 + die "'${my_print_defaults_binary}' not found! Please re-install dev-db/mysql-connector-c!"
203 + fi
204 +
205 _getoptval() {
206 - local mypd="${EROOT}"/usr/bin/my_print_defaults
207 local section="$1"
208 local flag="--${2}="
209 local extra_options="${3}"
210 - "${mypd}" $extra_options $section | sed -n "/^${flag}/s,${flag},,gp"
211 + local results=( $("${my_print_defaults_binary}" ${extra_options} ${section} | sed -n "/^${flag}/s,${flag},,gp") )
212 +
213 + if [[ ${#results[@]} -gt 0 ]] ; then
214 + # When option is set multiple times only return last value
215 + echo "${results[-1]}"
216 + fi
217 }
218 +
219 local old_MY_DATADIR="${MY_DATADIR}"
220 local old_HOME="${HOME}"
221 # my_print_defaults needs to read stuff in $HOME/.my.cnf
222 - export HOME=${EPREFIX}/root
223 + local -x HOME="${EROOT}/root"
224
225 # Make sure the vars are correctly initialized
226 mysql_init_vars
227
228 - [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
229 - if [[ ! -x "${EROOT}/usr/sbin/mysqld" ]] ; then
230 - die "Minimal builds do NOT include the MySQL server"
231 + # Bug #213475 - MySQL _will_ object strenously if your machine is named
232 + # localhost. Also causes weird failures.
233 + [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
234 +
235 + if [[ -z "${MY_DATADIR}" ]] ; then
236 + die "Sorry, unable to find MY_DATADIR!"
237 + elif [[ -d "${EROOT}/${MY_DATADIR#/}/mysql" ]] ; then
238 + ewarn "Looks like your data directory '${EROOT}/${MY_DATADIR#/}' is already initialized!"
239 + ewarn "Please rename or delete its content if you wish to initialize a new data directory."
240 + die "${PN} data directory at '${EROOT}/${MY_DATADIR#/}' looks already initialized!"
241 + else
242 + einfo "${PN} data directory detected as '${EROOT}/${MY_DATADIR#/}' ..."
243 + fi
244 +
245 + MYSQL_TMPDIR="$(_getoptval mysqld tmpdir)"
246 + # These are dir+prefix
247 + MYSQL_LOG_BIN="$(_getoptval mysqld log-bin)"
248 + MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
249 + MYSQL_RELAY_LOG="$(_getoptval mysqld relay-log)"
250 + MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
251 +
252 + # Create missing directories.
253 + # Always check if mysql user can write to directory even if we just
254 + # created directory because a parent directory might be not
255 + # accessible for that user.
256 + PID_DIR="${EROOT}/run/mysqld"
257 + if [[ ! -d "${PID_DIR}" ]] ; then
258 + einfo "Creating ${PN} PID directory '${PID_DIR}' ..."
259 + install -d -m 755 -o mysql -g mysql "${PID_DIR}" \
260 + || die "Failed to create PID directory '${PID_DIR}'!"
261 fi
262
263 - if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]] ; then
264 - local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
265 - MY_DATADIR_s="${MY_DATADIR_s%}"
266 - local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
267 - old_MY_DATADIR_s="${old_MY_DATADIR_s%}"
268 + local _pid_dir_testfile="$(mktemp --dry-run "${PID_DIR}/.pkg_config-access-test.XXXXXXXXX")"
269 + su -s /bin/sh -c "touch ${_pid_dir_testfile}" mysql &>/dev/null
270 + if [[ $? -ne 0 ]] ; then
271 + die "mysql user cannot write into PID dir '${PID_DIR}'!"
272 + else
273 + rm "${_pid_dir_testfile}" || die
274 + unset _pid_dir_testfile
275 + fi
276
277 - if [[ ( -d "${old_MY_DATADIR_s}" ) && ( "${old_MY_DATADIR_s}" != / ) ]] ; then
278 - if [[ -d "${MY_DATADIR_s}" ]] ; then
279 - ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
280 - ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
281 - else
282 - elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
283 - mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
284 - || die "Moving MY_DATADIR failed"
285 - fi
286 + if [[ ! -d "${EROOT}/${MY_DATADIR#/}" ]] ; then
287 + einfo "Creating ${PN} data directory '${EROOT}/${MY_DATADIR#/}' ..."
288 + install -d -m 770 -o mysql -g mysql "${EROOT}/${MY_DATADIR#/}" \
289 + || die "Failed to create ${PN} data directory '${EROOT}/${MY_DATADIR#/}'!"
290 + fi
291 +
292 + local _my_datadir_testfile="$(mktemp --dry-run "${EROOT}/${MY_DATADIR#/}/.pkg_config-access-test.XXXXXXXXX")"
293 + su -s /bin/sh -c "touch '${_my_datadir_testfile}'" mysql &>/dev/null
294 + if [[ $? -ne 0 ]]; then
295 + die "mysql user cannot write into data directory '${EROOT}/${MY_DATADIR#/}'!"
296 + else
297 + rm "${_my_datadir_testfile}" || die
298 + unset _my_datadir_testfile
299 + fi
300 +
301 + if [[ -n "${MYSQL_TMPDIR}" && ! -d "${EROOT}/${MYSQL_TMPDIR#/}" ]] ; then
302 + einfo "Creating ${PN} tmpdir '${EROOT}/${MYSQL_TMPDIR#/}' ..."
303 + install -d -m 770 -o mysql -g mysql "${EROOT}/${MYSQL_TMPDIR#/}" \
304 + || die "Failed to create ${PN} tmpdir '${EROOT}/${MYSQL_TMPDIR#/}'!"
305 + fi
306 +
307 + if [[ -n "${MYSQL_TMPDIR}" ]] ; then
308 + local _my_tmpdir_testfile="$(mktemp --dry-run "${EROOT}/${MYSQL_TMPDIR#/}/.pkg_config-access-test.XXXXXXXXX")"
309 + su -s /bin/sh -c "touch '${_my_tmpdir_testfile}'" mysql &>/dev/null
310 + if [[ $? -ne 0 ]]; then
311 + die "mysql user cannot write into data directory '${EROOT}/${MYSQL_TMPDIR#/}'!"
312 + else
313 + rm "${_my_tmpdir_testfile}" || die
314 + unset _my_tmpdir_testfile
315 + fi
316 + fi
317 +
318 + if [[ -n "${MYSQL_LOG_BIN}" && ! -d "${EROOT}/${MYSQL_LOG_BIN#/}" ]] ; then
319 + einfo "Creating ${PN} log-bin directory '${EROOT}/${MYSQL_LOG_BIN}' ..."
320 + install -d -m 770 -o mysql -g mysql "${EROOT}/${MYSQL_LOG_BIN}" \
321 + || die "Failed to create ${PN} log-bin directory '${EROOT}/${MYSQL_LOG_BIN}'"
322 + fi
323 +
324 + if [[ -n "${MYSQL_LOG_BIN}" ]] ; then
325 + local _my_logbin_testfile="$(mktemp --dry-run "${EROOT}/${MYSQL_LOG_BIN#/}/.pkg_config-access-test.XXXXXXXXX")"
326 + su -s /bin/sh -c "touch '${_my_logbin_testfile}'" mysql &>/dev/null
327 + if [[ $? -ne 0 ]]; then
328 + die "mysql user cannot write into data directory '${EROOT}/${MYSQL_LOG_BIN#/}'!"
329 else
330 - ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
331 - if [[ -d "${MY_DATADIR_s}" ]] ; then
332 - ewarn "Attempting to use ${MY_DATADIR_s}"
333 + rm "${_my_logbin_testfile}" || die
334 + unset _my_logbin_testfile
335 + fi
336 + fi
337 +
338 + if [[ -n "${MYSQL_RELAY_LOG}" && ! -d "${EROOT}/${MYSQL_RELAY_LOG#/}" ]] ; then
339 + einfo "Creating ${PN} relay-log directory '${EROOT}/${MYSQL_RELAY_LOG#/}' ..."
340 + install -d -m 770 -o mysql -g mysql "${EROOT}/${MYSQL_RELAY_LOG#/}" \
341 + || die "Failed to create ${PN} relay-log directory '${EROOT}/${MYSQL_RELAY_LOG#/}'!"
342 + fi
343 +
344 + if [[ -n "${MYSQL_RELAY_LOG}" ]] ; then
345 + local _my_relaylog_testfile="$(mktemp --dry-run "${EROOT}/${MYSQL_RELAY_LOG#/}/.pkg_config-access-test.XXXXXXXXX")"
346 + su -s /bin/sh -c "touch '${_my_relaylog_testfile}'" mysql &>/dev/null
347 + if [[ $? -ne 0 ]]; then
348 + die "mysql user cannot write into data directory '${EROOT}/${MYSQL_RELAY_LOG#/}'!"
349 + else
350 + rm "${_my_relaylog_testfile}" || die
351 + unset _my_relaylog_testfile
352 + fi
353 + fi
354 +
355 + local -a config_files
356 +
357 + local config_file="${EROOT}/etc/mysql/mysql.d/50-distro-client.cnf"
358 + if [[ -f "${config_file}" ]] ; then
359 + config_files+=( "${config_file}" )
360 + else
361 + ewarn "Client configuration '${config_file}' not found; Skipping configuration of default authentication plugin for client ..."
362 + fi
363 +
364 + config_file="${EROOT}/etc/mysql/mysql.d/50-distro-server.cnf"
365 + if [[ -f "${config_file}" ]] ; then
366 + config_files+=( "${config_file}" )
367 + else
368 + ewarn "Server configuration '${config_file}' not found; Skipping configuration of default authentication plugin for mysqld ..."
369 + fi
370 +
371 + if [[ ${#config_files[@]} -gt 0 ]] ; then
372 + if [[ -z "${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}" ]] ; then
373 + local tmp_mysql_default_authentication_plugin
374 +
375 + echo
376 + einfo "Please select default authentication plugin (enter number or plugin name):"
377 + einfo "1) caching_sha2_password [MySQL 8.0 default]"
378 + einfo "2) mysql_native_password [MySQL 5.7 default]"
379 + einfo
380 + einfo "For details see:"
381 + einfo "https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password"
382 + read -p " >" tmp_mysql_default_authentication_plugin
383 + echo
384 +
385 + case "${tmp_mysql_default_authentication_plugin}" in
386 + 1|caching_sha2_password)
387 + MYSQL_DEFAULT_AUTHENTICATION_PLUGIN=caching_sha2_password
388 + ;;
389 + 2|mysql_native_password)
390 + MYSQL_DEFAULT_AUTHENTICATION_PLUGIN=mysql_native_password
391 + ;;
392 + '')
393 + die "No authentication plugin selected!"
394 + ;;
395 + *)
396 + die "Authentication plugin '${tmp_mysql_default_authentication_plugin}' is unknown/unsupported!"
397 + ;;
398 + esac
399 + fi
400 +
401 + local cfg_option cfg_option_tabs cfg_section
402 + for config_file in "${config_files[@]}" ; do
403 + cfg_option="default-authentication-plugin"
404 + cfg_section="mysqld"
405 + cfg_option_tabs="\t\t"
406 + if [[ "${config_file}" == *client.cnf ]] ; then
407 + cfg_option="default-auth"
408 + cfg_section="client"
409 + cfg_option_tabs="\t\t\t\t"
410 + fi
411 +
412 + if grep -qE "^(loose-)?${cfg_option}\b.*=" "${config_file}" 2>/dev/null ; then
413 + einfo "Ensuring that ${cfg_option} is set to '${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}' in '${config_file}' ..."
414 + sed -i \
415 + -e "s/^\(loose-\)\?${cfg_option}\b.*=.*/loose-${cfg_option}${cfg_option_tabs}= ${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}/" \
416 + "${config_file}" || die "Failed to change ${cfg_option} in '${config_file}'!"
417 else
418 - eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
419 - die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
420 + einfo "Setting ${cfg_option} to '${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}' in '${config_file}' ..."
421 + sed -i \
422 + -e "/^\[${cfg_section}\]$/a loose-${cfg_option}${cfg_option_tabs}= ${MYSQL_DEFAULT_AUTHENTICATION_PLUGIN}" \
423 + "${config_file}" || die "Failed to add ${cfg_option} to '${config_file}'!"
424 fi
425 - fi
426 + done
427 + unset cfg_option cfg_option_tabs cfg_section
428 fi
429 + unset config_files config_file
430
431 - local pwd1="a"
432 - local pwd2="b"
433 - local maxtry=15
434 + echo
435
436 if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
437 local tmp_mysqld_password_source=
438 @@ -667,154 +825,188 @@ pkg_config() {
439
440 unset tmp_mysqld_password_source
441 fi
442 - MYSQL_TMPDIR="$(_getoptval mysqld tmpdir)"
443 - # These are dir+prefix
444 - MYSQL_RELAY_LOG="$(_getoptval mysqld relay-log)"
445 - MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
446 - MYSQL_LOG_BIN="$(_getoptval mysqld log-bin)"
447 - MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
448 -
449 - if [[ ! -d "${EROOT}/$MYSQL_TMPDIR" ]] ; then
450 - einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
451 - install -d -m 770 -o mysql -g mysql "${EROOT}/$MYSQL_TMPDIR"
452 - fi
453 -
454 - if [[ ! -d "${EROOT}/$MYSQL_LOG_BIN" ]] ; then
455 - einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
456 - install -d -m 770 -o mysql -g mysql "${EROOT}/$MYSQL_LOG_BIN"
457 - fi
458 -
459 - if [[ ! -d "${EROOT}/$MYSQL_RELAY_LOG" ]] ; then
460 - einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
461 - install -d -m 770 -o mysql -g mysql "${EROOT}/$MYSQL_RELAY_LOG"
462 - fi
463 -
464 - if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
465 - ewarn "You have already a MySQL database in place."
466 - ewarn "(${ROOT}/${MY_DATADIR}/*)"
467 - ewarn "Please rename or delete it if you wish to replace it."
468 - die "MySQL database already exists!"
469 - fi
470 -
471 - # Bug #213475 - MySQL _will_ object strenously if your machine is named
472 - # localhost. Also causes weird failures.
473 - [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
474
475 if [[ -z "${MYSQL_ROOT_PASSWORD}" ]] ; then
476 -
477 - einfo "Please provide a password for the mysql 'root' user now"
478 - einfo "or through the ${HOME}/.my.cnf file."
479 - ewarn "Avoid [\"'\\_%] characters in the password"
480 + local pwd1="a"
481 + local pwd2="b"
482 +
483 + echo
484 + einfo "No password for mysql 'root' user was specified via environment"
485 + einfo "variable MYSQL_ROOT_PASSWORD and no password was found in config"
486 + einfo "file like '${HOME}/.my.cnf'."
487 + einfo "To continue please provide a password for the mysql 'root' user"
488 + einfo "now on console:"
489 + ewarn "NOTE: Please avoid [\"'\\_%] characters in the password!"
490 read -rsp " >" pwd1 ; echo
491
492 einfo "Retype the password"
493 read -rsp " >" pwd2 ; echo
494
495 if [[ "x$pwd1" != "x$pwd2" ]] ; then
496 - die "Passwords are not the same"
497 + die "Passwords are not the same!"
498 fi
499 +
500 MYSQL_ROOT_PASSWORD="${pwd1}"
501 unset pwd1 pwd2
502 +
503 + echo
504 fi
505
506 - local options
507 - local sqltmp="$(emktemp)"
508 + local -a mysqld_options
509
510 # Fix bug 446200. Don't reference host my.cnf, needs to come first,
511 # see http://bugs.mysql.com/bug.php?id=31312
512 - use prefix && options="${options} '--defaults-file=${MY_SYSCONFDIR}/my.cnf'"
513 + use prefix && mysqld_options+=( "--defaults-file='${MY_SYSCONFDIR}/my.cnf'" )
514
515 # Figure out which options we need to disable to do the setup
516 local helpfile="${TMPDIR}/mysqld-help"
517 "${EROOT}/usr/sbin/mysqld" --verbose --help >"${helpfile}" 2>/dev/null
518 +
519 + local opt optexp optfull
520 for opt in host-cache name-resolve networking slave-start \
521 federated ssl log-bin relay-log slow-query-log external-locking \
522 log-slave-updates \
523 - ; do
524 + ; do
525 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
526 - egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
527 + egrep -sq -- "${optexp}" "${helpfile}" && mysqld_options+=( "${optfull}" )
528 done
529
530 - einfo "Creating the mysql database and setting proper permissions on it ..."
531 -
532 - # Now that /var/run is a tmpfs mount point, we need to ensure it exists before using it
533 - PID_DIR="${EROOT}/var/run/mysqld"
534 - if [[ ! -d "${PID_DIR}" ]] ; then
535 - install -d -m 755 -o mysql -g mysql "${PID_DIR}" || die "Could not create pid directory"
536 - fi
537 -
538 - if [[ ! -d "${MY_DATADIR}" ]] ; then
539 - install -d -m 750 -o mysql -g mysql "${MY_DATADIR}" || die "Could not create data directory"
540 + # Prepare timezones, see
541 + # https://dev.mysql.com/doc/mysql/en/time-zone-support.html
542 + local tz_sql="${TMPDIR}/tz.sql"
543 + echo "USE mysql;" >"${tz_sql}"
544 + "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" >> "${tz_sql}" 2>/dev/null
545 + if [[ $? -ne 0 ]] ; then
546 + die "mysql_tzinfo_to_sql failed!"
547 fi
548
549 - pushd "${TMPDIR}" &>/dev/null || die
550 + chown mysql "${tz_sql}" || die
551
552 - # Filling timezones, see
553 - # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
554 - echo "USE mysql;" >"${sqltmp}"
555 - "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" >> "${sqltmp}" 2>/dev/null
556 - chown mysql "${sqltmp}" || die
557 + local mysql_install_log="${TMPDIR}/mysql_install_db.log"
558 + touch "${mysql_install_log}" || die
559 + chown mysql "${mysql_install_log}" || die
560
561 # --initialize-insecure will not set root password
562 # --initialize would set a random one in the log which we don't need as we set it ourselves
563 - local cmd=( "${EROOT}/usr/sbin/mysqld" "--initialize-insecure" "--init-file='${sqltmp}'" )
564 - cmd+=( "--basedir=${EPREFIX}/usr" ${options} "--datadir=${ROOT}${MY_DATADIR}" "--tmpdir=${ROOT}${MYSQL_TMPDIR}" )
565 - einfo "Command: ${cmd[*]}"
566 + local cmd=(
567 + "${mysqld_binary}"
568 + "${mysqld_options[@]}"
569 + "--initialize-insecure"
570 + "--init-file='${tz_sql}'"
571 + "--basedir='${EROOT}/usr'"
572 + "--datadir='${EROOT}/${MY_DATADIR#/}'"
573 + "--tmpdir='${EROOT}/${MYSQL_TMPDIR#/}'"
574 + "--log-error='${mysql_install_log}'"
575 + )
576 +
577 + einfo "Initializing ${PN} data directory: ${cmd[@]}"
578 su -s /bin/sh -c "${cmd[*]}" mysql \
579 - >"${TMPDIR}"/mysql_install_db.log 2>&1
580 - if [[ $? -ne 0 ]] ; then
581 - grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
582 - die "Failed to initialize mysqld. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
583 + >>"${mysql_install_log}" 2>&1
584 +
585 + if [[ $? -ne 0 || ! -f "${EROOT}/${MY_DATADIR#/}/mysql.ibd" ]] ; then
586 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysql_install_log}"
587 + die "Failed to initialize ${PN} data directory. Please review '${mysql_install_log}'!"
588 fi
589 - popd &>/dev/null || die
590 - [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
591 - || die "MySQL databases not installed"
592 -
593 - use prefix || options="${options} --user=mysql"
594 -
595 - local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
596 - local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
597 - local mysqld="${EROOT}/usr/sbin/mysqld \
598 - ${options} \
599 - $(use prefix || echo --user=mysql) \
600 - --log-warnings=0 \
601 - --basedir=${EROOT}/usr \
602 - --datadir=${ROOT}/${MY_DATADIR} \
603 - --max_allowed_packet=8M \
604 - --net_buffer_length=16K \
605 - --socket=${socket} \
606 - --pid-file=${pidfile} \
607 - --tmpdir=${ROOT}/${MYSQL_TMPDIR}"
608 - #einfo "About to start mysqld: ${mysqld}"
609 - ebegin "Starting mysqld"
610 - einfo "Command ${mysqld}"
611 - ${mysqld} &
612 - rc=$?
613 - while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
614 +
615 + local x=${RANDOM}
616 + local socket="${EROOT}/run/mysqld/mysqld${x}.sock"
617 + local pidfile="${EROOT}/run/mysqld/mysqld${x}.pid"
618 + unset x
619 +
620 + local mysqld_logfile="${TMPDIR}/mysqld.log"
621 + touch "${mysqld_logfile}" || die
622 + chown mysql "${mysqld_logfile}" || die
623 +
624 + cmd=(
625 + "${mysqld_binary}"
626 + "${mysqld_options[@]}"
627 + "--basedir='${EROOT}/usr'"
628 + "--datadir='${EROOT}/${MY_DATADIR#/}'"
629 + --max_allowed_packet=8M
630 + --net_buffer_length=16K
631 + "--socket='${socket}'"
632 + "--pid-file='${pidfile}'"
633 + "--tmpdir='${EROOT}/${MYSQL_TMPDIR#/}'"
634 + "--log-error='${mysqld_logfile}'"
635 + )
636 +
637 + einfo "Starting mysqld to finalize initialization: ${cmd[@]}"
638 + su -s /bin/sh -c "${cmd[*]} &" mysql \
639 + >>"${mysqld_logfile}" 2>&1
640 +
641 + echo -n "Waiting for mysqld to accept connections "
642 + local maxtry=15
643 + while [[ ! -S "${socket}" && "${maxtry}" -gt 1 ]] ; do
644 maxtry=$((${maxtry}-1))
645 echo -n "."
646 sleep 1
647 done
648 - eend $rc
649
650 - if ! [[ -S "${socket}" ]] ; then
651 - die "Completely failed to start up mysqld with: ${mysqld}"
652 + if [[ -S "${socket}" ]] ; then
653 + # Even with a socket we don't know if mysqld will abort
654 + # start due to an error so just wait a little bit more...
655 + maxtry=5
656 + while [[ -S "${socket}" && "${maxtry}" -gt 1 ]] ; do
657 + maxtry=$((${maxtry}-1))
658 + echo -n "."
659 + sleep 1
660 + done
661 + fi
662 +
663 + echo
664 +
665 + if [[ ! -S "${socket}" ]] ; then
666 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysqld_logfile}"
667 + die "mysqld was unable to start from initialized data directory. Please review '${mysqld_logfile}'!"
668 fi
669
670 + local mysql_logfile="${TMPDIR}/set_root_pw.log"
671 + touch "${mysql_logfile}" || die
672 +
673 ebegin "Setting root password"
674 # Do this from memory, as we don't want clear text passwords in temp files
675 - local sql="ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '${MYSQL_ROOT_PASSWORD}'"
676 - "${EROOT}/usr/bin/mysql" \
677 - --no-defaults \
678 - "--socket=${socket}" \
679 - -hlocalhost \
680 - -e "${sql}"
681 - eend $?
682 -
683 - # Stop the server and cleanup
684 - einfo "Stopping the server ..."
685 - kill $(< "${pidfile}" )
686 - rm -f "${sqltmp}"
687 - wait %1
688 - einfo "Done"
689 + local sql="ALTER USER 'root'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}'"
690 + cmd=(
691 + "${mysql_binary}"
692 + --no-defaults
693 + "--socket='${socket}'"
694 + -hlocalhost
695 + "-e \"${sql}\""
696 + )
697 + eval "${cmd[@]}" >"${mysql_logfile}" 2>&1
698 + local rc=$?
699 + eend ${rc}
700 +
701 + if [[ ${rc} -ne 0 ]] ; then
702 + # Poor man's solution which tries to avoid having password
703 + # in log. NOTE: sed can fail if user didn't follow advice
704 + # and included character which will require escaping...
705 + sed -i -e "s/${MYSQL_ROOT_PASSWORD}/*****/" "${mysql_logfile}" 2>/dev/null
706 +
707 + grep -B5 -A999 -iE "(Aborting|ERROR|errno)" "${mysql_logfile}"
708 + die "Failed to set ${PN} root password. Please review '${mysql_logfile}'!"
709 + fi
710 +
711 + # Stop the server
712 + if [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; then
713 + echo -n "Stopping the server "
714 + pkill -F "${pidfile}" &>/dev/null
715 +
716 + maxtry=10
717 + while [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; do
718 + maxtry=$((${maxtry}-1))
719 + echo -n "."
720 + sleep 1
721 + done
722 +
723 + echo
724 +
725 + if [[ -f "${pidfile}" ]] && pgrep -F "${pidfile}" &>/dev/null ; then
726 + # We somehow failed to stop server.
727 + # However, not a fatal error. Just warn the user.
728 + ewarn "WARNING: mysqld[$(cat "${pidfile}")] is still running!"
729 + fi
730 + fi
731 +
732 + einfo "${PN} data directory at '${EROOT}/${MY_DATADIR#/}' successfully initialized!"
733 }