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

Contents of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Sun Aug 21 16:14:56 2011 UTC (3 years, 1 month ago) by jmbsvicetto
Branch: MAIN
Changes since 1.5: +4 -1 lines
[eclass] Move virtual/yacc dependency so that it's not added to RDEPEND. Fixes bug 379937.

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

  ViewVC Help
Powered by ViewVC 1.1.20