/[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.17 Revision 1.20
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.17 2012/07/23 10:57:15 jmbsvicetto Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/mysql-v2.eclass,v 1.20 2012/11/01 20:22:57 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
512 mysql_check_version_range "4.0 to 5.0.99.99" \ 512 mysql_check_version_range "4.0 to 5.0.99.99" \
513 && use berkdb \ 513 && use berkdb \
514 && elog "Berkeley DB support is deprecated and will be removed in future versions!" 514 && elog "Berkeley DB support is deprecated and will be removed in future versions!"
515} 515}
516 516
517# @FUNCTION: mysql-v2_getopt
518# @DESCRIPTION:
519# Use my_print_defaults to extract specific config options
520mysql-v2_getopt() {
521 local mypd="${EROOT}"/usr/bin/my_print_defaults
522 section="$1"
523 flag="--${2}="
524 "${mypd}" $section | sed -n "/^${flag}/p"
525}
526
527# @FUNCTION: mysql-v2_getoptval
528# @DESCRIPTION:
529# Use my_print_defaults to extract specific config options
530mysql-v2_getoptval() {
531 local mypd="${EROOT}"/usr/bin/my_print_defaults
532 section="$1"
533 flag="--${2}="
534 "${mypd}" $section | sed -n "/^${flag}/s,${flag},,gp"
535}
536
517# @FUNCTION: mysql-v2_pkg_config 537# @FUNCTION: mysql-v2_pkg_config
518# @DESCRIPTION: 538# @DESCRIPTION:
519# Configure mysql environment. 539# Configure mysql environment.
520mysql-v2_pkg_config() { 540mysql-v2_pkg_config() {
521 541
522 local old_MY_DATADIR="${MY_DATADIR}" 542 local old_MY_DATADIR="${MY_DATADIR}"
543 local old_HOME="${HOME}"
544 # my_print_defaults needs to read stuff in $HOME/.my.cnf
545 export HOME=/root
523 546
524 # Make sure the vars are correctly initialized 547 # Make sure the vars are correctly initialized
525 mysql_init_vars 548 mysql_init_vars
526 549
527 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR" 550 [[ -z "${MY_DATADIR}" ]] && die "Sorry, unable to find MY_DATADIR"
529 if built_with_use ${CATEGORY}/${PN} minimal ; then 552 if built_with_use ${CATEGORY}/${PN} minimal ; then
530 die "Minimal builds do NOT include the MySQL server" 553 die "Minimal builds do NOT include the MySQL server"
531 fi 554 fi
532 555
533 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then 556 if [[ ( -n "${MY_DATADIR}" ) && ( "${MY_DATADIR}" != "${old_MY_DATADIR}" ) ]]; then
534 local MY_DATADIR_s="$(strip_duplicate_slashes ${ROOT}/${MY_DATADIR})" 557 local MY_DATADIR_s="${ROOT}/${MY_DATADIR}"
558 MY_DATADIR_s="${MY_DATADIR_s%%/}"
535 local old_MY_DATADIR_s="$(strip_duplicate_slashes ${ROOT}/${old_MY_DATADIR})" 559 local old_MY_DATADIR_s="${ROOT}/${old_MY_DATADIR}"
560 old_MY_DATADIR_s="${old_MY_DATADIR_s%%/}"
536 561
537 if [[ -d "${old_MY_DATADIR_s}" ]]; then 562 if [[ -d "${old_MY_DATADIR_s}" ]] && [[ "${old_MY_DATADIR_s}" != / ]]; then
538 if [[ -d "${MY_DATADIR_s}" ]]; then 563 if [[ -d "${MY_DATADIR_s}" ]]; then
539 ewarn "Both ${old_MY_DATADIR_s} and ${MY_DATADIR_s} exist" 564 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}" 565 ewarn "Attempting to use ${MY_DATADIR_s} and preserving ${old_MY_DATADIR_s}"
541 else 566 else
542 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}" 567 elog "Moving MY_DATADIR from ${old_MY_DATADIR_s} to ${MY_DATADIR_s}"
556 581
557 local pwd1="a" 582 local pwd1="a"
558 local pwd2="b" 583 local pwd2="b"
559 local maxtry=15 584 local maxtry=15
560 585
561 if [ -z "${MYSQL_ROOT_PASSWORD}" -a -f "${EROOT}/root/.my.cnf" ]; then 586 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
562 MYSQL_ROOT_PASSWORD="$(sed -n -e '/^password=/s,^password=,,gp' "${EROOT}/root/.my.cnf")" 587 MYSQL_ROOT_PASSWORD="$(mysql-v2_getoptval 'client mysql' password)"
588 fi
589 MYSQL_TMPDIR="$(mysql-v2_getoptval mysqld tmpdir)"
590 # These are dir+prefix
591 MYSQL_RELAY_LOG="$(mysql-v2_getoptval mysqld relay-log)"
592 MYSQL_RELAY_LOG=${MYSQL_RELAY_LOG%/*}
593 MYSQL_LOG_BIN="$(mysql-v2_getoptval mysqld log-bin)"
594 MYSQL_LOG_BIN=${MYSQL_LOG_BIN%/*}
595
596 if [[ ! -d "${EROOT}"/$MYSQL_TMPDIR ]]; then
597 einfo "Creating MySQL tmpdir $MYSQL_TMPDIR"
598 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_TMPDIR
599 fi
600 if [[ ! -d "${EROOT}"/$MYSQL_LOG_BIN ]]; then
601 einfo "Creating MySQL log-bin directory $MYSQL_LOG_BIN"
602 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_LOG_BIN
603 fi
604 if [[ ! -d "${EROOT}"/$MYSQL_RELAY_LOG ]]; then
605 einfo "Creating MySQL relay-log directory $MYSQL_RELAY_LOG"
606 install -d -m 770 -o mysql -g mysql "${EROOT}"/$MYSQL_RELAY_LOG
563 fi 607 fi
564 608
565 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then 609 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
566 ewarn "You have already a MySQL database in place." 610 ewarn "You have already a MySQL database in place."
567 ewarn "(${ROOT}/${MY_DATADIR}/*)" 611 ewarn "(${ROOT}/${MY_DATADIR}/*)"
588 fi 632 fi
589 MYSQL_ROOT_PASSWORD="${pwd1}" 633 MYSQL_ROOT_PASSWORD="${pwd1}"
590 unset pwd1 pwd2 634 unset pwd1 pwd2
591 fi 635 fi
592 636
593 local options="" 637 local options="--log-warnings=0"
594 local sqltmp="$(emktemp)" 638 local sqltmp="$(emktemp)"
595 639
596 local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql" 640 local help_tables="${ROOT}${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
597 [[ -r "${help_tables}" ]] \ 641 [[ -r "${help_tables}" ]] \
598 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \ 642 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
599 || touch "${TMPDIR}/fill_help_tables.sql" 643 || touch "${TMPDIR}/fill_help_tables.sql"
600 help_tables="${TMPDIR}/fill_help_tables.sql" 644 help_tables="${TMPDIR}/fill_help_tables.sql"
645
646 # Figure out which options we need to disable to do the setup
647 helpfile="${TMPDIR}/mysqld-help"
648 ${EROOT}/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 log-slave-updates \
652 ; do
653 optexp="--(skip-)?${opt}" optfull="--loose-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 use prefix || options="${options} --user=mysql"
601 661
602 pushd "${TMPDIR}" &>/dev/null 662 pushd "${TMPDIR}" &>/dev/null
603 "${EROOT}/usr/bin/mysql_install_db" "--basedir=${EPREFIX}/usr" >"${TMPDIR}"/mysql_install_db.log 2>&1 663 #cmd="'${EROOT}/usr/share/mysql/scripts/mysql_install_db' '--basedir=${EPREFIX}/usr' ${options}"
664 cmd=${EROOT}usr/share/mysql/scripts/mysql_install_db
665 [ -f ${cmd} ] || cmd=${EROOT}usr/bin/mysql_install_db
666 cmd="'$cmd' '--basedir=${EPREFIX}/usr' ${options}"
667 einfo "Command: $cmd"
668 eval $cmd \
669 >"${TMPDIR}"/mysql_install_db.log 2>&1
604 if [ $? -ne 0 ]; then 670 if [ $? -ne 0 ]; then
605 grep -B5 -A999 -i "ERROR" "${TMPDIR}"/mysql_install_db.log 1>&2 671 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" 672 die "Failed to run mysql_install_db. Please review ${EPREFIX}/var/log/mysql/mysqld.err AND ${TMPDIR}/mysql_install_db.log"
607 fi 673 fi
608 popd &>/dev/null 674 popd &>/dev/null
609 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \ 675 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
610 || die "MySQL databases not installed" 676 || die "MySQL databases not installed"
611 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null 677 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
612 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null 678 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
613 679
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 680 # Filling timezones, see
629 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html 681 # 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 682 "${EROOT}/usr/bin/mysql_tzinfo_to_sql" "${EROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
631 683
632 if [[ -r "${help_tables}" ]] ; then 684 if [[ -r "${help_tables}" ]] ; then
639 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock" 691 local socket="${EROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
640 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid" 692 local pidfile="${EROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
641 local mysqld="${EROOT}/usr/sbin/mysqld \ 693 local mysqld="${EROOT}/usr/sbin/mysqld \
642 ${options} \ 694 ${options} \
643 --user=mysql \ 695 --user=mysql \
696 --log-warnings=0 \
644 --basedir=${EROOT}/usr \ 697 --basedir=${EROOT}/usr \
645 --datadir=${ROOT}/${MY_DATADIR} \ 698 --datadir=${ROOT}/${MY_DATADIR} \
646 --max_allowed_packet=8M \ 699 --max_allowed_packet=8M \
647 --net_buffer_length=16K \ 700 --net_buffer_length=16K \
648 --default-storage-engine=MyISAM \ 701 --default-storage-engine=MyISAM \
649 --socket=${socket} \ 702 --socket=${socket} \
650 --pid-file=${pidfile}" 703 --pid-file=${pidfile}"
651 #einfo "About to start mysqld: ${mysqld}" 704 #einfo "About to start mysqld: ${mysqld}"
652 ebegin "Starting mysqld" 705 ebegin "Starting mysqld"
706 einfo "Command ${mysqld}"
653 ${mysqld} & 707 ${mysqld} &
654 rc=$? 708 rc=$?
655 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do 709 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
656 maxtry=$((${maxtry}-1)) 710 maxtry=$((${maxtry}-1))
657 echo -n "." 711 echo -n "."
675 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..." 729 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..."
676 "${EROOT}/usr/bin/mysql" \ 730 "${EROOT}/usr/bin/mysql" \
677 --socket=${socket} \ 731 --socket=${socket} \
678 -hlocalhost \ 732 -hlocalhost \
679 -uroot \ 733 -uroot \
680 -p"${MYSQL_ROOT_PASSWORD}" \ 734 --password="${MYSQL_ROOT_PASSWORD}" \
681 mysql < "${sqltmp}" 735 mysql < "${sqltmp}"
682 rc=$? 736 rc=$?
683 eend $? 737 eend $?
684 [ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!" 738 [ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!"
685 739

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.20

  ViewVC Help
Powered by ViewVC 1.1.20