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

Contents of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (show annotations) (download)
Thu Nov 1 23:57:50 2012 UTC (17 months, 2 weeks ago) by robbat2
Branch: MAIN
Changes since 1.20: +19 -5 lines
Bring in MySQL overlay eclass changes for tcmalloc, jemalloc, systemtap, readline gplv3 and pbxt static build.

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.19 2012/09/27 16:35:41 axs 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="MariaDB is a MySQL fork with 3rd-party patches and additional storage engines merged."
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 mysql_version_is_at_least "5.5.7" \
196 && IUSE="${IUSE} systemtap"
197
198 #
199 # DEPENDENCIES:
200 #
201
202 # Be warned, *DEPEND are version-dependant
203 # These are used for both runtime and compiletime
204 DEPEND="
205 ssl? ( >=dev-libs/openssl-0.9.6d )
206 kernel_linux? ( sys-process/procps )
207 >=sys-apps/sed-4
208 >=sys-apps/texinfo-4.7-r1
209 >=sys-libs/readline-4.1
210 >=sys-libs/zlib-1.2.3
211 "
212
213 [[ ${PN} == mariadb ]] \
214 && mysql_check_version_range "5.1.38 to 5.3.99" \
215 && DEPEND="${DEPEND} libevent? ( >=dev-libs/libevent-1.4 )"
216
217 # Having different flavours at the same time is not a good idea
218 for i in "mysql" "mariadb" ; do
219 [[ ${i} == ${PN} ]] ||
220 DEPEND="${DEPEND} !dev-db/${i}"
221 done
222
223 # prefix: first need to implement something for #196294
224 RDEPEND="${DEPEND}
225 !minimal? ( !prefix? ( dev-db/mysql-init-scripts ) )
226 selinux? ( sec-policy/selinux-mysql )
227 "
228
229 DEPEND="${DEPEND}
230 virtual/yacc
231 "
232
233 DEPEND="${DEPEND} static? ( sys-libs/ncurses[static-libs] )"
234
235 # compile-time-only
236 DEPEND="${DEPEND} >=dev-util/cmake-2.4.3"
237
238 # compile-time-only
239 mysql_version_is_at_least "5.5.8" \
240 && DEPEND="${DEPEND} >=dev-util/cmake-2.6.3"
241
242 [[ "${PN}" == "mariadb" ]] \
243 && mysql_version_is_at_least "5.2" \
244 && DEPEND="${DEPEND} oqgraph? ( >=dev-libs/boost-1.40.0 )"
245
246 [[ "${PN}" == "mariadb" ]] \
247 && mysql_version_is_at_least "5.2.5" \
248 && DEPEND="${DEPEND} sphinx? ( app-misc/sphinx )"
249
250 mysql_version_is_at_least "5.5.7" \
251 && DEPEND="${DEPEND} systemtap? ( >=dev-util/systemtap-1.3 )" \
252 && DEPEND="${DEPEND} kernel_linux? ( dev-libs/libaio )"
253
254 mysql_version_is_at_least "5.5" \
255 && DEPEND="${DEPEND} jemalloc? ( dev-libs/jemalloc )"
256
257 mysql_version_is_at_least "5.5" \
258 && DEPEND="${DEPEND} tcmalloc? ( dev-util/google-perftools )"
259
260 # dev-perl/DBD-mysql is needed by some scripts installed by MySQL
261 PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
262
263 # For other stuff to bring us in
264 PDEPEND="${PDEPEND} =virtual/mysql-${MYSQL_PV_MAJOR}"
265
266 #
267 # External patches
268 #
269
270 # MariaDB has integrated PBXT
271 # PBXT_VERSION means that we have a PBXT patch for this PV
272 # PBXT was only introduced after 5.1.12
273 pbxt_patch_available() {
274 [[ ${PN} != "mariadb" ]] \
275 && [[ -n "${PBXT_VERSION}" ]]
276 return $?
277 }
278
279 pbxt_available() {
280 pbxt_patch_available || [[ ${PN} == "mariadb" ]]
281 return $?
282 }
283
284 # Get the percona tarball if XTRADB_VER and PERCONA_VER are both set
285 # MariaDB has integrated XtraDB
286 # XTRADB_VERS means that we have a XTRADB patch for this PV
287 # XTRADB was only introduced after 5.1.26
288 xtradb_patch_available() {
289 [[ ${PN} != "mariadb" ]] \
290 && [[ -n "${XTRADB_VER}" && -n "${PERCONA_VER}" ]]
291 return $?
292 }
293
294
295 if pbxt_patch_available; then
296
297 PBXT_P="pbxt-${PBXT_VERSION}"
298 PBXT_SRC_URI="http://www.primebase.org/download/${PBXT_P}.tar.gz mirror://sourceforge/pbxt/${PBXT_P}.tar.gz"
299 SRC_URI="${SRC_URI} pbxt? ( ${PBXT_SRC_URI} )"
300
301 fi
302
303 # PBXT_NEWSTYLE means pbxt is in storage/ and gets enabled as other plugins
304 # vs. built outside the dir
305 if pbxt_available; then
306
307 IUSE="${IUSE} pbxt"
308 PBXT_NEWSTYLE=1
309 fi
310
311 if xtradb_patch_available; then
312 XTRADB_P="percona-xtradb-${XTRADB_VER}"
313 XTRADB_SRC_URI_COMMON="${PERCONA_VER}/source/${XTRADB_P}.tar.gz"
314 XTRADB_SRC_B1="http://www.percona.com/"
315 XTRADB_SRC_B2="${XTRADB_SRC_B1}/percona-builds/"
316 XTRADB_SRC_URI1="${XTRADB_SRC_B2}/Percona-Server/Percona-Server-${XTRADB_SRC_URI_COMMON}"
317 XTRADB_SRC_URI2="${XTRADB_SRC_B2}/xtradb/${XTRADB_SRC_URI_COMMON}"
318 XTRADB_SRC_URI3="${XTRADB_SRC_B1}/${PN}/xtradb/${XTRADB_SRC_URI_COMMON}"
319 SRC_URI="${SRC_URI} xtradb? ( ${XTRADB_SRC_URI1} ${XTRADB_SRC_URI2} ${XTRADB_SRC_URI3} )"
320 IUSE="${IUSE} xtradb"
321 fi
322
323 #
324 # HELPER FUNCTIONS:
325 #
326
327 # @FUNCTION: mysql-v2_disable_test
328 # @DESCRIPTION:
329 # Helper function to disable specific tests.
330 mysql-v2_disable_test() {
331 ${BUILD_INHERIT}_disable_test "$@"
332 }
333
334 # @FUNCTION: mysql-v2_configure_minimal
335 # @DESCRIPTION:
336 # Helper function to configure minimal build
337 configure_minimal() {
338 ${BUILD_INHERIT}_configure_minimal "$@"
339 }
340
341 # @FUNCTION: mysql-v2_configure_common
342 # @DESCRIPTION:
343 # Helper function to configure common builds
344 configure_common() {
345 ${BUILD_INHERIT}_configure_common "$@"
346 }
347
348 #
349 # EBUILD FUNCTIONS
350 #
351
352 # @FUNCTION: mysql-v2_pkg_setup
353 # @DESCRIPTION:
354 # Perform some basic tests and tasks during pkg_setup phase:
355 # die if FEATURES="test", USE="-minimal" and not using FEATURES="userpriv"
356 # check for conflicting use flags
357 # create new user and group for mysql
358 # warn about deprecated features
359 mysql-v2_pkg_setup() {
360
361 if has test ${FEATURES} ; then
362 if ! use minimal ; then
363 if ! has userpriv ${FEATURES} ; then
364 eerror "Testing with FEATURES=-userpriv is no longer supported by upstream. Tests MUST be run as non-root."
365 fi
366 fi
367 fi
368
369 # Check for USE flag problems in pkg_setup
370 if use static && use ssl ; then
371 M="MySQL does not support being built statically with SSL support enabled!"
372 eerror "${M}"
373 die "${M}"
374 fi
375
376 if ! mysql_version_is_at_least "5.2" \
377 && use debug ; then
378 # Also in package.use.mask
379 die "Bug #344885: Upstream has broken USE=debug for 5.1 series >=5.1.51"
380 fi
381
382 if ( use cluster || use extraengine || use embedded ) \
383 && use minimal ; then
384 M="USE flags 'cluster', 'extraengine', 'embedded' conflict with 'minimal' USE flag!"
385 eerror "${M}"
386 die "${M}"
387 fi
388
389 if xtradb_patch_available \
390 && use xtradb \
391 && use embedded ; then
392 M="USE flags 'xtradb' and 'embedded' conflict and cause build failures"
393 eerror "${M}"
394 die "${M}"
395 fi
396
397 # This should come after all of the die statements
398 enewgroup mysql 60 || die "problem adding 'mysql' group"
399 enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
400
401 if use cluster; then
402 ewarn "Upstream has noted that the NDB cluster support in the 5.0 and"
403 ewarn "5.1 series should NOT be put into production. In the near"
404 ewarn "future, it will be disabled from building."
405 fi
406 }
407
408 # @FUNCTION: mysql-v2_src_unpack
409 # @DESCRIPTION:
410 # Unpack the source code
411 mysql-v2_src_unpack() {
412
413 # Initialize the proper variables first
414 mysql_init_vars
415
416 unpack ${A}
417 # Grab the patches
418 [[ "${MY_EXTRAS_VER}" == "live" ]] && S="${WORKDIR}/mysql-extras" git-2_src_unpack
419
420 mv -f "${WORKDIR}/${MY_SOURCEDIR}" "${S}"
421 }
422
423 # @FUNCTION: mysql-v2_src_prepare
424 # @DESCRIPTION:
425 # Apply patches to the source code and remove unneeded bundled libs.
426 mysql-v2_src_prepare() {
427 ${BUILD_INHERIT}_src_prepare "$@"
428 }
429
430 # @FUNCTION: mysql-v2_src_configure
431 # @DESCRIPTION:
432 # Configure mysql to build the code for Gentoo respecting the use flags.
433 mysql-v2_src_configure() {
434 ${BUILD_INHERIT}_src_configure "$@"
435 }
436
437 # @FUNCTION: mysql-v2_src_compile
438 # @DESCRIPTION:
439 # Compile the mysql code.
440 mysql-v2_src_compile() {
441 ${BUILD_INHERIT}_src_compile "$@"
442 }
443
444 # @FUNCTION: mysql-v2_src_install
445 # @DESCRIPTION:
446 # Install mysql.
447 mysql-v2_src_install() {
448 ${BUILD_INHERIT}_src_install "$@"
449 }
450
451 # @FUNCTION: mysql-v2_pkg_preinst
452 # @DESCRIPTION:
453 # Create the user and groups for mysql - die if that fails.
454 mysql-v2_pkg_preinst() {
455 enewgroup mysql 60 || die "problem adding 'mysql' group"
456 enewuser mysql 60 -1 /dev/null mysql || die "problem adding 'mysql' user"
457 }
458
459 # @FUNCTION: mysql-v2_pkg_postinst
460 # @DESCRIPTION:
461 # Run post-installation tasks:
462 # create the dir for logfiles if non-existant
463 # touch the logfiles and secure them
464 # install scripts
465 # issue required steps for optional features
466 # issue deprecation warnings
467 mysql-v2_pkg_postinst() {
468
469 # Make sure the vars are correctly initialized
470 mysql_init_vars
471
472 # Check FEATURES="collision-protect" before removing this
473 [[ -d "${ROOT}${MY_LOGDIR}" ]] || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
474
475 # Secure the logfiles
476 touch "${ROOT}${MY_LOGDIR}"/mysql.{log,err}
477 chown mysql:mysql "${ROOT}${MY_LOGDIR}"/mysql*
478 chmod 0660 "${ROOT}${MY_LOGDIR}"/mysql*
479
480 # Minimal builds don't have the MySQL server
481 if ! use minimal ; then
482 docinto "support-files"
483 for script in \
484 support-files/my-*.cnf \
485 support-files/magic \
486 support-files/ndb-config-2-node.ini
487 do
488 [[ -f "${script}" ]] \
489 && dodoc "${script}"
490 done
491
492 docinto "scripts"
493 for script in scripts/mysql* ; do
494 [[ -f "${script}" ]] \
495 && [[ "${script%.sh}" == "${script}" ]] \
496 && dodoc "${script}"
497 done
498
499 einfo
500 elog "You might want to run:"
501 elog "\"emerge --config =${CATEGORY}/${PF}\""
502 elog "if this is a new install."
503 einfo
504
505 einfo
506 elog "If you are upgrading major versions, you should run the"
507 elog "mysql_upgrade tool."
508 einfo
509 fi
510
511 if pbxt_available && use pbxt ; then
512 elog "Note: PBXT is now statically built when enabled."
513 elog ""
514 elog "If, you previously installed as a plugin and "
515 elog "you cannot start the MySQL server,"
516 elog "remove the ${MY_DATADIR}/mysql/plugin.* files, then"
517 elog "use the MySQL upgrade script to restore the table"
518 elog "or execute the following SQL command:"
519 elog " CREATE TABLE IF NOT EXISTS plugin ("
520 elog " name char(64) binary DEFAULT '' NOT NULL,"
521 elog " dl char(128) DEFAULT '' NOT NULL,"
522 elog " PRIMARY KEY (name)"
523 elog " ) CHARACTER SET utf8 COLLATE utf8_bin;"
524 fi
525
526 mysql_check_version_range "4.0 to 5.0.99.99" \
527 && use berkdb \
528 && elog "Berkeley DB support is deprecated and will be removed in future versions!"
529 }
530
531 # @FUNCTION: mysql-v2_getopt
532 # @DESCRIPTION:
533 # Use my_print_defaults to extract specific config options
534 mysql-v2_getopt() {
535 local mypd="${EROOT}"/usr/bin/my_print_defaults
536 section="$1"
537 flag="--${2}="
538 "${mypd}" $section | sed -n "/^${flag}/p"
539 }
540
541 # @FUNCTION: mysql-v2_getoptval
542 # @DESCRIPTION:
543 # Use my_print_defaults to extract specific config options
544 mysql-v2_getoptval() {
545 local mypd="${EROOT}"/usr/bin/my_print_defaults
546 section="$1"
547 flag="--${2}="
548 "${mypd}" $section | sed -n "/^${flag}/s,${flag},,gp"
549 }
550
551 # @FUNCTION: mysql-v2_pkg_config
552 # @DESCRIPTION:
553 # Configure mysql environment.
554 mysql-v2_pkg_config() {
555
556 local old_MY_DATADIR="${MY_DATADIR}"
557 local old_HOME="${HOME}"
558 # my_print_defaults needs to read stuff in $HOME/.my.cnf
559 export HOME=/root
560
561 # Make sure the vars are correctly initialized
562 mysql_init_vars
563
564 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
565
566 if built_with_use ${CATEGORY}/${PN} minimal ; then
567 die "Minimal builds do NOT include the MySQL server"
568 fi
569
570 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
571 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
572 MY_DATADIR_s="${MY_DATADIR_s%%/}"
573 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
574 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
575
576 if [[ -d "${old_MY_DATADIR_s}" ]] && [[ "${old_MY_DATADIR_s}" != / ]]; then
577 if [[ -d "${MY_DATADIR_s}" ]]; then
578 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
579 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
580 else
581 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
582 mv --strip-trailing-slashes -T "${old_MY_DATADIR_s}" "${MY_DATADIR_s}" \
583 || die "Moving MY_DATADIR failed"
584 fi
585 else
586 ewarn "Previous MY_DATADIR (${old_MY_DATADIR_s}) does not exist"
587 if [[ -d "${MY_DATADIR_s}" ]]; then
588 ewarn "Attempting to use ${MY_DATADIR_s}"
589 else
590 eerror "New MY_DATADIR (${MY_DATADIR_s}) does not exist"
591 die "Configuration Failed! Please reinstall ${CATEGORY}/${PN}"
592 fi
593 fi
594 fi
595
596 local pwd1="a"
597 local pwd2="b"
598 local maxtry=15
599
600 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
601 MYSQL_ROOT_PASSWORD="$(mysql-v2_getoptval 'client mysql' password)"
602 fi
603 MYSQL_TMPDIR="$(mysql-v2_getoptval mysqld tmpdir)"
604 # These are dir+prefix
605 MYSQL_RELAY_LOG="$(mysql-v2_getoptval mysqld relay-log)"
606 MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
607 MYSQL_LOG_BIN="$(mysql-v2_getoptval mysqld log-bin)"
608 MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
609
610 if [[ ! -d "${EROOT}"/$MYSQL_TMPDIR ]]; then
611 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
612 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_TMPDIR
613 fi
614 if [[ ! -d "${EROOT}"/$MYSQL_LOG_BIN ]]; then
615 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
616 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_LOG_BIN
617 fi
618 if [[ ! -d "${EROOT}"/$MYSQL_RELAY_LOG ]]; then
619 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
620 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_RELAY_LOG
621 fi
622
623 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
624 ewarn "You have already a MySQL database in place."
625 ewarn "(${ROOT}/${MY_DATADIR}/*)"
626 ewarn "Please rename or delete it if you wish to replace it."
627 die "MySQL database already exists!"
628 fi
629
630 # Bug #213475 - MySQL _will_ object strenously if your machine is named
631 # localhost. Also causes weird failures.
632 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
633
634 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
635
636 einfo "Please provide a password for the mysql 'root' user now, in the"
637 einfo "MYSQL_ROOT_PASSWORD env var or through the /root/.my.cnf file."
638 ewarn "Avoid [\"'\\_%] characters in the password"
639 read -rsp " >" pwd1 ; echo
640
641 einfo "Retype the password"
642 read -rsp " >" pwd2 ; echo
643
644 if [[ "x$pwd1" != "x$pwd2" ]] ; then
645 die "Passwords are not the same"
646 fi
647 MYSQL_ROOT_PASSWORD="${pwd1}"
648 unset pwd1 pwd2
649 fi
650
651 local options="--log-warnings=0"
652 local sqltmp="$(emktemp)"
653
654 local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
655 [[ -r "${help_tables}" ]] \
656 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
657 || touch "${TMPDIR}/fill_help_tables.sql"
658 help_tables="${TMPDIR}/fill_help_tables.sql"
659
660 # Figure out which options we need to disable to do the setup
661 helpfile="${TMPDIR}/mysqld-help"
662 ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
663 for opt in grant-tables host-cache name-resolve networking slave-start bdb \
664 federated innodb ssl log-bin relay-log slow-query-log external-locking \
665 ndbcluster log-slave-updates \
666 ; do
667 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
668 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
669 done
670 # But some options changed names
671 egrep -sq external-locking "${helpfile}" && \
672 options="${options/skip-locking/skip-external-locking}"
673
674 use prefix || options="${options} --user=mysql"
675
676 pushd "${TMPDIR}" &>/dev/null
677 #cmd="'${EROOT}/usr/share/mysql/scripts/mysql_install_db' '--basedir=${EPREFIX}/usr' ${options}"
678 cmd=${EROOT}usr/share/mysql/scripts/mysql_install_db
679 [ -f ${cmd} ] || cmd=${EROOT}usr/bin/mysql_install_db
680 cmd="'$cmd' '--basedir=${EPREFIX}/usr' ${options}"
681 einfo "Command: $cmd"
682 eval $cmd \
683 >"${TMPDIR}"/mysql_install_db.log 2>&1
684 if [ $? -ne 0 ]; then
685 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
686 die "Failed to run mysql_install_db. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
687 fi
688 popd &>/dev/null
689 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
690 || die "MySQL databases not installed"
691 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
692 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
693
694 # Filling timezones, see
695 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
696 "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
697
698 if [[ -r "${help_tables}" ]] ; then
699 cat "${help_tables}" >> "${sqltmp}"
700 fi
701
702 einfo "Creating the mysql database and setting proper"
703 einfo "permissions on it ..."
704
705 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
706 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
707 local mysqld="${EROOT}/usr/sbin/mysqld \
708 ${options} \
709 --user=mysql \
710 --log-warnings=0 \
711 --basedir=${EROOT}/usr \
712 --datadir=${ROOT}/${MY_DATADIR} \
713 --max_allowed_packet=8M \
714 --net_buffer_length=16K \
715 --default-storage-engine=MyISAM \
716 --socket=${socket} \
717 --pid-file=${pidfile}"
718 #einfo "About to start mysqld: ${mysqld}"
719 ebegin "Starting mysqld"
720 einfo "Command ${mysqld}"
721 ${mysqld} &
722 rc=$?
723 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
724 maxtry=$((${maxtry}-1))
725 echo -n "."
726 sleep 1
727 done
728 eend $rc
729
730 if ! [[ -S "${socket}" ]]; then
731 die "Completely failed to start up mysqld with: ${mysqld}"
732 fi
733
734 ebegin "Setting root password"
735 # Do this from memory, as we don't want clear text passwords in temp files
736 local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'"
737 "${EROOT}/usr/bin/mysql" \
738 --socket=${socket} \
739 -hlocalhost \
740 -e "${sql}"
741 eend $?
742
743 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..."
744 "${EROOT}/usr/bin/mysql" \
745 --socket=${socket} \
746 -hlocalhost \
747 -uroot \
748 --password="${MYSQL_ROOT_PASSWORD}" \
749 mysql < "${sqltmp}"
750 rc=$?
751 eend $?
752 [ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!"
753
754 # Stop the server and cleanup
755 einfo "Stopping the server ..."
756 kill $(< "${pidfile}" )
757 rm -f "${sqltmp}"
758 wait %1
759 einfo "Done"
760 }
761
762 # @FUNCTION: mysql-v2_pkg_postrm
763 # @DESCRIPTION:
764 # Remove mysql symlinks.
765 mysql-v2_pkg_postrm() {
766
767 : # mysql_lib_symlinks "${ED}"
768 }

  ViewVC Help
Powered by ViewVC 1.1.20