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

Diff of /eclass/mysql.eclass

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

Revision 1.138 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.138 2010/03/15 19:05:51 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
922 if use !test ; then 926 if use !test ; then
923 rm -rf "${D}"/${MY_SHAREDSTATEDIR}/mysql-test 927 rm -rf "${D}"/${MY_SHAREDSTATEDIR}/mysql-test
924 fi 928 fi
925 929
926 # Configuration stuff 930 # Configuration stuff
931 if mysql_version_is_at_least "5.1" ; then
932 mysql_mycnf_version="5.1"
927 if mysql_version_is_at_least "4.1" ; then 933 elif mysql_version_is_at_least "4.1" ; then
928 mysql_mycnf_version="4.1" 934 mysql_mycnf_version="4.1"
929 else 935 else
930 mysql_mycnf_version="4.0" 936 mysql_mycnf_version="4.0"
931 fi 937 fi
932 einfo "Building default my.cnf" 938 einfo "Building default my.cnf"
934 doins scripts/mysqlaccess.conf 940 doins scripts/mysqlaccess.conf
935 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \ 941 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
936 "${FILESDIR}/my.cnf-${mysql_mycnf_version}" \ 942 "${FILESDIR}/my.cnf-${mysql_mycnf_version}" \
937 > "${TMPDIR}/my.cnf.ok" 943 > "${TMPDIR}/my.cnf.ok"
938 if mysql_version_is_at_least "4.1" && use latin1 ; then 944 if mysql_version_is_at_least "4.1" && use latin1 ; then
939 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"
940 fi 948 fi
941 newins "${TMPDIR}/my.cnf.ok" my.cnf 949 newins "${TMPDIR}/my.cnf.ok" my.cnf
942 950
943 # Minimal builds don't have the MySQL server 951 # Minimal builds don't have the MySQL server
944 if ! use minimal ; then 952 if ! use minimal ; then
1099 fi 1107 fi
1100 fi 1108 fi
1101 1109
1102 local pwd1="a" 1110 local pwd1="a"
1103 local pwd2="b" 1111 local pwd2="b"
1112 local MYSQL_ROOT_PASSWORD=''
1104 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
1105 1118
1106 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then 1119 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
1107 ewarn "You have already a MySQL database in place." 1120 ewarn "You have already a MySQL database in place."
1108 ewarn "(${ROOT}/${MY_DATADIR}/*)" 1121 ewarn "(${ROOT}/${MY_DATADIR}/*)"
1109 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."
1112 1125
1113 # Bug #213475 - MySQL _will_ object strenously if your machine is named 1126 # Bug #213475 - MySQL _will_ object strenously if your machine is named
1114 # localhost. Also causes weird failures. 1127 # localhost. Also causes weird failures.
1115 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost" 1128 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
1116 1129
1117 einfo "Creating the mysql database and setting proper" 1130 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
1118 einfo "permissions on it ..."
1119 1131
1120 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."
1121 ewarn "Avoid [\"'\\_%] characters in the password" 1134 ewarn "Avoid [\"'\\_%] characters in the password"
1122 read -rsp " >" pwd1 ; echo 1135 read -rsp " >" pwd1 ; echo
1123 1136
1124 einfo "Retype the password" 1137 einfo "Retype the password"
1125 read -rsp " >" pwd2 ; echo 1138 read -rsp " >" pwd2 ; echo
1126 1139
1127 if [[ "x$pwd1" != "x$pwd2" ]] ; then 1140 if [[ "x$pwd1" != "x$pwd2" ]] ; then
1128 die "Passwords are not the same" 1141 die "Passwords are not the same"
1142 fi
1143 MYSQL_ROOT_PASSWORD="${pwd1}"
1144 unset pwd1 pwd2
1129 fi 1145 fi
1130 1146
1131 local options="" 1147 local options=""
1132 local sqltmp="$(emktemp)" 1148 local sqltmp="$(emktemp)"
1133 1149
1147 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \ 1163 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
1148 || die "MySQL databases not installed" 1164 || die "MySQL databases not installed"
1149 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null 1165 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
1150 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null 1166 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
1151 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
1152 if mysql_version_is_at_least "4.1.3" ; then 1181 if mysql_version_is_at_least "4.1.3" ; then
1153 options="--skip-ndbcluster"
1154
1155 # Filling timezones, see 1182 # Filling timezones, see
1156 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html 1183 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html
1157 "${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
1158 1185
1159 if [[ -r "${help_tables}" ]] ; then 1186 if [[ -r "${help_tables}" ]] ; then
1160 cat "${help_tables}" >> "${sqltmp}" 1187 cat "${help_tables}" >> "${sqltmp}"
1161 fi 1188 fi
1162 fi 1189 fi
1190
1191 einfo "Creating the mysql database and setting proper"
1192 einfo "permissions on it ..."
1163 1193
1164 local socket="${ROOT}/var/run/mysqld/mysqld${RANDOM}.sock" 1194 local socket="${ROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
1165 local pidfile="${ROOT}/var/run/mysqld/mysqld${RANDOM}.pid" 1195 local pidfile="${ROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
1166 local mysqld="${ROOT}/usr/sbin/mysqld \ 1196 local mysqld="${ROOT}/usr/sbin/mysqld \
1167 ${options} \ 1197 ${options} \
1168 --user=mysql \ 1198 --user=mysql \
1169 --skip-grant-tables \
1170 --basedir=${ROOT}/usr \ 1199 --basedir=${ROOT}/usr \
1171 --datadir=${ROOT}/${MY_DATADIR} \ 1200 --datadir=${ROOT}/${MY_DATADIR} \
1172 --skip-innodb \
1173 --skip-bdb \
1174 --skip-networking \
1175 --max_allowed_packet=8M \ 1201 --max_allowed_packet=8M \
1176 --net_buffer_length=16K \ 1202 --net_buffer_length=16K \
1177 --socket=${socket} \ 1203 --socket=${socket} \
1178 --pid-file=${pidfile}" 1204 --pid-file=${pidfile}"
1205 #einfo "About to start mysqld: ${mysqld}"
1206 ebegin "Starting mysqld"
1179 ${mysqld} & 1207 ${mysqld} &
1208 rc=$?
1180 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do 1209 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
1181 maxtry=$((${maxtry}-1)) 1210 maxtry=$((${maxtry}-1))
1182 echo -n "." 1211 echo -n "."
1183 sleep 1 1212 sleep 1
1184 done 1213 done
1214 eend $rc
1185 1215
1216 if ! [[ -S "${socket}" ]]; then
1217 die "Completely failed to start up mysqld with: ${mysqld}"
1218 fi
1219
1220 ebegin "Setting root password"
1186 # 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
1187 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'"
1188 "${ROOT}/usr/bin/mysql" \ 1223 "${ROOT}/usr/bin/mysql" \
1189 --socket=${socket} \ 1224 --socket=${socket} \
1190 -hlocalhost \ 1225 -hlocalhost \
1191 -e "${sql}" 1226 -e "${sql}"
1227 eend $?
1192 1228
1193 einfo "Loading \"zoneinfo\", this step may require a few seconds ..." 1229 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..."
1194
1195 "${ROOT}/usr/bin/mysql" \ 1230 "${ROOT}/usr/bin/mysql" \
1196 --socket=${socket} \ 1231 --socket=${socket} \
1197 -hlocalhost \ 1232 -hlocalhost \
1198 -uroot \ 1233 -uroot \
1199 -p"${pwd1}" \ 1234 -p"${MYSQL_ROOT_PASSWORD}" \
1200 mysql < "${sqltmp}" 1235 mysql < "${sqltmp}"
1236 rc=$?
1237 eend $?
1238 [ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!"
1201 1239
1202 # Stop the server and cleanup 1240 # Stop the server and cleanup
1241 einfo "Stopping the server ..."
1203 kill $(< "${pidfile}" ) 1242 kill $(< "${pidfile}" )
1204 rm -f "${sqltmp}" 1243 rm -f "${sqltmp}"
1205 einfo "Stopping the server ..."
1206 wait %1 1244 wait %1
1207 einfo "Done" 1245 einfo "Done"
1208} 1246}
1209 1247
1210# @FUNCTION: mysql_pkg_postrm 1248# @FUNCTION: mysql_pkg_postrm

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

  ViewVC Help
Powered by ViewVC 1.1.20