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

Contents of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.24 - (hide annotations) (download)
Wed Feb 13 00:40:57 2013 UTC (17 months, 1 week ago) by robbat2
Branch: MAIN
Changes since 1.23: +28 -2 lines
Bug #455462: Libtool cleanup; Bug #455016: mariadb mytop deps; Bug #448598: USE=pam support.

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

  ViewVC Help
Powered by ViewVC 1.1.20