/[gentoo-x86]/eclass/mysql-v2.eclass
Gentoo

Contents of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (show annotations) (download)
Mon Jan 28 02:13:05 2013 UTC (19 months, 3 weeks ago) by robbat2
Branch: MAIN
Changes since 1.22: +11 -23 lines
Sync mysql eclasses from gentoo-mysql tree. Fixes: PBXT nice (#374349), MariaDB desc (#453934), REQUIRED_USED (#441700).

1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/mysql-v2.eclass,v 1.22 2013/01/20 02:23:10 robbat2 Exp $
4
5 # @ECLASS: mysql-v2.eclass
6 # @MAINTAINER:
7 # Maintainers:
8 # - MySQL Team <mysql-bugs@gentoo.org>
9 # - Robin H. Johnson <robbat2@gentoo.org>
10 # - Jorge Manuel B. S. Vicetto <jmbsvicetto@gentoo.org>
11 # @BLURB: This eclass provides most of the functions for mysql ebuilds
12 # @DESCRIPTION:
13 # The mysql-v2.eclass is the base eclass to build the mysql and
14 # alternative projects (mariadb) ebuilds.
15 # This eclass uses the mysql-autotools and mysql-cmake eclasses for the
16 # specific bits related to the build system.
17 # It provides the src_unpack, src_prepare, src_configure, src_compile,
18 # src_install, pkg_preinst, pkg_postinst, pkg_config and pkg_postrm
19 # phase hooks.
20
21 # @ECLASS-VARIABLE: BUILD
22 # @DESCRIPTION:
23 # Build type of the mysql version
24 : ${BUILD:=autotools}
25
26 case ${BUILD} in
27 "cmake")
28 BUILD_INHERIT="mysql-cmake"
29 ;;
30 "autotools")
31 BUILD_INHERIT="mysql-autotools"
32
33 WANT_AUTOCONF="latest"
34 WANT_AUTOMAKE="latest"
35 ;;
36 *)
37 die "${BUILD} is not a valid build system for mysql"
38 ;;
39 esac
40
41 MYSQL_EXTRAS=""
42
43 # @ECLASS-VARIABLE: MYSQL_EXTRAS_VER
44 # @DESCRIPTION:
45 # The version of the MYSQL_EXTRAS repo to use to build mysql
46 # Use "none" to disable it's use
47 [[ "${MY_EXTRAS_VER}" == "live" ]] && MYSQL_EXTRAS="git-2"
48
49 inherit eutils flag-o-matic gnuconfig ${MYSQL_EXTRAS} ${BUILD_INHERIT} mysql_fx versionator toolchain-funcs
50
51 #
52 # Supported EAPI versions and export functions
53 #
54
55 case "${EAPI:-0}" in
56 3|4|5) ;;
57 *) die "Unsupported EAPI: ${EAPI}" ;;
58 esac
59
60 EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_install pkg_preinst pkg_postinst pkg_config pkg_postrm
61
62 #
63 # VARIABLES:
64 #
65
66 # Shorten the path because the socket path length must be shorter than 107 chars
67 # and we will run a mysql server during test phase
68 S="${WORKDIR}/mysql"
69
70 [[ "${MY_EXTRAS_VER}" == "latest" ]] && MY_EXTRAS_VER="20090228-0714Z"
71 if [[ "${MY_EXTRAS_VER}" == "live" ]]; then
72 EGIT_PROJECT=mysql-extras
73 EGIT_REPO_URI="git://git.overlays.gentoo.org/proj/mysql-extras.git"
74 fi
75
76 # @ECLASS-VARIABLE: MYSQL_PV_MAJOR
77 # @DESCRIPTION:
78 # Upstream MySQL considers the first two parts of the version number to be the
79 # major version. Upgrades that change major version should always run
80 # mysql_upgrade.
81 MYSQL_PV_MAJOR="$(get_version_component_range 1-2 ${PV})"
82
83 # @ECLASS-VARIABLE: MYSQL_VERSION_ID
84 # @DESCRIPTION:
85 # MYSQL_VERSION_ID will be:
86 # major * 10e6 + minor * 10e4 + micro * 10e2 + gentoo revision number, all [0..99]
87 # This is an important part, because many of the choices the MySQL ebuild will do
88 # depend on this variable.
89 # In particular, the code below transforms a $PVR like "5.0.18-r3" in "5001803"
90 # We also strip off upstream's trailing letter that they use to respin tarballs
91 MYSQL_VERSION_ID=""
92 tpv="${PV%[a-z]}"
93 tpv=( ${tpv//[-._]/ } ) ; tpv[3]="${PVR:${#PV}}" ; tpv[3]="${tpv[3]##*-r}"
94 for vatom in 0 1 2 3 ; do
95 # pad to length 2
96 tpv[${vatom}]="00${tpv[${vatom}]}"
97 MYSQL_VERSION_ID="${MYSQL_VERSION_ID}${tpv[${vatom}]:0-2}"
98 done
99 # strip leading "0" (otherwise it's considered an octal number by BASH)
100 MYSQL_VERSION_ID=${MYSQL_VERSION_ID##"0"}
101
102 # This eclass should only be used with at least mysql-5.1.50
103 mysql_version_is_at_least "5.1.50" || die "This eclass should only be used with >=mysql-5.1.50"
104
105 # @ECLASS-VARIABLE: XTRADB_VER
106 # @DEFAULT_UNSET
107 # @DESCRIPTION:
108 # Version of the XTRADB storage engine
109
110 # @ECLASS-VARIABLE: PERCONA_VER
111 # @DEFAULT_UNSET
112 # @DESCRIPTION:
113 # Designation by PERCONA for a MySQL version to apply an XTRADB release
114
115 # Work out the default SERVER_URI correctly
116 if [ -z "${SERVER_URI}" ]; then
117 [ -z "${MY_PV}" ] && MY_PV="${PV//_/-}"
118 if [ "${PN}" == "mariadb" ]; then
119 MARIA_FULL_PV="$(replace_version_separator 3 '-' ${MY_PV})"
120 MARIA_FULL_P="${PN}-${MARIA_FULL_PV}"
121 SERVER_URI="
122 http://ftp.osuosl.org/pub/mariadb/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
123 http://ftp.rediris.es/mirror/MariaDB/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
124 http://maria.llarian.net/download/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
125 http://launchpad.net/maria/${MYSQL_PV_MAJOR}/ongoing/+download/${MARIA_FULL_P}.tar.gz
126 http://mirrors.fe.up.pt/pub/${PN}/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
127 http://ftp-stud.hs-esslingen.de/pub/Mirrors/${PN}/${MARIA_FULL_P}/kvm-tarbake-jaunty-x86/${MARIA_FULL_P}.tar.gz
128 "
129 else
130 URI_DIR="MySQL"
131 URI_FILE="mysql"
132 URI_A="${URI_FILE}-${MY_PV}.tar.gz"
133 MIRROR_PV=$(get_version_component_range 1-2 ${PV})
134 # Recently upstream switched to an archive site, and not on mirrors
135 SERVER_URI="http://downloads.mysql.com/archives/${URI_FILE}-${MIRROR_PV}/${URI_A}
136 mirror://mysql/Downloads/${URI_DIR}-${PV%.*}/${URI_A}"
137 fi
138 fi
139
140 # Define correct SRC_URIs
141 SRC_URI="${SERVER_URI}"
142
143 # Gentoo patches to MySQL
144 [[ ${MY_EXTRAS_VER} != live ]] && [[ ${MY_EXTRAS_VER} != none ]] \
145 && SRC_URI="${SRC_URI}
146 mirror://gentoo/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
147 http://g3nt8.org/patches/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
148 http://dev.gentoo.org/~robbat2/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2
149 http://dev.gentoo.org/~jmbsvicetto/distfiles/mysql-extras-${MY_EXTRAS_VER}.tar.bz2"
150
151 DESCRIPTION="A fast, multi-threaded, multi-user SQL database server."
152 HOMEPAGE="http://www.mysql.com/"
153 if [[ "${PN}" == "mariadb" ]]; then
154 HOMEPAGE="http://mariadb.org/"
155 DESCRIPTION="An enhanced, drop-in replacement for MySQL"
156 fi
157 LICENSE="GPL-2"
158 SLOT="0"
159
160 case "${BUILD}" in
161 "autotools")
162 IUSE="big-tables debug embedded minimal +perl selinux ssl static test"
163 ;;
164 "cmake")
165 IUSE="debug embedded minimal +perl selinux ssl static test"
166 ;;
167 esac
168
169 IUSE="${IUSE} latin1"
170
171 IUSE="${IUSE} extraengine"
172 IUSE="${IUSE} cluster"
173
174 IUSE="${IUSE} max-idx-128"
175 IUSE="${IUSE} berkdb"
176 IUSE="${IUSE} +community profiling"
177
178 [[ ${PN} == "mariadb" ]] \
179 && mysql_check_version_range "5.1.38 to 5.3.99" \
180 && IUSE="${IUSE} libevent"
181
182 [[ ${PN} == "mariadb" ]] \
183 && mysql_version_is_at_least "5.2" \
184 && IUSE="${IUSE} oqgraph"
185
186 [[ ${PN} == "mariadb" ]] \
187 && mysql_version_is_at_least "5.2.5" \
188 && IUSE="${IUSE} sphinx"
189
190 if mysql_version_is_at_least "5.5"; then
191 REQUIRED_USE="tcmalloc? ( !jemalloc ) jemalloc? ( !tcmalloc )"
192 IUSE="${IUSE} jemalloc tcmalloc"
193 fi
194
195 REQUIRED_USE="${REQUIRED_USE} minimal? ( !cluster !extraengine !embedded ) static? ( !ssl )"
196
197 mysql_version_is_at_least "5.5.7" \
198 && IUSE="${IUSE} systemtap"
199
200 #
201 # DEPENDENCIES:
202 #
203
204 # Be warned, *DEPEND are version-dependant
205 # These are used for both runtime and compiletime
206 DEPEND="
207 ssl? ( >=dev-libs/openssl-0.9.6d )
208 kernel_linux? ( sys-process/procps )
209 >=sys-apps/sed-4
210 >=sys-apps/texinfo-4.7-r1
211 >=sys-libs/readline-4.1
212 >=sys-libs/zlib-1.2.3
213 "
214
215 [[ ${PN} == mariadb ]] \
216 && mysql_check_version_range "5.1.38 to 5.3.99" \
217 && DEPEND="${DEPEND} libevent? ( >=dev-libs/libevent-1.4 )"
218
219 # Having different flavours at the same time is not a good idea
220 for i in "mysql" "mariadb" ; do
221 [[ ${i} == ${PN} ]] ||
222 DEPEND="${DEPEND} !dev-db/${i}"
223 done
224
225 [[ "${PN}" == "mariadb" ]] \
226 && mysql_version_is_at_least "5.2" \
227 && DEPEND="${DEPEND} oqgraph? ( >=dev-libs/boost-1.40.0 )"
228
229 [[ "${PN}" == "mariadb" ]] \
230 && mysql_version_is_at_least "5.2.5" \
231 && DEPEND="${DEPEND} sphinx? ( app-misc/sphinx )"
232
233 # Bug 441700 MariaDB >=5.3 include custom mytop
234 [[ "${PN}" == "mariadb" ]] \
235 && mysql_version_is_at_least "5.3" \
236 && DEPEND="${DEPEND} !dev-db/mytop"
237
238 mysql_version_is_at_least "5.5.7" \
239 && DEPEND="${DEPEND} systemtap? ( >=dev-util/systemtap-1.3 )" \
240 && DEPEND="${DEPEND} kernel_linux? ( dev-libs/libaio )"
241
242 mysql_version_is_at_least "5.5" \
243 && DEPEND="${DEPEND} jemalloc? ( dev-libs/jemalloc )"
244
245 mysql_version_is_at_least "5.5" \
246 && DEPEND="${DEPEND} tcmalloc? ( dev-util/google-perftools )"
247
248 # prefix: first need to implement something for #196294
249 RDEPEND="${DEPEND}
250 !minimal? ( !prefix? ( dev-db/mysql-init-scripts ) )
251 selinux? ( sec-policy/selinux-mysql )
252 "
253
254 DEPEND="${DEPEND}
255 virtual/yacc
256 "
257
258 DEPEND="${DEPEND} static? ( sys-libs/ncurses[static-libs] )"
259
260 # compile-time-only
261 DEPEND="${DEPEND} >=dev-util/cmake-2.4.3"
262
263 # compile-time-only
264 mysql_version_is_at_least "5.5.8" \
265 && DEPEND="${DEPEND} >=dev-util/cmake-2.6.3"
266
267 # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
268 PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
269
270 # For other stuff to bring us in
271 PDEPEND="${PDEPEND} =virtual/mysql-${MYSQL_PV_MAJOR}"
272
273 #
274 # External patches
275 #
276
277 # MariaDB has integrated PBXT
278 # PBXT_VERSION means that we have a PBXT patch for this PV
279 # PBXT was only introduced after 5.1.12
280 pbxt_patch_available() {
281 [[ ${PN} != "mariadb" ]] \
282 && [[ -n "${PBXT_VERSION}" ]]
283 return $?
284 }
285
286 pbxt_available() {
287 pbxt_patch_available || [[ ${PN} == "mariadb" ]]
288 return $?
289 }
290
291 # Get the percona tarball if XTRADB_VER and PERCONA_VER are both set
292 # MariaDB has integrated XtraDB
293 # XTRADB_VERS means that we have a XTRADB patch for this PV
294 # XTRADB was only introduced after 5.1.26
295 xtradb_patch_available() {
296 [[ ${PN} != "mariadb" ]] \
297 && [[ -n "${XTRADB_VER}" && -n "${PERCONA_VER}" ]]
298 return $?
299 }
300
301
302 if pbxt_patch_available; then
303
304 PBXT_P="pbxt-${PBXT_VERSION}"
305 PBXT_SRC_URI="http://www.primebase.org/download/${PBXT_P}.tar.gz mirror://sourceforge/pbxt/${PBXT_P}.tar.gz"
306 SRC_URI="${SRC_URI} pbxt? ( ${PBXT_SRC_URI} )"
307
308 fi
309
310 # PBXT_NEWSTYLE means pbxt is in storage/ and gets enabled as other plugins
311 # vs. built outside the dir
312 if pbxt_available; then
313
314 IUSE="${IUSE} pbxt"
315 PBXT_NEWSTYLE=1
316 REQUIRED_USE="${REQUIRED_USE} pbxt? ( !embedded ) "
317 fi
318
319 if xtradb_patch_available; then
320 XTRADB_P="percona-xtradb-${XTRADB_VER}"
321 XTRADB_SRC_URI_COMMON="${PERCONA_VER}/source/${XTRADB_P}.tar.gz"
322 XTRADB_SRC_B1="http://www.percona.com/"
323 XTRADB_SRC_B2="${XTRADB_SRC_B1}/percona-builds/"
324 XTRADB_SRC_URI1="${XTRADB_SRC_B2}/Percona-Server/Percona-Server-${XTRADB_SRC_URI_COMMON}"
325 XTRADB_SRC_URI2="${XTRADB_SRC_B2}/xtradb/${XTRADB_SRC_URI_COMMON}"
326 XTRADB_SRC_URI3="${XTRADB_SRC_B1}/${PN}/xtradb/${XTRADB_SRC_URI_COMMON}"
327 SRC_URI="${SRC_URI} xtradb? ( ${XTRADB_SRC_URI1} ${XTRADB_SRC_URI2} ${XTRADB_SRC_URI3} )"
328 IUSE="${IUSE} xtradb"
329 REQUIRED_USE="${REQUIRED_USE} xtradb? ( !embedded ) "
330 fi
331
332 #
333 # HELPER FUNCTIONS:
334 #
335
336 # @FUNCTION: mysql-v2_disable_test
337 # @DESCRIPTION:
338 # Helper function to disable specific tests.
339 mysql-v2_disable_test() {
340 ${BUILD_INHERIT}_disable_test "$@"
341 }
342
343 # @FUNCTION: mysql-v2_configure_minimal
344 # @DESCRIPTION:
345 # Helper function to configure minimal build
346 configure_minimal() {
347 ${BUILD_INHERIT}_configure_minimal "$@"
348 }
349
350 # @FUNCTION: mysql-v2_configure_common
351 # @DESCRIPTION:
352 # Helper function to configure common builds
353 configure_common() {
354 ${BUILD_INHERIT}_configure_common "$@"
355 }
356
357 #
358 # EBUILD FUNCTIONS
359 #
360
361 # @FUNCTION: mysql-v2_pkg_setup
362 # @DESCRIPTION:
363 # Perform some basic tests and tasks during pkg_setup phase:
364 # die if FEATURES="test", USE="-minimal" and not using FEATURES="userpriv"
365 # check for conflicting use flags
366 # create new user and group for mysql
367 # warn about deprecated features
368 mysql-v2_pkg_setup() {
369
370 if has test ${FEATURES} ; then
371 if ! use minimal ; then
372 if ! has userpriv ${FEATURES} ; then
373 eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
374 fi
375 fi
376 fi
377
378 # Check for USE flag problems in pkg_setup
379 if ! mysql_version_is_at_least "5.2" \
380 && use debug ; then
381 # Also in package.use.mask
382 die "Bug #344885: Upstream has broken USE=debug for 5.1 series >=5.1.51"
383 fi
384
385 # This should come after all of the die statements
386 enewgroup mysql 60 || die "problem adding 'mysql' group"
387 enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
388
389 if use cluster; then
390 ewarn "Upstream has noted that the NDB cluster support in the 5.0 and"
391 ewarn "5.1 series should NOT be put into production. In the near"
392 ewarn "future, it will be disabled from building."
393 fi
394 }
395
396 # @FUNCTION: mysql-v2_src_unpack
397 # @DESCRIPTION:
398 # Unpack the source code
399 mysql-v2_src_unpack() {
400
401 # Initialize the proper variables first
402 mysql_init_vars
403
404 unpack ${A}
405 # Grab the patches
406 [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-2_src_unpack
407
408 mv -f "${WORKDIR}/${MY_SOURCEDIR}" "${S}"
409 }
410
411 # @FUNCTION: mysql-v2_src_prepare
412 # @DESCRIPTION:
413 # Apply patches to the source code and remove unneeded bundled libs.
414 mysql-v2_src_prepare() {
415 ${BUILD_INHERIT}_src_prepare "$@"
416 }
417
418 # @FUNCTION: mysql-v2_src_configure
419 # @DESCRIPTION:
420 # Configure mysql to build the code for Gentoo respecting the use flags.
421 mysql-v2_src_configure() {
422 ${BUILD_INHERIT}_src_configure "$@"
423 }
424
425 # @FUNCTION: mysql-v2_src_compile
426 # @DESCRIPTION:
427 # Compile the mysql code.
428 mysql-v2_src_compile() {
429 ${BUILD_INHERIT}_src_compile "$@"
430 }
431
432 # @FUNCTION: mysql-v2_src_install
433 # @DESCRIPTION:
434 # Install mysql.
435 mysql-v2_src_install() {
436 ${BUILD_INHERIT}_src_install "$@"
437 }
438
439 # @FUNCTION: mysql-v2_pkg_preinst
440 # @DESCRIPTION:
441 # Create the user and groups for mysql - die if that fails.
442 mysql-v2_pkg_preinst() {
443 enewgroup mysql 60 || die "problem adding 'mysql' group"
444 enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
445 }
446
447 # @FUNCTION: mysql-v2_pkg_postinst
448 # @DESCRIPTION:
449 # Run post-installation tasks:
450 # create the dir for logfiles if non-existant
451 # touch the logfiles and secure them
452 # install scripts
453 # issue required steps for optional features
454 # issue deprecation warnings
455 mysql-v2_pkg_postinst() {
456
457 # Make sure the vars are correctly initialized
458 mysql_init_vars
459
460 # Check FEATURES="collision-protect" before removing this
461 [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
462
463 # Secure the logfiles
464 touch "${ROOT}${MY_LOGDIR}"/mysql.{log,err}
465 chown mysql:mysql "${ROOT}${MY_LOGDIR}"/mysql*
466 chmod 0660 "${ROOT}${MY_LOGDIR}"/mysql*
467
468 # Minimal builds don't have the MySQL server
469 if ! use minimal ; then
470 docinto "support-files"
471 for script in \
472 support-files/my-*.cnf \
473 support-files/magic \
474 support-files/ndb-config-2-node.ini
475 do
476 [[ -f "${script}" ]] \
477 && dodoc "${script}"
478 done
479
480 docinto "scripts"
481 for script in scripts/mysql* ; do
482 [[ -f "${script}" ]] \
483 && [[ "${script%.sh}" == "${script}" ]] \
484 && dodoc "${script}"
485 done
486
487 einfo
488 elog "You might want to run:"
489 elog "\"emerge --config =${CATEGORY}/${PF}\""
490 elog "if this is a new install."
491 einfo
492
493 einfo
494 elog "If you are upgrading major versions, you should run the"
495 elog "mysql_upgrade tool."
496 einfo
497 fi
498
499 if pbxt_available && use pbxt ; then
500 elog "Note: PBXT is now statically built when enabled."
501 elog ""
502 elog "If, you previously installed as a plugin and "
503 elog "you cannot start the MySQL server,"
504 elog "remove the ${MY_DATADIR}/mysql/plugin.* files, then"
505 elog "use the MySQL upgrade script to restore the table"
506 elog "or execute the following SQL command:"
507 elog " CREATE TABLE IF NOT EXISTS plugin ("
508 elog " name char(64) binary DEFAULT '' NOT NULL,"
509 elog " dl char(128) DEFAULT '' NOT NULL,"
510 elog " PRIMARY KEY (name)"
511 elog " ) CHARACTER SET utf8 COLLATE utf8_bin;"
512 fi
513
514 mysql_check_version_range "4.0 to 5.0.99.99" \
515 && use berkdb \
516 && elog "Berkeley DB support is deprecated and will be removed in future versions!"
517 }
518
519 # @FUNCTION: mysql-v2_getopt
520 # @DESCRIPTION:
521 # Use my_print_defaults to extract specific config options
522 mysql-v2_getopt() {
523 local mypd="${EROOT}"/usr/bin/my_print_defaults
524 section="$1"
525 flag="--${2}="
526 "${mypd}" $section | sed -n "/^${flag}/p"
527 }
528
529 # @FUNCTION: mysql-v2_getoptval
530 # @DESCRIPTION:
531 # Use my_print_defaults to extract specific config options
532 mysql-v2_getoptval() {
533 local mypd="${EROOT}"/usr/bin/my_print_defaults
534 section="$1"
535 flag="--${2}="
536 "${mypd}" $section | sed -n "/^${flag}/s,${flag},,gp"
537 }
538
539 # @FUNCTION: mysql-v2_pkg_config
540 # @DESCRIPTION:
541 # Configure mysql environment.
542 mysql-v2_pkg_config() {
543
544 local old_MY_DATADIR="${MY_DATADIR}"
545 local old_HOME="${HOME}"
546 # my_print_defaults needs to read stuff in $HOME/.my.cnf
547 export HOME=/root
548
549 # Make sure the vars are correctly initialized
550 mysql_init_vars
551
552 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
553
554 if built_with_use ${CATEGORY}/${PN} minimal ; then
555 die "Minimal builds do NOT include the MySQL server"
556 fi
557
558 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
559 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
560 MY_DATADIR_s="${MY_DATADIR_s%%/}"
561 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
562 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
563
564 if [[ -d "${old_MY_DATADIR_s}" ]] && [[ "${old_MY_DATADIR_s}" != / ]]; then
565 if [[ -d "${MY_DATADIR_s}" ]]; then
566 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
567 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
568 else
569 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
570 mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
571 || die "Moving MY_DATADIR failed"
572 fi
573 else
574 ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
575 if [[ -d "${MY_DATADIR_s}" ]]; then
576 ewarn "Attempting to use ${MY_DATADIR_s}"
577 else
578 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
579 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
580 fi
581 fi
582 fi
583
584 local pwd1="a"
585 local pwd2="b"
586 local maxtry=15
587
588 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
589 MYSQL_ROOT_PASSWORD="$(mysql-v2_getoptval 'client mysql' password)"
590 fi
591 MYSQL_TMPDIR="$(mysql-v2_getoptval mysqld tmpdir)"
592 # These are dir+prefix
593 MYSQL_RELAY_LOG="$(mysql-v2_getoptval mysqld relay-log)"
594 MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
595 MYSQL_LOG_BIN="$(mysql-v2_getoptval mysqld log-bin)"
596 MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
597
598 if [[ ! -d "${EROOT}"/$MYSQL_TMPDIR ]]; then
599 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
600 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_TMPDIR
601 fi
602 if [[ ! -d "${EROOT}"/$MYSQL_LOG_BIN ]]; then
603 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
604 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_LOG_BIN
605 fi
606 if [[ ! -d "${EROOT}"/$MYSQL_RELAY_LOG ]]; then
607 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
608 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_RELAY_LOG
609 fi
610
611 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
612 ewarn "You have already a MySQL database in place."
613 ewarn "(${ROOT}/${MY_DATADIR}/*)"
614 ewarn "Please rename or delete it if you wish to replace it."
615 die "MySQL database already exists!"
616 fi
617
618 # Bug #213475 - MySQL _will_ object strenously if your machine is named
619 # localhost. Also causes weird failures.
620 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
621
622 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
623
624 einfo "Please provide a password for the mysql 'root' user now, in the"
625 einfo "MYSQL_ROOT_PASSWORD env var or through the /root/.my.cnf file."
626 ewarn "Avoid [\"'\\_%] characters in the password"
627 read -rsp " >" pwd1 ; echo
628
629 einfo "Retype the password"
630 read -rsp " >" pwd2 ; echo
631
632 if [[ "x$pwd1" != "x$pwd2" ]] ; then
633 die "Passwords are not the same"
634 fi
635 MYSQL_ROOT_PASSWORD="${pwd1}"
636 unset pwd1 pwd2
637 fi
638
639 local options="--log-warnings=0"
640 local sqltmp="$(emktemp)"
641
642 local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
643 [[ -r "${help_tables}" ]] \
644 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
645 || touch "${TMPDIR}/fill_help_tables.sql"
646 help_tables="${TMPDIR}/fill_help_tables.sql"
647
648 # Figure out which options we need to disable to do the setup
649 helpfile="${TMPDIR}/mysqld-help"
650 ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
651 for opt in grant-tables host-cache name-resolve networking slave-start bdb \
652 federated innodb ssl log-bin relay-log slow-query-log external-locking \
653 ndbcluster log-slave-updates \
654 ; do
655 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
656 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
657 done
658 # But some options changed names
659 egrep -sq external-locking "${helpfile}" && \
660 options="${options/skip-locking/skip-external-locking}"
661
662 use prefix || options="${options} --user=mysql"
663
664 pushd "${TMPDIR}" &>/dev/null
665 #cmd="'${EROOT}/usr/share/mysql/scripts/mysql_install_db' '--basedir=${EPREFIX}/usr' ${options}"
666 cmd=${EROOT}usr/share/mysql/scripts/mysql_install_db
667 [ -f ${cmd} ] || cmd=${EROOT}usr/bin/mysql_install_db
668 cmd="'$cmd' '--basedir=${EPREFIX}/usr' ${options}"
669 einfo "Command: $cmd"
670 eval $cmd \
671 >"${TMPDIR}"/mysql_install_db.log 2>&1
672 if [ $? -ne 0 ]; then
673 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
674 die "Failed to run mysql_install_db. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
675 fi
676 popd &>/dev/null
677 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
678 || die "MySQL databases not installed"
679 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
680 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
681
682 # Filling timezones, see
683 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
684 "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
685
686 if [[ -r "${help_tables}" ]] ; then
687 cat "${help_tables}" >> "${sqltmp}"
688 fi
689
690 einfo "Creating the mysql database and setting proper"
691 einfo "permissions on it ..."
692
693 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
694 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
695 local mysqld="${EROOT}/usr/sbin/mysqld \
696 ${options} \
697 --user=mysql \
698 --log-warnings=0 \
699 --basedir=${EROOT}/usr \
700 --datadir=${ROOT}/${MY_DATADIR} \
701 --max_allowed_packet=8M \
702 --net_buffer_length=16K \
703 --default-storage-engine=MyISAM \
704 --socket=${socket} \
705 --pid-file=${pidfile}"
706 #einfo "About to start mysqld: ${mysqld}"
707 ebegin "Starting mysqld"
708 einfo "Command ${mysqld}"
709 ${mysqld} &
710 rc=$?
711 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
712 maxtry=$((${maxtry}-1))
713 echo -n "."
714 sleep 1
715 done
716 eend $rc
717
718 if ! [[ -S "${socket}" ]]; then
719 die "Completely failed to start up mysqld with: ${mysqld}"
720 fi
721
722 ebegin "Setting root password"
723 # Do this from memory, as we don't want clear text passwords in temp files
724 local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'"
725 "${EROOT}/usr/bin/mysql" \
726 --socket=${socket} \
727 -hlocalhost \
728 -e "${sql}"
729 eend $?
730
731 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..."
732 "${EROOT}/usr/bin/mysql" \
733 --socket=${socket} \
734 -hlocalhost \
735 -uroot \
736 --password="${MYSQL_ROOT_PASSWORD}" \
737 mysql < "${sqltmp}"
738 rc=$?
739 eend $?
740 [ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!"
741
742 # Stop the server and cleanup
743 einfo "Stopping the server ..."
744 kill $(< "${pidfile}" )
745 rm -f "${sqltmp}"
746 wait %1
747 einfo "Done"
748 }
749
750 # @FUNCTION: mysql-v2_pkg_postrm
751 # @DESCRIPTION:
752 # Remove mysql symlinks.
753 mysql-v2_pkg_postrm() {
754
755 : # mysql_lib_symlinks "${ED}"
756 }

  ViewVC Help
Powered by ViewVC 1.1.20