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

Diff of /eclass/mysql.eclass

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

Revision 1.137 Revision 1.142
1# Copyright 1999-2009 Gentoo Foundation 1# Copyright 1999-2009 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.137 2010/03/15 18:50:43 robbat2 Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/mysql.eclass,v 1.142 2010/03/24 20:37:54 robbat2 Exp $
4 4
5# @ECLASS: mysql.eclass 5# @ECLASS: mysql.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Author: Francesco Riosa (Retired) <vivo@gentoo.org> 7# Author: Francesco Riosa (Retired) <vivo@gentoo.org>
8# Maintainers: MySQL Team <mysql-bugs@gentoo.org> 8# Maintainers: MySQL Team <mysql-bugs@gentoo.org>
177DESCRIPTION="A fast, multi-threaded, multi-user SQL database server." 177DESCRIPTION="A fast, multi-threaded, multi-user SQL database server."
178HOMEPAGE="http://www.mysql.com/" 178HOMEPAGE="http://www.mysql.com/"
179if [[ "${PN}" == "mariadb" ]]; then 179if [[ "${PN}" == "mariadb" ]]; then
180 HOMEPAGE="http://askmonty.org/" 180 HOMEPAGE="http://askmonty.org/"
181 DESCRIPTION="MariaDB is a MySQL fork with 3rd-party patches and additional storage engines merged." 181 DESCRIPTION="MariaDB is a MySQL fork with 3rd-party patches and additional storage engines merged."
182fi
183if [[ "${PN}" == "mysql-community" ]]; then
184 DESCRIPTION="${DESCRIPTION} (obsolete, move to dev-db/mysql)"
182fi 185fi
183LICENSE="GPL-2" 186LICENSE="GPL-2"
184SLOT="0" 187SLOT="0"
185IUSE="big-tables debug embedded minimal ${IUSE_DEFAULT_ON}perl selinux ssl static test" 188IUSE="big-tables debug embedded minimal ${IUSE_DEFAULT_ON}perl selinux ssl static test"
186 189
533 fi 536 fi
534 fi 537 fi
535 538
536 # 5.1 introduces a new way to manage storage engines (plugins) 539 # 5.1 introduces a new way to manage storage engines (plugins)
537 # like configuration=none 540 # like configuration=none
541 # This base set are required, and will always be statically built.
538 local plugins="csv,myisam,myisammrg,heap" 542 local plugins="csv,myisam,myisammrg,heap"
539 if use extraengine ; then 543 if use extraengine ; then
540 # like configuration=max-no-ndb, archive and example removed in 5.1.11 544 # like configuration=max-no-ndb, archive and example removed in 5.1.11
541 # not added yet: ibmdb2i 545 # not added yet: ibmdb2i
542 # Not supporting as examples: example,daemon_example,ftexample 546 # Not supporting as examples: example,daemon_example,ftexample
589 593
590 einfo "Reconfiguring dir '${PWD}'" 594 einfo "Reconfiguring dir '${PWD}'"
591 AT_GNUCONF_UPDATE="yes" eautoreconf 595 AT_GNUCONF_UPDATE="yes" eautoreconf
592 596
593 local myconf="" 597 local myconf=""
594 myconf="${myconf} --with-mysql=${S} --libdir=${MY_LIBDIR}" 598 myconf="${myconf} --with-mysql=${S} --libdir=/usr/$(get_libdir)"
595 use debug && myconf="${myconf} --with-debug=full" 599 use debug && myconf="${myconf} --with-debug=full"
596 # TODO: is it safe/needed to use econf here ?
597 ./configure ${myconf} || die "Problem configuring PBXT storage engine" 600 econf ${myconf} || die "Problem configuring PBXT storage engine"
598} 601}
599 602
600pbxt_src_compile() { 603pbxt_src_compile() {
601 # Be backwards compatible for now 604 # Be backwards compatible for now
602 if [[ $EAPI != 2 ]]; then 605 if [[ $EAPI != 2 ]]; then
923 if use !test ; then 926 if use !test ; then
924 rm -rf "${D}"/${MY_SHAREDSTATEDIR}/mysql-test 927 rm -rf "${D}"/${MY_SHAREDSTATEDIR}/mysql-test
925 fi 928 fi
926 929
927 # Configuration stuff 930 # Configuration stuff
931 if mysql_version_is_at_least "5.1" ; then
932 mysql_mycnf_version="5.1"
928 if mysql_version_is_at_least "4.1" ; then 933 elif mysql_version_is_at_least "4.1" ; then
929 mysql_mycnf_version="4.1" 934 mysql_mycnf_version="4.1"
930 else 935 else
931 mysql_mycnf_version="4.0" 936 mysql_mycnf_version="4.0"
932 fi 937 fi
933 einfo "Building default my.cnf" 938 einfo "Building default my.cnf"
935 doins scripts/mysqlaccess.conf 940 doins scripts/mysqlaccess.conf
936 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \ 941 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
937 "${FILESDIR}/my.cnf-${mysql_mycnf_version}" \ 942 "${FILESDIR}/my.cnf-${mysql_mycnf_version}" \
938 > "${TMPDIR}/my.cnf.ok" 943 > "${TMPDIR}/my.cnf.ok"
939 if mysql_version_is_at_least "4.1" && use latin1 ; then 944 if mysql_version_is_at_least "4.1" && use latin1 ; then
940 sed -e "s|utf8|latin1|g" -i "${TMPDIR}/my.cnf.ok" 945 sed -i \
946 -e "/character-set/s|utf8|latin1|g" \
947 "${TMPDIR}/my.cnf.ok"
941 fi 948 fi
942 newins "${TMPDIR}/my.cnf.ok" my.cnf 949 newins "${TMPDIR}/my.cnf.ok" my.cnf
943 950
944 # Minimal builds don't have the MySQL server 951 # Minimal builds don't have the MySQL server
945 if ! use minimal ; then 952 if ! use minimal ; then
1100 fi 1107 fi
1101 fi 1108 fi
1102 1109
1103 local pwd1="a" 1110 local pwd1="a"
1104 local pwd2="b" 1111 local pwd2="b"
1112 local MYSQL_ROOT_PASSWORD=''
1105 local maxtry=5 1113 local maxtry=15
1114
1115 if [ -z "${MYSQL_ROOT_PASSWORD}" -a -f "${ROOT}/root/.my.cnf" ]; then
1116 MYSQL_ROOT_PASSWORD="$(sed -n -e '/^password=/s,^password=,,gp' "${ROOT}/root/.my.cnf")"
1117 fi
1106 1118
1107 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then 1119 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
1108 ewarn "You have already a MySQL database in place." 1120 ewarn "You have already a MySQL database in place."
1109 ewarn "(${ROOT}/${MY_DATADIR}/*)" 1121 ewarn "(${ROOT}/${MY_DATADIR}/*)"
1110 ewarn "Please rename or delete it if you wish to replace it." 1122 ewarn "Please rename or delete it if you wish to replace it."
1113 1125
1114 # Bug #213475 - MySQL _will_ object strenously if your machine is named 1126 # Bug #213475 - MySQL _will_ object strenously if your machine is named
1115 # localhost. Also causes weird failures. 1127 # localhost. Also causes weird failures.
1116 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost" 1128 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
1117 1129
1118 einfo "Creating the mysql database and setting proper" 1130 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
1119 einfo "permissions on it ..."
1120 1131
1121 einfo "Insert a password for the mysql 'root' user" 1132 einfo "Please provide a password for the mysql 'root' user now,"
1133 einfo "or in the MYSQL_ROOT_PASSWORD env var."
1122 ewarn "Avoid [\"'\\_%] characters in the password" 1134 ewarn "Avoid [\"'\\_%] characters in the password"
1123 read -rsp " >" pwd1 ; echo 1135 read -rsp " >" pwd1 ; echo
1124 1136
1125 einfo "Retype the password" 1137 einfo "Retype the password"
1126 read -rsp " >" pwd2 ; echo 1138 read -rsp " >" pwd2 ; echo
1127 1139
1128 if [[ "x$pwd1" != "x$pwd2" ]] ; then 1140 if [[ "x$pwd1" != "x$pwd2" ]] ; then
1129 die "Passwords are not the same" 1141 die "Passwords are not the same"
1142 fi
1143 MYSQL_ROOT_PASSWORD="${pwd1}"
1144 unset pwd1 pwd2
1130 fi 1145 fi
1131 1146
1132 local options="" 1147 local options=""
1133 local sqltmp="$(emktemp)" 1148 local sqltmp="$(emktemp)"
1134 1149
1148 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \ 1163 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
1149 || die "MySQL databases not installed" 1164 || die "MySQL databases not installed"
1150 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null 1165 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
1151 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null 1166 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
1152 1167
1168 # Figure out which options we need to disable to do the setup
1169 helpfile="${TMPDIR}/mysqld-help"
1170 ${ROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
1171 for opt in grant-tables host-cache name-resolve networking slave-start bdb \
1172 federated innodb ssl log-bin relay-log slow-query-log external-locking \
1173 ; do
1174 optexp="--(skip-)?${opt}" optfull="--skip-${opt}"
1175 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
1176 done
1177 # But some options changed names
1178 egrep -sq external-locking "${helpfile}" && \
1179 options="${options/skip-locking/skip-external-locking}"
1180
1153 if mysql_version_is_at_least "4.1.3" ; then 1181 if mysql_version_is_at_least "4.1.3" ; then
1154 options="--skip-ndbcluster"
1155
1156 # Filling timezones, see 1182 # Filling timezones, see
1157 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html 1183 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
1158 "${ROOT}/usr/bin/mysql_tzinfo_to_sql" "${ROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null 1184 "${ROOT}/usr/bin/mysql_tzinfo_to_sql" "${ROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
1159 1185
1160 if [[ -r "${help_tables}" ]] ; then 1186 if [[ -r "${help_tables}" ]] ; then
1161 cat "${help_tables}" >> "${sqltmp}" 1187 cat "${help_tables}" >> "${sqltmp}"
1162 fi 1188 fi
1163 fi 1189 fi
1190
1191 einfo "Creating the mysql database and setting proper"
1192 einfo "permissions on it ..."
1164 1193
1165 local socket="${ROOT}/var/run/mysqld/mysqld${RANDOM}.sock" 1194 local socket="${ROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
1166 local pidfile="${ROOT}/var/run/mysqld/mysqld${RANDOM}.pid" 1195 local pidfile="${ROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
1167 local mysqld="${ROOT}/usr/sbin/mysqld \ 1196 local mysqld="${ROOT}/usr/sbin/mysqld \
1168 ${options} \ 1197 ${options} \
1169 --user=mysql \ 1198 --user=mysql \
1170 --skip-grant-tables \
1171 --basedir=${ROOT}/usr \ 1199 --basedir=${ROOT}/usr \
1172 --datadir=${ROOT}/${MY_DATADIR} \ 1200 --datadir=${ROOT}/${MY_DATADIR} \
1173 --skip-innodb \
1174 --skip-bdb \
1175 --skip-networking \
1176 --max_allowed_packet=8M \ 1201 --max_allowed_packet=8M \
1177 --net_buffer_length=16K \ 1202 --net_buffer_length=16K \
1178 --socket=${socket} \ 1203 --socket=${socket} \
1179 --pid-file=${pidfile}" 1204 --pid-file=${pidfile}"
1205 #einfo "About to start mysqld: ${mysqld}"
1206 ebegin "Starting mysqld"
1180 ${mysqld} & 1207 ${mysqld} &
1208 rc=$?
1181 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do 1209 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
1182 maxtry=$((${maxtry}-1)) 1210 maxtry=$((${maxtry}-1))
1183 echo -n "." 1211 echo -n "."
1184 sleep 1 1212 sleep 1
1185 done 1213 done
1214 eend $rc
1186 1215
1216 if ! [[ -S "${socket}" ]]; then
1217 die "Completely failed to start up mysqld with: ${mysqld}"
1218 fi
1219
1220 ebegin "Setting root password"
1187 # Do this from memory, as we don't want clear text passwords in temp files 1221 # Do this from memory, as we don't want clear text passwords in temp files
1188 local sql="UPDATE mysql.user SET Password = PASSWORD('${pwd1}') WHERE USER='root'" 1222 local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'"
1189 "${ROOT}/usr/bin/mysql" \ 1223 "${ROOT}/usr/bin/mysql" \
1190 --socket=${socket} \ 1224 --socket=${socket} \
1191 -hlocalhost \ 1225 -hlocalhost \
1192 -e "${sql}" 1226 -e "${sql}"
1227 eend $?
1193 1228
1194 einfo "Loading \"zoneinfo\", this step may require a few seconds ..." 1229 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..."
1195
1196 "${ROOT}/usr/bin/mysql" \ 1230 "${ROOT}/usr/bin/mysql" \
1197 --socket=${socket} \ 1231 --socket=${socket} \
1198 -hlocalhost \ 1232 -hlocalhost \
1199 -uroot \ 1233 -uroot \
1200 -p"${pwd1}" \ 1234 -p"${MYSQL_ROOT_PASSWORD}" \
1201 mysql < "${sqltmp}" 1235 mysql < "${sqltmp}"
1236 rc=$?
1237 eend $?
1238 [ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!"
1202 1239
1203 # Stop the server and cleanup 1240 # Stop the server and cleanup
1241 einfo "Stopping the server ..."
1204 kill $(< "${pidfile}" ) 1242 kill $(< "${pidfile}" )
1205 rm -f "${sqltmp}" 1243 rm -f "${sqltmp}"
1206 einfo "Stopping the server ..."
1207 wait %1 1244 wait %1
1208 einfo "Done" 1245 einfo "Done"
1209} 1246}
1210 1247
1211# @FUNCTION: mysql_pkg_postrm 1248# @FUNCTION: mysql_pkg_postrm

Legend:
Removed from v.1.137  
changed lines
  Added in v.1.142

  ViewVC Help
Powered by ViewVC 1.1.20