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

Contents of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Wed Jul 20 14:23:11 2011 UTC (3 years, 2 months ago) by jmbsvicetto
Branch: MAIN
Changes since 1.1: +1 -1 lines
[eclass/mysql-v2] Sync with overlay, exports pkg_config - bug 375705.

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

  ViewVC Help
Powered by ViewVC 1.1.20