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

Contents of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (hide annotations) (download)
Mon Jan 9 10:42:19 2012 UTC (2 years, 8 months ago) by grobian
Branch: MAIN
Changes since 1.13: +1 -1 lines
Restore incorrectly removed eclasses, wrong repo

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

  ViewVC Help
Powered by ViewVC 1.1.20