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

Diff of /eclass/mysql.eclass

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

Revision 1.6 Revision 1.15
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2005 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.eclass,v 1.6 2006/01/14 19:00:32 vivo Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/mysql.eclass,v 1.15 2006/02/08 16:17:52 vivo Exp $
4 4
5# Author: Francesco Riosa <vivo at gentoo.org> 5# Author: Francesco Riosa <vivo at gentoo.org>
6# Maintainer: Francesco Riosa <vivo at gentoo.org> 6# Maintainer: Francesco Riosa <vivo at gentoo.org>
7 7
8inherit eutils flag-o-matic gnuconfig mysql_fx 8inherit eutils flag-o-matic gnuconfig mysql_fx
14# and we will run a mysql server during test phase 14# and we will run a mysql server during test phase
15S="${WORKDIR}/${PN}" 15S="${WORKDIR}/${PN}"
16 16
17DESCRIPTION="A fast, multi-threaded, multi-user SQL database server" 17DESCRIPTION="A fast, multi-threaded, multi-user SQL database server"
18HOMEPAGE="http://www.mysql.com/" 18HOMEPAGE="http://www.mysql.com/"
19NEWP="${PN}-${PV/_/-}" 19NEWP="${P/_/-}"
20SRC_URI="mirror://mysql/Downloads/MySQL-${PV%.*}/${NEWP}.tar.gz 20SRC_URI="mirror://mysql/Downloads/MySQL-${PV%.*}/${NEWP}.tar.gz
21 mirror://gentoo/mysql-extras-20060114.tar.bz2" 21 mirror://gentoo/mysql-extras-20060115.tar.bz2"
22LICENSE="GPL-2" 22LICENSE="GPL-2"
23IUSE="big-tables berkdb debug minimal perl selinux ssl static" 23IUSE="big-tables berkdb debug minimal perl selinux srvdir ssl static"
24RESTRICT="primaryuri" 24RESTRICT="primaryuri confcache"
25DEPEND="app-admin/eselect-mysql" 25DEPEND="app-admin/eselect-mysql"
26 26
27mysql_version_is_at_least "4.01.03.00" \ 27mysql_version_is_at_least "4.01.03.00" \
28&& IUSE="${IUSE} cluster utf8 extraengine" 28&& IUSE="${IUSE} cluster extraengine"
29 29
30mysql_version_is_at_least "5.00.18.00" \ 30mysql_version_is_at_least "5.00.18.00" \
31&& IUSE="${IUSE} max-idx-128" 31&& IUSE="${IUSE} max-idx-128"
32 32
33mysql_version_is_at_least "5.01.00.00" \ 33mysql_version_is_at_least "5.01.00.00" \
34&& IUSE="${IUSE} innodb" 34&& IUSE="${IUSE} innodb"
35 35
36EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_preinst pkg_postinst pkg_config pkg_postrm 36EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_preinst pkg_postinst pkg_config mysql_pkg_prerm pkg_postrm
37
38# void mysql_init_vars()
39#
40# initialize global variables
41# 2005-11-19 <vivo at gentoo.org>
42mysql_init_vars() {
43
44 if [[ ${SLOT} -eq 0 ]] ; then
45 MY_SUFFIX=""
46 else
47 MY_SUFFIX=${MY_SUFFIX:-"-${SLOT}"}
48 fi
49 MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR:-"/usr/share/mysql${MY_SUFFIX}"}
50 MY_SYSCONFDIR=${MY_SYSCONFDIR="/etc/mysql${MY_SUFFIX}"}
51 MY_LIBDIR=${MY_LIBDIR="/usr/$(get_libdir)/mysql${MY_SUFFIX}"}
52 MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="/var/lib/mysql${MY_SUFFIX}"}
53 MY_LOGDIR=${MY_LOGDIR="/var/log/mysql${MY_SUFFIX}"}
54 MY_INCLUDEDIR=${MY_INCLUDEDIR="/usr/include/mysql${MY_SUFFIX}"}
55
56 if [ -z "${DATADIR}" ]; then
57 DATADIR=""
58 if [ -f "${SYSCONFDIR}/my.cnf" ] ; then
59 DATADIR=`"my_print_defaults${MY_SUFFIX}" mysqld 2>/dev/null | sed -ne '/datadir/s|^--datadir=||p' | tail -n1`
60 if [ -z "${DATADIR}" ]; then
61 if useq "srvdir" ; then
62 DATADIR="/srv/localhost/mysql/datadir"
63 else
64 DATADIR=`grep ^datadir "${SYSCONFDIR}/my.cnf" | sed -e 's/.*=\s*//'`
65 fi
66 fi
67 fi
68 if [ -z "${DATADIR}" ]; then
69 DATADIR="${MY_LOCALSTATEDIR}"
70 einfo "Using default DATADIR"
71 fi
72 einfo "MySQL DATADIR is ${DATADIR}"
73
74 if [ -z "${PREVIOUS_DATADIR}" ] ; then
75 if [ -a "${DATADIR}" ] ; then
76 ewarn "Previous datadir found, it's YOUR job to change"
77 ewarn "ownership and have care of it"
78 PREVIOUS_DATADIR="yes"
79 export PREVIOUS_DATADIR
80 else
81 PREVIOUS_DATADIR="no"
82 export PREVIOUS_DATADIR
83 fi
84 fi
85 fi
86
87 export MY_SUFFIX MY_SHAREDSTATEDIR MY_SYSCONFDIR
88 export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
89 export MY_INCLUDEDIR
90 export DATADIR
91}
37 92
38mysql_pkg_setup() { 93mysql_pkg_setup() {
39 94
40 enewgroup mysql 60 || die "problem adding group mysql" 95 enewgroup mysql 60 || die "problem adding group mysql"
41 enewuser mysql 60 -1 /dev/null mysql \ 96 enewuser mysql 60 -1 /dev/null mysql \
118 ${buildstep} || die "failed ${buildstep/ */} dir \"${d}\"" 173 ${buildstep} || die "failed ${buildstep/ */} dir \"${d}\""
119 done 174 done
120 popd &>/dev/null 175 popd &>/dev/null
121 done 176 done
122 177
123 if ! useq bdbdir && ! mysql_check_version_range "5.01.00.00 to 5.01.06.99" 178 if useq berkdb && ! mysql_check_version_range "5.01.00.00 to 5.01.06.99"
124 then 179 then
125 [[ -w "${bdbdir}/ltmain.sh" ]] && cp -f ltmain.sh "${bdbdir}/ltmain.sh" 180 [[ -w "${bdbdir}/ltmain.sh" ]] && cp -f ltmain.sh "${bdbdir}/ltmain.sh"
126 pushd "${bdbdir}" && sh s_all || die "failed bdb reconfigure" &>/dev/null 181 pushd "${bdbdir}" && sh s_all || die "failed bdb reconfigure" &>/dev/null
127 popd &>/dev/null 182 popd &>/dev/null
128 fi 183 fi
190 else 245 else
191 myconf="${myconf} --with-raid" 246 myconf="${myconf} --with-raid"
192 fi 247 fi
193 248
194 if ! mysql_version_is_at_least "5.00.00.00" ; then 249 if ! mysql_version_is_at_least "5.00.00.00" ; then
195 if mysql_version_is_at_least "4.01.00.00" && useq utf8; then 250 if mysql_version_is_at_least "4.01.00.00" ; then
196 myconf="${myconf} --with-charset=utf8" 251 myconf="${myconf} --with-charset=utf8"
197 myconf="${myconf} --with-collation=utf8_general_ci" 252 myconf="${myconf} --with-collation=utf8_general_ci"
198 else 253 else
199 myconf="${myconf} --with-charset=latin1" 254 myconf="${myconf} --with-charset=latin1"
200 myconf="${myconf} --with-collation=latin1_swedish_ci" 255 myconf="${myconf} --with-collation=latin1_swedish_ci"
262 if mysql_version_is_at_least "5.01.00.00" ; then 317 if mysql_version_is_at_least "5.01.00.00" ; then
263 myconf="${myconf} --with-partition" 318 myconf="${myconf} --with-partition"
264 fi 319 fi
265 fi 320 fi
266 321
322 fi
323
267 mysql_version_is_at_least "5.00.18.00" \ 324 mysql_version_is_at_least "5.00.18.00" \
268 && useq "max-idx-128" \ 325 && useq "max-idx-128" \
269 && myconf="${myconf} --with-max-indexes=128" 326 && myconf="${myconf} --with-max-indexes=128"
327
328 if mysql_version_is_at_least "5.01.05.00" ; then
329 myconf="${myconf} --with-row-based-replication"
270 fi 330 fi
271 331
272 #Bug #114895,Bug #110149 332 #Bug #114895,Bug #110149
273 filter-flags "-O" "-O[01]" 333 filter-flags "-O" "-O[01]"
274 #glibc-2.3.2_pre fix; bug #16496 334 #glibc-2.3.2_pre fix; bug #16496
293 --enable-local-infile \ 353 --enable-local-infile \
294 --with-mysqld-user=mysql \ 354 --with-mysqld-user=mysql \
295 --with-client-ldflags=-lstdc++ \ 355 --with-client-ldflags=-lstdc++ \
296 --enable-thread-safe-client \ 356 --enable-thread-safe-client \
297 --with-comment="Gentoo Linux ${PF}" \ 357 --with-comment="Gentoo Linux ${PF}" \
298 --with-unix-socket-path="/var/run/mysqld/mysqld${MY_SUFFIX}.sock" \ 358 --with-unix-socket-path="/var/run/mysqld/mysqld.sock" \
299 --with-zlib-dir=/usr \ 359 --with-zlib-dir=/usr \
300 --with-lib-ccflags="-fPIC" \ 360 --with-lib-ccflags="-fPIC" \
301 --without-readline \ 361 --without-readline \
302 --without-docs \ 362 --without-docs \
303 ${myconf} || die "bad ./configure" 363 ${myconf} || die "bad ./configure"
360 fi 420 fi
361 421
362 # config stuff 422 # config stuff
363 insinto "${MY_SYSCONFDIR}" 423 insinto "${MY_SYSCONFDIR}"
364 doins scripts/mysqlaccess.conf 424 doins scripts/mysqlaccess.conf
425 sed -e "s!@MY_SUFFIX@!${MY_SUFFIX}!g" \
426 -e "s!@DATADIR@!${DATADIR}!g" \
427 "${FILESDIR}/my.cnf-4.1-r1" \
428 > "${TMPDIR}/my.cnf.ok"
365 newins "${FILESDIR}/my.cnf-4.1" my.cnf 429 newins "${TMPDIR}/my.cnf.ok" my.cnf
430
366 insinto "/etc/conf.d" 431 insinto "/etc/conf.d"
367 newins "${FILESDIR}/mysql-slot.conf.d-r2" "mysql" 432 newins "${FILESDIR}/mysql-slot.conf.d-r1" "mysql"
368 mysql_version_is_at_least "5.00.11.00" \ 433 mysql_version_is_at_least "5.00.11.00" \
369 && newins "${FILESDIR}/mysqlmanager-slot.conf.d" "mysqlmanager" 434 && newins "${FILESDIR}/mysqlmanager-slot.conf.d" "mysqlmanager"
370
371 local charset='utf8'
372 ! useq utf8 && local charset='latin1'
373 sed --in-place \
374 -e "s/@MY_SUFFIX@/${MY_SUFFIX}/" \
375 -e "s/@CHARSET@/${charset}/" \
376 "${D}/etc/mysql${MY_SUFFIX}/my.cnf"
377 435
378 # minimal builds don't have the server 436 # minimal builds don't have the server
379 if ! useq minimal; then 437 if ! useq minimal; then
380 exeinto /etc/init.d 438 exeinto /etc/init.d
381 newexe "${FILESDIR}/mysql-slot.rc6-r2" "mysql" 439 newexe "${FILESDIR}/mysql-slot.rc6-r3" "mysql"
382 [[ ${SLOT} -gt 0 ]] && dosym "/etc/init.d/mysql" "/etc/init.d/mysql${MY_SUFFIX}"
383 440
384 mysql_version_is_at_least "5.00.11.00" \ 441 mysql_version_is_at_least "5.00.11.00" \
385 && newexe "${FILESDIR}/mysqlmanager-slot.rc6" "mysqlmanager" 442 && newexe "${FILESDIR}/mysqlmanager-slot.rc6" "mysqlmanager"
386 insinto /etc/logrotate.d 443 insinto /etc/logrotate.d
387 # TODO 444 sed -e "s!___MY_SUFFIX___!${MY_SUFFIX}!g" \
445 "${FILESDIR}/logrotate-slot.mysql" \
446 > "${TMPDIR}/logrotate.mysql"
388 newins "${FILESDIR}/logrotate.mysql" "mysql${MY_SUFFIX}" 447 newins "${TMPDIR}/logrotate.mysql" "mysql${MY_SUFFIX}"
389 448
390 #empty dirs... 449 #empty dirs...
391 diropts "-m0750" 450 diropts "-m0750"
392 if [[ "${PREVIOUS_DATADIR}" != "yes" ]] ; then 451 if [[ "${PREVIOUS_DATADIR}" != "yes" ]] ; then
393 dodir "${DATADIR}" 452 dodir "${DATADIR}"
425 # oops, temporary fix 484 # oops, temporary fix
426 mysql_check_version_range "5.00.16.00 to 5.00.18.99" \ 485 mysql_check_version_range "5.00.16.00 to 5.00.18.99" \
427 && cp -f \ 486 && cp -f \
428 "${WORKDIR}/mysql-extras/fill_help_tables.sql-5.0" \ 487 "${WORKDIR}/mysql-extras/fill_help_tables.sql-5.0" \
429 "${D}/usr/share/mysql${MY_SUFFIX}/fill_help_tables.sql" 488 "${D}/usr/share/mysql${MY_SUFFIX}/fill_help_tables.sql"
430}
431 489
432mysql_pkg_preinst() { 490 # MOVED HERE DUE TO BUG #121445
433
434 enewgroup mysql 60 || die "problem adding group mysql"
435 enewuser mysql 60 -1 /dev/null mysql \
436 || die "problem adding user mysql"
437}
438
439mysql_pkg_postinst() {
440
441 mysql_init_vars
442 mysql_lib_symlinks
443
444 # mind at FEATURES=collision-protect before to remove this
445 [ -d "${ROOT}/var/log/mysql" ] \
446 || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
447
448 #secure the logfiles... does this bother anybody?
449 touch "${ROOT}${MY_LOGDIR}"/mysql.{log,err}
450 chown mysql:mysql "${ROOT}${MY_LOGDIR}"/mysql*
451 chmod 0660 "${ROOT}${MY_LOGDIR}"/mysql*
452
453 # create a list of files, to be used 491 # create a list of files, to be used
454 # by external utilities 492 # by external utilities
455 # uncompressed because of the small size 493 mkdir -p "${D}/var/lib/eselect/mysql/"
456 local filelist="${ROOT}/var/lib/eselect/mysql/mysql${MY_SUFFIX}" 494 local filelist="${D}/var/lib/eselect/mysql/mysql${MY_SUFFIX}.filelist"
457 pushd "${D}/" &>/dev/null 495 pushd "${D}/" &>/dev/null
458 mkdir -p "${ROOT}/var/lib/eselect/mysql/" 496 mkdir -p "${ROOT}/var/lib/eselect/mysql/"
459 env -i find usr/bin/ usr/sbin/ usr/share/man \ 497 env -i find usr/bin/ usr/sbin/ usr/share/man \
460 -type f -name "*${MY_SUFFIX}*" \ 498 -type f -name "*${MY_SUFFIX}*" \
461 -and -not -name "mysql_config${MY_SUFFIX}" \ 499 -and -not -name "mysql_config${MY_SUFFIX}" \
462 > "${filelist}.filelist" 500 > "${filelist}"
463 echo "${MY_SYSCONFDIR#"/"}" >> "${filelist}.filelist" 501 echo "${MY_SYSCONFDIR#"/"}" >> "${filelist}"
464 echo "${MY_LIBDIR#"/"}" >> "${filelist}.filelist" 502 echo "${MY_LIBDIR#"/"}" >> "${filelist}"
465 echo "${MY_SHAREDSTATEDIR#"/"}" >> "${filelist}.filelist" 503 echo "${MY_SHAREDSTATEDIR#"/"}" >> "${filelist}"
466 popd &>/dev/null 504 popd &>/dev/null
505
506}
507
508mysql_pkg_preinst() {
509
510 ## create a list of files, to be used
511 ## by external utilities
512 ## will be used in pkg_postinst
513 #local filelist="${TMPDIR}/FILELIST"
514 #pushd "${D}/" &>/dev/null
515 # mkdir -p "${ROOT}/var/lib/eselect/mysql/"
516 # env -i find usr/bin/ usr/sbin/ usr/share/man \
517 # -type f -name "*${MY_SUFFIX}*" \
518 # -and -not -name "mysql_config${MY_SUFFIX}" \
519 # > "${filelist}"
520 # echo "${MY_SYSCONFDIR#"/"}" >> "${filelist}"
521 # echo "${MY_LIBDIR#"/"}" >> "${filelist}"
522 # echo "${MY_SHAREDSTATEDIR#"/"}" >> "${filelist}"
523 #popd &>/dev/null
524
525 enewgroup mysql 60 || die "problem adding group mysql"
526 enewuser mysql 60 -1 /dev/null mysql \
527 || die "problem adding user mysql"
528}
529
530mysql_pkg_postinst() {
531
532 mysql_init_vars
533 mysql_lib_symlinks
534
535 # mind at FEATURES=collision-protect before to remove this
536 [ -d "${ROOT}/var/log/mysql" ] \
537 || install -d -m0750 -o mysql -g mysql "${ROOT}${MY_LOGDIR}"
538
539 #secure the logfiles... does this bother anybody?
540 touch "${ROOT}${MY_LOGDIR}"/mysql.{log,err}
541 chown mysql:mysql "${ROOT}${MY_LOGDIR}"/mysql*
542 chmod 0660 "${ROOT}${MY_LOGDIR}"/mysql*
543
544 ## list of files, to be used
545 ## by external utilities
546 #mkdir -p "${ROOT}/var/lib/eselect/mysql/"
547 #cp "${TMPDIR}/FILELIST" "${ROOT}/var/lib/eselect/mysql/mysql${MY_SUFFIX}.filelist"
467 548
468 if ! useq minimal; then 549 if ! useq minimal; then
469 if [[ ${SLOT} -gt 0 ]] ; then 550 if [[ ${SLOT} -gt 0 ]] ; then
470 if [[ -f "${ROOT}/usr/sbin/mysqld" ]] ; then 551 #if [[ -f "${ROOT}/usr/sbin/mysqld" ]] ; then
471 einfo "you may want to run unmerge any unslotted MySQL versions with " 552 einfo "you may want to read:"
472 einfo "emerge -C --pretend dev-db/mysql" 553 einfo "http://www.gentoo.org/doc/en/mysql-upgrade-slotted.xml"
473 einfo "emerge -C =dev-db/mysql-X.Y.Z"
474 einfo "After the unmerge run \"eselect myqsl list\" followed by a "
475 einfo "\"eselect myqsl set 1\" to chose the default mysql server"
476 else 554 #else
477 local tmpres="$( eselect mysql show )" 555 # local tmpres="$( eselect mysql show )"
478 # "like grep -q unset" 556 # # "like grep -q unset"
479 if [[ "{$tmpres}" == "{$tmpres/unset/}" ]] ; then 557 # if [[ "{$tmpres}" == "{$tmpres/unset/}" ]] ; then
480 eselect mysql set 1 558 # eselect mysql set 1
481 else 559 # else
482 einfo "The version of mysql emerged now stils is _NOT_ the default" 560 # einfo "The version of mysql emerged now stils is _NOT_ the default"
483 einfo "you may want to run \"eselect myqsl list\" followed by a " 561 einfo "you may want to run \"eselect myqsl list\" followed by a "
484 einfo "\"eselect myqsl set 1\" to chose the default mysql server" 562 einfo "\"eselect myqsl set 1\" to chose the default mysql server"
485 fi 563 # fi
486 fi 564 #fi
487 fi 565 fi
488 566
489 # your friendly public service announcement... 567 # your friendly public service announcement...
490 einfo 568 einfo
491 einfo "You might want to run:" 569 einfo "You might want to run:"
530 fi 608 fi
531 609
532 local options="" 610 local options=""
533 local sqltmp="$(emktemp)" 611 local sqltmp="$(emktemp)"
534 612
535 local help_tables="${ROOT}/usr/share/doc/mysql-${PVR}/scripts/fill_help_tables.sql.gz" 613 local help_tables="${MY_SHAREDSTATEDIR}/fill_help_tables.sql"
536 [[ -r "${help_tables}" ]] \ 614 [[ -r "${help_tables}" ]] \
537 && zcat "${help_tables}" > "${TMPDIR}/fill_help_tables.sql" \ 615 && cp "${help_tables}" "${TMPDIR}/fill_help_tables.sql" \
538 || touch "${TMPDIR}/fill_help_tables.sql" 616 || touch "${TMPDIR}/fill_help_tables.sql"
539 help_tables="${TMPDIR}/fill_help_tables.sql" 617 help_tables="${TMPDIR}/fill_help_tables.sql"
540 618
541 pushd "${TMPDIR}" &>/dev/null 619 pushd "${TMPDIR}" &>/dev/null
542 ${ROOT}/usr/bin/mysql_install_db${MY_SUFFIX} | grep -B5 -A999 -i "ERROR" 620 ${ROOT}/usr/bin/mysql_install_db${MY_SUFFIX} | grep -B5 -A999 -i "ERROR"
556 if [[ -r "${help_tables}" ]] ; then 634 if [[ -r "${help_tables}" ]] ; then
557 cat "${help_tables}" >> "${sqltmp}" 635 cat "${help_tables}" >> "${sqltmp}"
558 fi 636 fi
559 fi 637 fi
560 638
561 local socket=${ROOT}/var/run/mysqld/mysqld${MY_SUFFIX}${RANDOM}.sock 639 local socket=${ROOT}/var/run/mysqld/mysqld${RANDOM}.sock
562 local pidfile=${ROOT}/var/run/mysqld/mysqld${MY_SUFFIX}${RANDOM}.sock 640 local pidfile=${ROOT}/var/run/mysqld/mysqld${MY_SUFFIX}${RANDOM}.pid
563 local mysqld="${ROOT}/usr/sbin/mysqld${MY_SUFFIX} \ 641 local mysqld="${ROOT}/usr/sbin/mysqld${MY_SUFFIX} \
564 ${options} \ 642 ${options} \
565 --user=mysql \ 643 --user=mysql \
566 --skip-grant-tables \ 644 --skip-grant-tables \
567 --basedir=${ROOT}/usr \ 645 --basedir=${ROOT}/usr \
602 einfo "stopping the server," 680 einfo "stopping the server,"
603 wait %1 681 wait %1
604 einfo "done" 682 einfo "done"
605} 683}
606 684
685mysql_pkg_prerm() {
686 # external program
687 eselect mysql slot_remove "${SLOT}"
688}
689
607mysql_pkg_postrm() { 690mysql_pkg_postrm() {
608 mysql_lib_symlinks 691 mysql_lib_symlinks
609 if [[ ${SLOT} -gt 0 ]] ; then 692 if [[ ${SLOT} -gt 0 ]] ; then
610 einfo "you may want to run \"eselect myqsl list\" followed by a " 693 einfo "you may want to run \"eselect myqsl list\" followed by a "
611 einfo "\"eselect myqsl list\" to chose the default mysql server" 694 einfo "\"eselect myqsl list\" to chose the default mysql server"

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.20