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

Diff of /eclass/mysql.eclass

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

Revision 1.139 Revision 1.140
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.139 2010/03/15 19:27:04 robbat2 Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/mysql.eclass,v 1.140 2010/03/24 03:09:08 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>
923 if use !test ; then 923 if use !test ; then
924 rm -rf "${D}"/${MY_SHAREDSTATEDIR}/mysql-test 924 rm -rf "${D}"/${MY_SHAREDSTATEDIR}/mysql-test
925 fi 925 fi
926 926
927 # Configuration stuff 927 # Configuration stuff
928 if mysql_version_is_at_least "5.1" ; then
929 mysql_mycnf_version="5.1"
928 if mysql_version_is_at_least "4.1" ; then 930 elif mysql_version_is_at_least "4.1" ; then
929 mysql_mycnf_version="4.1" 931 mysql_mycnf_version="4.1"
930 else 932 else
931 mysql_mycnf_version="4.0" 933 mysql_mycnf_version="4.0"
932 fi 934 fi
933 einfo "Building default my.cnf" 935 einfo "Building default my.cnf"
935 doins scripts/mysqlaccess.conf 937 doins scripts/mysqlaccess.conf
936 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \ 938 sed -e "s!@DATADIR@!${MY_DATADIR}!g" \
937 "${FILESDIR}/my.cnf-${mysql_mycnf_version}" \ 939 "${FILESDIR}/my.cnf-${mysql_mycnf_version}" \
938 > "${TMPDIR}/my.cnf.ok" 940 > "${TMPDIR}/my.cnf.ok"
939 if mysql_version_is_at_least "4.1" && use latin1 ; then 941 if mysql_version_is_at_least "4.1" && use latin1 ; then
940 sed -e "s|utf8|latin1|g" -i "${TMPDIR}/my.cnf.ok" 942 sed -i \
943 -e "/character-set/s|utf8|latin1|g" \
944 "${TMPDIR}/my.cnf.ok"
941 fi 945 fi
942 newins "${TMPDIR}/my.cnf.ok" my.cnf 946 newins "${TMPDIR}/my.cnf.ok" my.cnf
943 947
944 # Minimal builds don't have the MySQL server 948 # Minimal builds don't have the MySQL server
945 if ! use minimal ; then 949 if ! use minimal ; then
1100 fi 1104 fi
1101 fi 1105 fi
1102 1106
1103 local pwd1="a" 1107 local pwd1="a"
1104 local pwd2="b" 1108 local pwd2="b"
1109 local MYSQL_ROOT_PASSWORD=''
1105 local maxtry=5 1110 local maxtry=15
1106 1111
1107 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then 1112 if [[ -d "${ROOT}/${MY_DATADIR}/mysql" ]] ; then
1108 ewarn "You have already a MySQL database in place." 1113 ewarn "You have already a MySQL database in place."
1109 ewarn "(${ROOT}/${MY_DATADIR}/*)" 1114 ewarn "(${ROOT}/${MY_DATADIR}/*)"
1110 ewarn "Please rename or delete it if you wish to replace it." 1115 ewarn "Please rename or delete it if you wish to replace it."
1113 1118
1114 # Bug #213475 - MySQL _will_ object strenously if your machine is named 1119 # Bug #213475 - MySQL _will_ object strenously if your machine is named
1115 # localhost. Also causes weird failures. 1120 # localhost. Also causes weird failures.
1116 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost" 1121 [[ "${HOSTNAME}" == "localhost" ]] && die "Your machine must NOT be named localhost"
1117 1122
1118 einfo "Creating the mysql database and setting proper" 1123 if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
1119 einfo "permissions on it ..."
1120 1124
1121 einfo "Insert a password for the mysql 'root' user" 1125 einfo "Please provide a password for the mysql 'root' user now,"
1126 einfo "or in the MYSQL_ROOT_PASSWORD env var."
1122 ewarn "Avoid [\"'\\_%] characters in the password" 1127 ewarn "Avoid [\"'\\_%] characters in the password"
1123 read -rsp " >" pwd1 ; echo 1128 read -rsp " >" pwd1 ; echo
1124 1129
1125 einfo "Retype the password" 1130 einfo "Retype the password"
1126 read -rsp " >" pwd2 ; echo 1131 read -rsp " >" pwd2 ; echo
1127 1132
1128 if [[ "x$pwd1" != "x$pwd2" ]] ; then 1133 if [[ "x$pwd1" != "x$pwd2" ]] ; then
1129 die "Passwords are not the same" 1134 die "Passwords are not the same"
1135 fi
1136 MYSQL_ROOT_PASSWORD="${pwd1}"
1137 unset pwd1 pwd2
1130 fi 1138 fi
1131 1139
1132 local options="" 1140 local options=""
1133 local sqltmp="$(emktemp)" 1141 local sqltmp="$(emktemp)"
1134 1142
1148 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \ 1156 [[ -f "${ROOT}/${MY_DATADIR}/mysql/user.frm" ]] \
1149 || die "MySQL databases not installed" 1157 || die "MySQL databases not installed"
1150 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null 1158 chown -R mysql:mysql "${ROOT}/${MY_DATADIR}" 2>/dev/null
1151 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null 1159 chmod 0750 "${ROOT}/${MY_DATADIR}" 2>/dev/null
1152 1160
1161 # Figure out which options we need to disable to do the setup
1162 helpfile="${TMPDIR}/mysqld-help"
1163 ${ROOT}/usr/sbin/mysqld --verbose --help >"${helpfile}" 2>/dev/null
1164 for opt in grant-tables host-cache name-resolve networking slave-start bdb \
1165 federated innodb ssl log-bin relay-log slow-query-log external-locking \
1166 ; do
1167 optexp="--(skip-)?${opt}" optfull="--skip-${opt}"
1168 egrep -sq -- "${optexp}" "${helpfile}" && options="${options} ${optfull}"
1169 done
1170 # But some options changed names
1171 egrep -sq external-locking "${helpfile}" && \
1172 options="${options/skip-locking/skip-external-locking}"
1173
1153 if mysql_version_is_at_least "4.1.3" ; then 1174 if mysql_version_is_at_least "4.1.3" ; then
1154 options="--skip-ndbcluster"
1155
1156 # Filling timezones, see 1175 # Filling timezones, see
1157 # http://dev.mysql.com/doc/mysql/en/time-zone-support.html 1176 # 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 1177 "${ROOT}/usr/bin/mysql_tzinfo_to_sql" "${ROOT}/usr/share/zoneinfo" > "${sqltmp}" 2>/dev/null
1159 1178
1160 if [[ -r "${help_tables}" ]] ; then 1179 if [[ -r "${help_tables}" ]] ; then
1161 cat "${help_tables}" >> "${sqltmp}" 1180 cat "${help_tables}" >> "${sqltmp}"
1162 fi 1181 fi
1163 fi 1182 fi
1183
1184 einfo "Creating the mysql database and setting proper"
1185 einfo "permissions on it ..."
1164 1186
1165 local socket="${ROOT}/var/run/mysqld/mysqld${RANDOM}.sock" 1187 local socket="${ROOT}/var/run/mysqld/mysqld${RANDOM}.sock"
1166 local pidfile="${ROOT}/var/run/mysqld/mysqld${RANDOM}.pid" 1188 local pidfile="${ROOT}/var/run/mysqld/mysqld${RANDOM}.pid"
1167 local mysqld="${ROOT}/usr/sbin/mysqld \ 1189 local mysqld="${ROOT}/usr/sbin/mysqld \
1168 ${options} \ 1190 ${options} \
1169 --user=mysql \ 1191 --user=mysql \
1170 --skip-grant-tables \
1171 --basedir=${ROOT}/usr \ 1192 --basedir=${ROOT}/usr \
1172 --datadir=${ROOT}/${MY_DATADIR} \ 1193 --datadir=${ROOT}/${MY_DATADIR} \
1173 --skip-innodb \
1174 --skip-bdb \
1175 --skip-networking \
1176 --max_allowed_packet=8M \ 1194 --max_allowed_packet=8M \
1177 --net_buffer_length=16K \ 1195 --net_buffer_length=16K \
1178 --socket=${socket} \ 1196 --socket=${socket} \
1179 --pid-file=${pidfile}" 1197 --pid-file=${pidfile}"
1198 #einfo "About to start mysqld: ${mysqld}"
1199 ebegin "Starting mysqld"
1180 ${mysqld} & 1200 ${mysqld} &
1201 rc=$?
1181 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do 1202 while ! [[ -S "${socket}" || "${maxtry}" -lt 1 ]] ; do
1182 maxtry=$((${maxtry}-1)) 1203 maxtry=$((${maxtry}-1))
1183 echo -n "." 1204 echo -n "."
1184 sleep 1 1205 sleep 1
1185 done 1206 done
1207 eend $rc
1186 1208
1209 if ! [[ -S "${socket}" ]]; then
1210 die "Completely failed to start up mysqld with: ${mysqld}"
1211 fi
1212
1213 ebegin "Setting root password"
1187 # Do this from memory, as we don't want clear text passwords in temp files 1214 # 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'" 1215 local sql="UPDATE mysql.user SET Password = PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE USER='root'"
1189 "${ROOT}/usr/bin/mysql" \ 1216 "${ROOT}/usr/bin/mysql" \
1190 --socket=${socket} \ 1217 --socket=${socket} \
1191 -hlocalhost \ 1218 -hlocalhost \
1192 -e "${sql}" 1219 -e "${sql}"
1220 eend $?
1193 1221
1194 einfo "Loading \"zoneinfo\", this step may require a few seconds ..." 1222 ebegin "Loading \"zoneinfo\", this step may require a few seconds ..."
1195
1196 "${ROOT}/usr/bin/mysql" \ 1223 "${ROOT}/usr/bin/mysql" \
1197 --socket=${socket} \ 1224 --socket=${socket} \
1198 -hlocalhost \ 1225 -hlocalhost \
1199 -uroot \ 1226 -uroot \
1200 -p"${pwd1}" \ 1227 -p"${MYSQL_ROOT_PASSWORD}" \
1201 mysql < "${sqltmp}" 1228 mysql < "${sqltmp}"
1229 rc=$?
1230 eend $?
1231 [ $rc -ne 0 ] && ewarn "Failed to load zoneinfo!"
1202 1232
1203 # Stop the server and cleanup 1233 # Stop the server and cleanup
1234 einfo "Stopping the server ..."
1204 kill $(< "${pidfile}" ) 1235 kill $(< "${pidfile}" )
1205 rm -f "${sqltmp}" 1236 rm -f "${sqltmp}"
1206 einfo "Stopping the server ..."
1207 wait %1 1237 wait %1
1208 einfo "Done" 1238 einfo "Done"
1209} 1239}
1210 1240
1211# @FUNCTION: mysql_pkg_postrm 1241# @FUNCTION: mysql_pkg_postrm

Legend:
Removed from v.1.139  
changed lines
  Added in v.1.140

  ViewVC Help
Powered by ViewVC 1.1.20