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

Contents of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download)
Sun Sep 25 12:43:28 2011 UTC (2 years, 10 months ago) by grobian
Branch: MAIN
Changes since 1.7: +3 -2 lines
mysql: don't depend on mysql-init-script in Prefix

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

  ViewVC Help
Powered by ViewVC 1.1.20