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

Contents of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (show annotations) (download)
Thu Sep 27 16:35:41 2012 UTC (18 months, 3 weeks ago) by axs
Branch: MAIN
Changes since 1.18: +2 -2 lines
naive bump of all EAPI-specific checks in eclasses to permit EAPI=5 where EAPI=4 was previously allowed

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

  ViewVC Help
Powered by ViewVC 1.1.20