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

Contents of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Mon Aug 22 04:46:32 2011 UTC (3 years, 1 month ago) by vapier
Branch: MAIN
Changes since 1.6: +5 -4 lines
fix random bugs in eclass documentation, and convert to new @AUTHOR tag

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

  ViewVC Help
Powered by ViewVC 1.1.20