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

Contents of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Fri Aug 19 20:06:12 2011 UTC (3 years, 1 month ago) by jmbsvicetto
Branch: MAIN
Changes since 1.4: +1 -0 lines
[eclass] Added virtual/yacc dependency - fixes bug 376773.

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

  ViewVC Help
Powered by ViewVC 1.1.20