# Copyright 1999-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ inherit eutils gnuconfig gcc flag-o-matic mysql SVER=$(get_version_component_range 1-2) PLV="" version_is_at_least "5.0.0" && PLV="-alpha" BK="no" NEWP="${PN}-${SVER}.$( get_version_component_range 3-3 )" S=${WORKDIR}/${NEWP}${PLV} DESCRIPTION="A fast, multi-threaded, multi-user SQL database server" HOMEPAGE="http://www.mysql.com/" SRC_URI="mirror://mysql/Downloads/MySQL-${SVER}/${NEWP}${PLV}.tar.gz" LICENSE="GPL-2" SLOT="0" KEYWORDS="~x86 ~amd64" IUSE="static readline innodb berkdb tcpd ssl perl ruby selinux debug libwrap raid doc" RESTRICT="nomirror" DEPEND=" readline? ( >=sys-libs/readline-4.1 ) tcpd? ( >=sys-apps/tcp-wrappers-7.6-r6 ) ssl? ( >=dev-libs/openssl-0.9.6d ) perl? ( dev-lang/perl ) >=sys-libs/zlib-1.1.3 || ( sys-apps/procps sys-process/procps ) >=sys-apps/texinfo-4.7 >=sys-apps/sed-4" PDEPEND="perl? ( >=dev-perl/DBD-mysql-2.9004 ) ruby? ( >=dev-ruby/mysql-ruby-2.5 )" RDEPEND="${DEPEND} selinux? ( sec-policy/selinux-mysql )" if version_is_at_least "4.1.3" ; then #dev-db/mysql:geometry - Add spatial extensions #dev-db/mysql:raid - Add support for raid tables #dev-db/mysql:extraengine - Add all the engines that don't have a # specific USE flag IUSE="${IUSE} cluster utf8 geometry extraengine" fi warning() { ewarn "" ewarn "If you're upgrading from MySQL-3.x to 4.0, or 4.0.x to 4.1.x, you" ewarn "must recompile the other packages on your system that link with" ewarn "libmysqlclient after the upgrade completes. To obtain such a list" ewarn "of packages for your system, you may use 'revdep-rebuild' from" ewarn "app-portage/gentoolkit." ewarn "" ewarn "MySQL 4.1 stores table names and column names in UTF8." ewarn "If you have table names or column names that use characters" ewarn "outside of the standard 7-bit US-ASCII range, you may have to" ewarn "do a mysqldump of your tables in MySQL 4.0 and restore them" ewarn "after upgrading to MySQL 4.1." ewarn "" ewarn "After upgrading, update the grant tables to have the new longer" ewarn "Password column. To fix it you need to run:" ewarn "# /etc/init.d/mysql start" ewarn "# mysql_fix_privilege_tables --password=root_password" ewarn "If you don't do this, MySQL will not use the new more secure" ewarn "protocol to authenticate." ewarn "" ewarn "There are also changes in replication and bdb tables, a more" ewarn "in deep explanation is avaiable at MySQL website." ewarn "You may want to upgrade also dev-php/*php." ewarn "" ewarn "You can also choose to preview the new MySQL 4.1 behaviour" ewarn "under 4.0 by adding a row with the word \"new\" in the [mysqld]" ewarn "section of your /etc/mysql/my.cnf (you need a recent MySQL version)" } pkg_setup() { warning epause 10 } src_unpack() { if use static && use ssl; then local msg="MySQL does not support building statically with SSL support" eerror "${msg}" die "${msg}" fi unpack ${A} || die cd ${S} if [[ "${BK}" == "yes" ]]; then patch -p1 --silent --input="${WORKDIR}/${P}.patch" fi # for correct hardcoded sysconf directory epatch "$(find_versioned_file "my-print-defaults")" # NPTL support if have_NPTL ; then epatch "$(find_versioned_file "gentoo-nptl")" fi # attempt to get libmysqlclient_r linked against ssl if USE="ssl" enabled # i would really prefer to fix this at the Makefile.am level, but can't # get the software to autoreconf as distributed - too many missing files if use ssl; then epatch "$(find_versioned_file "thrssl")" fi if use tcpd; then epatch "$(find_versioned_file "tcpd-vars-fix")" fi # Security fix for bug #77805: version_is_at_least "4.1.10_alpha20050201" || \ epatch "$(find_versioned_file "accesstmp")" # http://bugs.mysql.com/bug.php?id=7928 out of connection objects version_is_at_least "4.1.0" \ && ! version_is_at_least "4.1.10_alpha20050201" \ && epatch "$(find_versioned_file "ndb")" # [DIRTY] this stuff need do be rewieved if [[ "${BK}" == "yes" ]] ;then libtoolize --copy --force autoreconf --install --force WANT_AUTOCONF="2.5" WANT_AUTOMAKE="1.8" autoconf gnuconfig_update else autoconf libtoolize --copy --force gnuconfig_update fi } src_compile() { local myconf # The following fix is due to a bug with bdb on sparc's. See: # http://www.geocrawler.com/mail/msg.php3?msg_id=4754814&list=8 if use sparc || use alpha || use hppa || use mips then myconf="${myconf} --without-berkeley-db" else use berkdb \ && myconf="${myconf} --with-berkeley-db=./bdb" \ || myconf="${myconf} --without-berkeley-db" fi # readline pair reads backwards on purpose, DONT change it around, Ok? # this is because it refers to the building of a bundled readline # versus the system copy use readline && myconf="${myconf} --without-readline" use readline || myconf="${myconf} --with-readline" use static \ && myconf="${myconf} --with-mysqld-ldflags=-all-static --disable-shared" \ || myconf="${myconf} --enable-shared --enable-static" myconf="${myconf} `use_with tcpd libwrap`" myconf="${myconf} `use_with innodb`" use ssl \ && myconf="${myconf} --with-vio --with-openssl" \ || myconf="${myconf} --without-openssl" if version_is_at_least "4.1.3" ; then if use geometry; then myconf="${myconf} --with-geometry" else # myconf="${myconf} --without-geometry" ewarn "MySQL can't compile without geometry at the moment, enabling it" fi fi # MySQL cluster UseFlag version_is_at_least "4.1.3" && if use cluster; then myconf="${myconf} --with-ndbcluster" fi if version_is_at_least "4.1.3" && use utf8; then myconf="${myconf} --with-charset=utf8 --with-collation=utf8_general_ci" myconf="${myconf} --with-extra-charsets=complex" else myconf="${myconf} --with-charset=latin1 --with-collation=latin1_swedish_ci" myconf="${myconf} --with-extra-charsets=complex" fi use raid \ && myconf="${myconf} --with-raid" \ || myconf="${myconf} --without-raid" if [[ "`gcc-major-version`" -eq "3" ]] && [[ "`gcc-minor-version`" -eq "4" ]] then export CXXFLAGS="${CXXFLAGS} -fpermissive" fi if ! use doc; then myconf="${myconf} --without-docs" fi if use debug; then myconf="${myconf} --with-debug=full" else myconf="${myconf} --without-debug" version_is_at_least "4.1.3" && use cluster && myconf="${myconf} --without-ndb-debug" fi if version_is_at_least "4.1.3" && use extraengine; then # http://dev.mysql.com/doc/mysql/en/archive-storage-engine.html myconf="${myconf} --with-archive-storage-engine" # http://dev.mysql.com/doc/mysql/en/csv-storage-engine.html version_is_at_least "4.1.4" \ && myconf="${myconf} --with-csv-storage-engine" # http://dev.mysql.com/doc/mysql/en/federated-description.html # http://dev.mysql.com/doc/mysql/en/federated-limitations.html if version_is_at_least "5.1.3" ; then einfo "before to use federated engine be sure to read" einfo "http://dev.mysql.com/doc/mysql/en/federated-limitations.html" myconf="${myconf} --with-federated-storage-engine" fi fi #glibc-2.3.2_pre fix; bug #16496 if has_version "=sys-libs/glibc-2.3*"; then CFLAGS="${CFLAGS} -DHAVE_ERRNO_AS_DEFINE=1" fi # let MySQL choose the optimization level filter-flags -O? export CXXFLAGS="${CXXFLAGS} -felide-constructors -fno-exceptions -fno-rtti" has_m64 && append-flags "-m64" append-flags "-D_GNU_SOURCE" econf \ --libexecdir=/usr/sbin \ --sysconfdir=/etc/mysql \ --localstatedir=/var/lib/mysql \ --with-mysqlmanager=no \ --enable-local-infile \ --with-mysqld-user=mysql \ --enable-thread-safe-client \ --with-client-ldflags=-lstdc++ \ --with-comment="Still Not g.o Linux ${PF}" \ --with-unix-socket-path=/var/run/mysqld/mysqld.sock \ --with-embedded-server \ --with-low-memory \ --without-isam \ --with-zlib-dir=/usr \ --enable-assembler \ --with-lib-ccflags="-fPIC" \ ${myconf} || die "bad ./configure" emake || die "compile problem" } src_test() { local myconf="--local --fast --force" cd "${S}/mysql-test/" # The "mysql-test-run" script cannot skip more than one test # so we need to manually move the offending tests # this one generate sandbox violations # symlink.test generate sandbox access violations # open_wr: /this-dir-does-not-exist/t9.MYI #mv t/symlink.test t/symlink.nasty addpredict "/this-dir-does-not-exist/t9.MYI" # nptl, headers > 2.6.8, glibc-2.3.4.20050125, # x86_64-pc-linux-gnu-3.4.3 # [DIRTY] rpl_openssl script frozen with no hope # does ssl work outside sandbox ? mv t/rpl_openssl.test t/rpl_openssl.nasty # nptl, headers > 2.6.8, glibc-2.3.4.20050125, # x86_64-pc-linux-gnu-3.4.3 # [DIRTY] *ndb* tests fail # dmesg show # factorial[17891]: segfault at 0000000000020f11 rip 0000000000402ef2 rsp 00007fffffffda70 error 4 # ndbd[26967]: segfault at 0000000040000fd8 rip 00002aaaaabc6587 rsp 0000000040000fe0 error 6 version_is_at_least "4.1.3" && use cluster && myconf="${myconf} --with-ndbcluster" use ssl && myconf="${myconf} --with-openssl" use debug && myconf="${myconf} --debug" ./mysql-test-run ${myconf} # [BUG] seems that this *always* return an error #if [[ $? -ne 0 ]]; then # ewarn "test finished: THERE ARE FAILED TESTs" einfo "mysqldump.test is known to fail because of use of missing" einfo " (cp850) charset" # # [DIRTY] force a positive result for the moment (2005-02-20) # # in the future only fully compliant versions should be installed true #else # einfo "test finished:" #fi # to be sure ;) pkill -9 -f ${S}/ndb/src/kernel/ndbd pkill -9 -f ${S}/ndb/src/mgmsrv/ndb_mgmd pkill -9 -f ${S}/ndb/src/mgmclient/ndb_mgm pkill -9 -f ${S}/sql/mysqld } src_install() { make install DESTDIR=${D} benchdir_root="/usr/share/mysql" || die diropts "-m0750" dodir /var/lib/mysql /var/run/mysqld /var/log/mysql touch ${D}/var/lib/mysql/.keep \ ${D}/var/run/mysqld/.keep \ ${D}/var/log/mysql/.keep chown -R mysql:mysql ${D}/var/lib/mysql \ ${D}/var/run/mysqld \ ${D}/var/log/mysql # move client libs, install a couple of missing headers mv ${D}/usr/$(get_libdir)/mysql/libmysqlclient*.so* ${D}/usr/$(get_libdir) dosym ../libmysqlclient.so /usr/$(get_libdir)/mysql/libmysqlclient.so dosym ../libmysqlclient_r.so /usr/$(get_libdir)/mysql/libmysqlclient_r.so insinto /usr/include/mysql ; doins include/{my_config.h,my_dir.h} # convenience links dosym /usr/bin/mysqlcheck /usr/bin/mysqlanalyze dosym /usr/bin/mysqlcheck /usr/bin/mysqlrepair dosym /usr/bin/mysqlcheck /usr/bin/mysqloptimize # various junk rm -f ${D}/usr/share/mysql/mysql.server rm -f ${D}/usr/share/mysql/binary-configure rm -f ${D}/usr/share/mysql/make_binary_distribution rm -f ${D}/usr/share/mysql/mysql-log-rotate rm -f ${D}/usr/share/mysql/{post,pre}install rm -f ${D}/usr/share/mysql/mi_test* rm -f ${D}/usr/share/mysql/*.spec # Redhat junk rm -f ${D}/usr/share/mysql/*.plist # Apple junk rm -f ${D}/usr/share/mysql/my-*.cnf # Put them elsewhere # All of these (ab)use Perl. if ! use perl; then rm -f ${D}/usr/bin/mysql_setpermission fi if ! use perl || ! use doc; then rm -rf ${D}/usr/share/mysql/sql-bench fi dodoc COPYING COPYING.LIB if use doc; then dohtml Docs/*.html rm -f Docs/*.html dodoc README COPYING COPYING.LIB Docs/manual.* docinto conf-samples docinto conf-samples dodoc support-files/my-*.cnf fi insinto /etc/mysql newins "$(find_versioned_file "my.cnf")" my.cnf if version_is_at_least "4.1.3" && ! use utf8; then sed --in-place "s/utf8/latin1/" \ ${D}/etc/mysql/my.cnf fi if use innodb; then sed --in-place \ "s/^skip-innodb/#skip-innodb/" \ "s/^#innodb_/innodb_/" \ ${D}/etc/mysql/my.cnf fi if use berkdb; then sed --in-place \ "s/^#bdb_/bdb_/" \ ${D}/etc/mysql/my.cnf fi doins scripts/mysqlaccess.conf exeinto /etc/init.d newexe "$(find_versioned_file "rc6")" mysql insinto /etc/logrotate.d newins "$(find_versioned_file "logrotate")" mysql } pkg_config() { local DATADIR="" local timestamp="" local pwd1="a" local pwd2="b" local options="" local help_tables="" if [[ -f '/etc/mysql/my.cnf' ]] ; then DATADIR=`${ROOT}/usr/bin/my_print_defaults mysqld \ | sed -ne '/datadir/s|^--datadir=||p' | tail -n1` fi if [[ -z "${DATADIR}" ]]; then DATADIR="${ROOT}/var/lib/mysql/" einfo "Using default DATADIR" fi einfo "MySQL DATADIR is ${DATADIR}" if [[ -d "${DATADIR}/mysql" ]] ; then timestamp=$(/usr/bin/date +"%Y%m%d%H%M") ewarn "You have already a mysql database in place." ewarn "Press enter to RENAME it to \"my${timestamp}\"" ewarn "Press \"Contrl-C\" to abort now..." read mv "${DATADIR}/mysql" "${DATADIR}/my${timestamp}" fi einfo "Creating the mysql database and setting proper" einfo "permissions on it..." mkdir -p "${ROOT}/var/lib/mysql/mysql/../test" # MySQL 5.0 don't ned this chown -R mysql:mysql ${DATADIR} einfo "Insert a password for the mysql 'root' user" ewarn "the password will be visible on the screen" echo -n " >" && read -r pwd1 einfo "Check the password" echo -n " >" && read -r pwd2 if (( pwd1 != pwd2 )) ; then ewarn "Passwords are not the same" die fi sed -e "s/@HOST@/$(get_hostname)/" \ -e "s/@PWD@/${pwd1}/" \ "$(find_versioned_file "sql-create-db")" \ > "${T}/create-db.sql" #/usr/bin/mysql_create_system_tables real /var/lib/mysql/mysql \ # $(hostname) 0 | \ # sed -e "s|NO_AUTO_VALUE_ON_ZERO'\s*) DEFAULT 0 NOT # NULL,\s*comment|NO_AUTO_VALUE_ON_ZERO' ) DEFAULT '' # NOT NULL, comment|" | \ if version_is_at_least "4.1.3" ; then options="--skip-ndbcluster" help_tables="${ROOT}/usr/share/mysql/fill_help_tables.sql" fi cat "${T}/create-db.sql" ${help_tables} \ | "${ROOT}/usr/sbin/mysqld" \ --bootstrap \ --skip-grant-tables \ --basedir=/usr \ --datadir=/var/lib/mysql \ --skip-innodb \ --skip-bdb \ ${options} \ --max_allowed_packet=8M \ --net_buffer_length=16K # changing ownership of newly created databases to mysql.mysql chown -R mysql:mysql ${DATADIR} chmod 0750 ${DATADIR} } pkg_preinst() { enewgroup mysql 60 || die "problem adding group mysql" enewuser mysql 60 /dev/null /var/lib/mysql mysql \ || die "problem adding user mysql" } pkg_postinst() { # secure the logfiles... does this bother anybody? touch ${ROOT}/var/log/mysql/mysql.{log,err} chown mysql:mysql ${ROOT}/var/log/mysql/mysql* chmod 0660 ${ROOT}/var/log/mysql/mysql* # secure some directories chmod 0750 ${ROOT}/var/log/mysql ${ROOT}/var/lib/mysql # your friendly public service announcement... einfo einfo "You might want to run:" einfo "\"ebuild /var/db/pkg/dev-db/${PF}/${PF}.ebuild config\"" einfo "if this is a new install." einfo warning }