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

Diff of /eclass/mysql-v2.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.16 Revision 1.21
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2012 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/mysql-v2.eclass,v 1.16 2012/05/06 10:42:36 heroxbd Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/mysql-v2.eclass,v 1.21 2012/11/01 23:57:50 robbat2 Exp $
4 4
5# @ECLASS: mysql-v2.eclass 5# @ECLASS: mysql-v2.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Maintainers: 7# Maintainers:
8# - MySQL Team <mysql-bugs@gentoo.org> 8# - MySQL Team <mysql-bugs@gentoo.org>
51# 51#
52# Supported EAPI versions and export functions 52# Supported EAPI versions and export functions
53# 53#
54 54
55case "${EAPI:-0}" in 55case "${EAPI:-0}" in
56 3|4) ;; 56 3|4|5) ;;
57 *) die "Unsupported EAPI: ${EAPI}" ;; 57 *) die "Unsupported EAPI: ${EAPI}" ;;
58esac 58esac
59 59
60EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_install pkg_preinst pkg_postinst pkg_config pkg_postrm 60EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_install pkg_preinst pkg_postinst pkg_config pkg_postrm
61 61
174IUSE="${IUSE} max-idx-128" 174IUSE="${IUSE} max-idx-128"
175IUSE="${IUSE} berkdb" 175IUSE="${IUSE} berkdb"
176IUSE="${IUSE} +community profiling" 176IUSE="${IUSE} +community profiling"
177 177
178[[ ${PN} == "mariadb" ]] \ 178[[ ${PN} == "mariadb" ]] \
179&& mysql_check_version_range "5.1.38 to 5.3.99" \
179&& IUSE="${IUSE} libevent" 180&& IUSE="${IUSE} libevent"
180 181
181[[ ${PN} == "mariadb" ]] \ 182[[ ${PN} == "mariadb" ]] \
182&& mysql_version_is_at_least "5.2" \ 183&& mysql_version_is_at_least "5.2" \
183&& IUSE="${IUSE} oqgraph" 184&& IUSE="${IUSE} oqgraph"
184 185
185[[ ${PN} == "mariadb" ]] \ 186[[ ${PN} == "mariadb" ]] \
186&& mysql_version_is_at_least "5.2.5" \ 187&& mysql_version_is_at_least "5.2.5" \
187&& IUSE="${IUSE} sphinx" 188&& IUSE="${IUSE} sphinx"
189
190if mysql_version_is_at_least "5.5"; then
191 REQUIRED_USE="tcmalloc? ( !jemalloc ) jemalloc? ( !tcmalloc )"
192 IUSE="${IUSE} jemalloc tcmalloc"
193fi
188 194
189mysql_version_is_at_least "5.5.7" \ 195mysql_version_is_at_least "5.5.7" \
190&& IUSE="${IUSE} systemtap" 196&& IUSE="${IUSE} systemtap"
191 197
192# 198#
203 >=sys-libs/readline-4.1 209 >=sys-libs/readline-4.1
204 >=sys-libs/zlib-1.2.3 210 >=sys-libs/zlib-1.2.3
205" 211"
206 212
207[[ ${PN} == mariadb ]] \ 213[[ ${PN} == mariadb ]] \
214&& mysql_check_version_range "5.1.38 to 5.3.99" \
208&& DEPEND="${DEPEND} libevent? ( >=dev-libs/libevent-1.4 )" 215&& DEPEND="${DEPEND} libevent? ( >=dev-libs/libevent-1.4 )"
209 216
210# Having different flavours at the same time is not a good idea 217# Having different flavours at the same time is not a good idea
211for i in "mysql" "mariadb" ; do 218for i in "mysql" "mariadb" ; do
212 [[ ${i} == ${PN} ]] || 219 [[ ${i} == ${PN} ]] ||
221 228
222DEPEND="${DEPEND} 229DEPEND="${DEPEND}
223 virtual/yacc 230 virtual/yacc
224" 231"
225 232
226DEPEND="${DEPEND} static? ( || ( sys-libs/ncurses[static-libs] <=sys-libs/ncurses-5.7-r3 ) )" 233DEPEND="${DEPEND} static? ( sys-libs/ncurses[static-libs] )"
227 234
228# compile-time-only 235# compile-time-only
229DEPEND="${DEPEND} >=dev-util/cmake-2.4.3" 236DEPEND="${DEPEND} >=dev-util/cmake-2.4.3"
230 237
231# compile-time-only 238# compile-time-only
239[[ "${PN}" == "mariadb" ]] \ 246[[ "${PN}" == "mariadb" ]] \
240&& mysql_version_is_at_least "5.2.5" \ 247&& mysql_version_is_at_least "5.2.5" \
241&& DEPEND="${DEPEND} sphinx? ( app-misc/sphinx )" 248&& DEPEND="${DEPEND} sphinx? ( app-misc/sphinx )"
242 249
243mysql_version_is_at_least "5.5.7" \ 250mysql_version_is_at_least "5.5.7" \
244&& DEPEND="${DEPEND} systemtap? ( >=dev-util/systemtap-1.3 )" 251&& DEPEND="${DEPEND} systemtap? ( >=dev-util/systemtap-1.3 )" \
252&& DEPEND="${DEPEND} kernel_linux? ( dev-libs/libaio )"
253
254mysql_version_is_at_least "5.5" \
255&& DEPEND="${DEPEND} jemalloc? ( dev-libs/jemalloc )"
256
257mysql_version_is_at_least "5.5" \
258&& DEPEND="${DEPEND} tcmalloc? ( dev-util/google-perftools )"
245 259
246# dev-perl/DBD-mysql is needed by some scripts installed by MySQL 260# dev-perl/DBD-mysql is needed by some scripts installed by MySQL
247PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )" 261PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 )"
248 262
249# For other stuff to bring us in 263# For other stuff to bring us in
493 elog "mysql_upgrade tool." 507 elog "mysql_upgrade tool."
494 einfo 508 einfo
495 fi 509 fi
496 510
497 if pbxt_available && use pbxt ; then 511 if pbxt_available && use pbxt ; then
498 # TODO: explain it better 512 elog "Note: PBXT is now statically built when enabled."
499 elog " mysql> INSTALL PLUGIN pbxt SONAME 'libpbxt.so';" 513 elog ""
500 elog " mysql> CREATE TABLE t1 (c1 int, c2 text) ENGINE=pbxt;" 514 elog "If, you previously installed as a plugin and "
501 elog "if, after that, you cannot start the MySQL server," 515 elog "you cannot start the MySQL server,"
502 elog "remove the ${MY_DATADIR}/mysql/plugin.* files, then" 516 elog "remove the ${MY_DATADIR}/mysql/plugin.* files, then"
503 elog "use the MySQL upgrade script to restore the table" 517 elog "use the MySQL upgrade script to restore the table"
504 elog "or execute the following SQL command:" 518 elog "or execute the following SQL command:"
505 elog " CREATE TABLE IF NOT EXISTS plugin (" 519 elog " CREATE TABLE IF NOT EXISTS plugin ("
506 elog " name char(64) binary DEFAULT '' NOT NULL," 520 elog " name char(64) binary DEFAULT '' NOT NULL,"
512 mysql_check_version_range "4.0 to 5.0.99.99" \ 526 mysql_check_version_range "4.0 to 5.0.99.99" \
513 && use berkdb \ 527 && use berkdb \
514 && elog "Berkeley DB support is deprecated and will be removed in future versions!" 528 && elog "Berkeley DB support is deprecated and will be removed in future versions!"
515} 529}
516 530
531# @FUNCTION: mysql-v2_getopt
532# @DESCRIPTION:
533# Use my_print_defaults to extract specific config options
534mysql-v2_getopt() {
535 local mypd="${EROOT}"/usr/bin/my_print_defaults
536 section="$1"
537 flag="--${2}="
538 "${mypd}" $section | sed -n "/^${flag}/p"
539}
540
541# @FUNCTION: mysql-v2_getoptval
542# @DESCRIPTION:
543# Use my_print_defaults to extract specific config options
544mysql-v2_getoptval() {
545 local mypd="${EROOT}"/usr/bin/my_print_defaults
546 section="$1"
547 flag="--${2}="
548 "${mypd}" $section | sed -n "/^${flag}/s,${flag},,gp"
549}
550
517# @FUNCTION: mysql-v2_pkg_config 551# @FUNCTION: mysql-v2_pkg_config
518# @DESCRIPTION: 552# @DESCRIPTION:
519# Configure mysql environment. 553# Configure mysql environment.
520mysql-v2_pkg_config() { 554mysql-v2_pkg_config() {
521 555
522 local old_MY_DATADIR="${MY_DATADIR}" 556 local old_MY_DATADIR="${MY_DATADIR}"
557 local old_HOME="${HOME}"
558 # my_print_defaults needs to read stuff in $HOME/.my.cnf
559 export HOME=/root
523 560
524 # Make sure the vars are correctly initialized 561 # Make sure the vars are correctly initialized
525 mysql_init_vars 562 mysql_init_vars
526 563
527 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR" 564 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
529 if built_with_use ${CATEGORY}/${PN} minimal ; then 566 if built_with_use ${CATEGORY}/${PN} minimal ; then
530 die "Minimal builds do NOT include the MySQL server" 567 die "Minimal builds do NOT include the MySQL server"
531 fi 568 fi
532 569
533 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then 570 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
534 local MY_DATADIR_s="$(strip_duplicate_slashes ${ROOT}/${MY_DATADIR})" 571 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
572 MY_DATADIR_s="${MY_DATADIR_s%%/}"
535 local old_MY_DATADIR_s="$(strip_duplicate_slashes ${ROOT}/${old_MY_DATADIR})" 573 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
574 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
536 575
537 if [[ -d "${old_MY_DATADIR_s}" ]]; then 576 if [[ -d "${old_MY_DATADIR_s}" ]] && [[ "${old_MY_DATADIR_s}" != / ]]; then
538 if [[ -d "${MY_DATADIR_s}" ]]; then 577 if [[ -d "${MY_DATADIR_s}" ]]; then
539 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist" 578 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist"
540 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}" 579 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
541 else 580 else
542 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}" 581 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
556 595
557 local pwd1="a" 596 local pwd1="a"
558 local pwd2="b" 597 local pwd2="b"
559 local maxtry=15 598 local maxtry=15
560 599
561 if [ -z "${MYSQL_ROOT_PASSWORD}" -a -f "${EROOT}/root/.my.cnf" ]; then 600 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
562 MYSQL_ROOT_PASSWORD="$(sed -n -e '/^password=/s,^password=,,gp' "${EROOT}/root/.my.cnf")" 601 MYSQL_ROOT_PASSWORD="$(mysql-v2_getoptval 'client mysql' password)"
602 fi
603 MYSQL_TMPDIR="$(mysql-v2_getoptval mysqld tmpdir)"
604 # These are dir+prefix
605 MYSQL_RELAY_LOG="$(mysql-v2_getoptval mysqld relay-log)"
606 MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
607 MYSQL_LOG_BIN="$(mysql-v2_getoptval mysqld log-bin)"
608 MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
609
610 if [[ ! -d "${EROOT}"/$MYSQL_TMPDIR ]]; then
611 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
612 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_TMPDIR
613 fi
614 if [[ ! -d "${EROOT}"/$MYSQL_LOG_BIN ]]; then
615 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
616 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_LOG_BIN
617 fi
618 if [[ ! -d "${EROOT}"/$MYSQL_RELAY_LOG ]]; then
619 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
620 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_RELAY_LOG
563 fi 621 fi
564 622
565 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then 623 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
566 ewarn "You have already a MySQL database in place." 624 ewarn "You have already a MySQL database in place."
567 ewarn "(${ROOT}/${MY_DATADIR}/*)" 625 ewarn "(${ROOT}/${MY_DATADIR}/*)"
588 fi 646 fi
589 MYSQL_ROOT_PASSWORD="${pwd1}" 647 MYSQL_ROOT_PASSWORD="${pwd1}"
590 unset pwd1 pwd2 648 unset pwd1 pwd2
591 fi 649 fi
592 650
593 local options="" 651 local options="--log-warnings=0"
594 local sqltmp="$(emktemp)" 652 local sqltmp="$(emktemp)"
595 653
596 local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql" 654 local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
597 [[ -r "${help_tables}" ]] \ 655 [[ -r "${help_tables}" ]] \
598 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \ 656 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
599 || touch "${TMPDIR}/fill_help_tables.sql" 657 || touch "${TMPDIR}/fill_help_tables.sql"
600 help_tables="${TMPDIR}/fill_help_tables.sql" 658 help_tables="${TMPDIR}/fill_help_tables.sql"
659
660 # Figure out which options we need to disable to do the setup
661 helpfile="${TMPDIR}/mysqld-help"
662 ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
663 for opt in grant-tables host-cache name-resolve networking slave-start bdb \
664 federated innodb ssl log-bin relay-log slow-query-log external-locking \
665 ndbcluster log-slave-updates \
666 ; do
667 optexp="--(skip-)?${opt}" optfull="--loose-skip-${opt}"
668 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
669 done
670 # But some options changed names
671 egrep -sq external-locking "${helpfile}" && \
672 options="${options/skip-locking/skip-external-locking}"
673
674 use prefix || options="${options} --user=mysql"
601 675
602 pushd "${TMPDIR}" &>/dev/null 676 pushd "${TMPDIR}" &>/dev/null
603 "${EROOT}/usr/bin/mysql_install_db" "--basedir=${EPREFIX}/usr" >"${TMPDIR}"/mysql_install_db.log 2>&1 677 #cmd="'${EROOT}/usr/share/mysql/scripts/mysql_install_db' '--basedir=${EPREFIX}/usr' ${options}"
678 cmd=${EROOT}usr/share/mysql/scripts/mysql_install_db
679 [ -f ${cmd} ] || cmd=${EROOT}usr/bin/mysql_install_db
680 cmd="'$cmd' '--basedir=${EPREFIX}/usr' ${options}"
681 einfo "Command: $cmd"
682 eval $cmd \
683 >"${TMPDIR}"/mysql_install_db.log 2>&1
604 if [ $? -ne 0 ]; then 684 if [ $? -ne 0 ]; then
605 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2 685 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2
606 die "Failed to run mysql_install_db. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log" 686 die "Failed to run mysql_install_db. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
607 fi 687 fi
608 popd &>/dev/null 688 popd &>/dev/null
609 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \ 689 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
610 || die "MySQL databases not installed" 690 || die "MySQL databases not installed"
611 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null 691 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
612 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null 692 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
613 693
614 # Figure out which options we need to disable to do the setup
615 helpfile="${TMPDIR}/mysqld-help"
616 ${EROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
617 for opt in grant-tables host-cache name-resolve networking slave-start bdb \
618 federated innodb ssl log-bin relay-log slow-query-log external-locking \
619 ndbcluster \
620 ; do
621 optexp="--(skip-)?${opt}" optfull="--skip-${opt}"
622 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
623 done
624 # But some options changed names
625 egrep -sq external-locking "${helpfile}" && \
626 options="${options/skip-locking/skip-external-locking}"
627
628 # Filling timezones, see 694 # Filling timezones, see
629 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html 695 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
630 "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null 696 "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
631 697
632 if [[ -r "${help_tables}" ]] ; then 698 if [[ -r "${help_tables}" ]] ; then
639 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock" 705 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
640 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid" 706 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
641 local mysqld="${EROOT}/usr/sbin/mysqld \ 707 local mysqld="${EROOT}/usr/sbin/mysqld \
642 ${options} \ 708 ${options} \
643 --user=mysql \ 709 --user=mysql \
710 --log-warnings=0 \
644 --basedir=${EROOT}/usr \ 711 --basedir=${EROOT}/usr \
645 --datadir=${ROOT}/${MY_DATADIR} \ 712 --datadir=${ROOT}/${MY_DATADIR} \
646 --max_allowed_packet=8M \ 713 --max_allowed_packet=8M \
647 --net_buffer_length=16K \ 714 --net_buffer_length=16K \
648 --default-storage-engine=MyISAM \ 715 --default-storage-engine=MyISAM \
649 --socket=${socket} \ 716 --socket=${socket} \
650 --pid-file=${pidfile}" 717 --pid-file=${pidfile}"
651 #einfo "About to start mysqld: ${mysqld}" 718 #einfo "About to start mysqld: ${mysqld}"
652 ebegin "Starting mysqld" 719 ebegin "Starting mysqld"
720 einfo "Command ${mysqld}"
653 ${mysqld} & 721 ${mysqld} &
654 rc=$? 722 rc=$?
655 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do 723 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
656 maxtry=$((${maxtry}-1)) 724 maxtry=$((${maxtry}-1))
657 echo -n "." 725 echo -n "."
675 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..." 743 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..."
676 "${EROOT}/usr/bin/mysql" \ 744 "${EROOT}/usr/bin/mysql" \
677 --socket=${socket} \ 745 --socket=${socket} \
678 -hlocalhost \ 746 -hlocalhost \
679 -uroot \ 747 -uroot \
680 -p"${MYSQL_ROOT_PASSWORD}" \ 748 --password="${MYSQL_ROOT_PASSWORD}" \
681 mysql < "${sqltmp}" 749 mysql < "${sqltmp}"
682 rc=$? 750 rc=$?
683 eend $? 751 eend $?
684 [ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!" 752 [ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!"
685 753

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.20