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

Contents of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Thu Jul 21 05:57:22 2011 UTC (3 years, 1 month ago) by jmbsvicetto
Branch: MAIN
Changes since 1.3: +3 -2 lines
[eclass/mysql-v2] Add my local space as an alternative SRC_URI.

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

  ViewVC Help
Powered by ViewVC 1.1.20