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

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

  ViewVC Help
Powered by ViewVC 1.1.20