1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # Author: Francesco Riosa (Retired) <vivo@gentoo.org>
7 # - MySQL Team <mysql-bugs@gentoo.org>
8 # - Luca Longinotti <chtekk@gentoo.org>
13 # Helper function, version (integer) may have sections separated by dots
17 local dotver=${1:-"0"}
20 if [[ "${dotver/./}" != "${dotver}" ]] ; then
21 # dotted version number
22 for i in 1000000 10000 100 1 ; do
24 # remove leading zeroes
25 while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
26 # increment integer version number
27 ret=$(( ${v} * ${i} + ${ret} ))
28 if [[ "${dotver}" == "${dotver/\.}" ]] ; then
38 while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
44 # Check if a version number falls inside a given range.
45 # The range includes the extremes and must be specified as
46 # "low_version to high_version" i.e. "4.1.2 to 5.1.99.99".
47 # Returns true if inside the range.
49 mysql_check_version_range() {
50 local lbound="${1%% to *}" ; lbound=$(stripdots "${lbound}")
51 local rbound="${1#* to }" ; rbound=$(stripdots "${rbound}")
52 local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
53 [[ ${lbound} -le ${my_ver} ]] && [[ ${my_ver} -le ${rbound} ]] && return 0
58 # True if at least one applicable range is found for the patch.
60 _mysql_test_patch_ver_pn() {
61 local allelements=", version, package name"
62 # So that it fails the directory test if none of them exist
63 local filesdir="/dev/null"
64 for d in "${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}" \
65 "${WORKDIR}/mysql-extras" ; do
66 if [ -d "${d}" ]; then
72 [[ -d "${filesdir}" ]] || die "Source dir must be a directory"
73 local flags=$1 pname=$2
74 if [[ $(( $flags & $(( 1 + 4 + 16 )) )) -eq 21 ]] ; then
75 einfo "using '${pname}'"
76 ln -sf "${filesdir}/${pname}" "${EPATCH_SOURCE}" || die "Couldn't move ${pname}"
80 [[ $(( $flags & $(( 2 + 4 )) )) -gt 0 ]] \
81 && allelements="${allelements//", version"}"
83 [[ $(( $flags & $(( 8 + 16 )) )) -gt 0 ]] \
84 && allelements="${allelements//", package name"}"
86 [[ -n "${allelements}" ]] && [[ "${flags}" -gt 0 ]] \
87 && ewarn "QA notice: ${allelements} missing in ${pname} patch"
93 # Parse a "index_file" looking for patches to apply to the
94 # current MySQL version.
95 # If the patch applies, print its description.
98 # So that it fails the directory test if none of them exist
99 local filesdir="/dev/null"
100 if [[ -z "${1}" ]]; then
101 for d in "${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}" \
102 "${WORKDIR}/mysql-extras" ; do
103 if [ -d "${d}" ]; then
108 [[ -d "${filesdir}" ]] || die "No patches directory found!"
111 for i in "$1" "${filesdir}/0000_index.txt" "${filesdir}/000_index.txt" ; do
112 if [ -n "$i" -a -f "$i" ]; then
113 local index_file="$i"
118 local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
119 local my_test_fx=${3:-"_mysql_test_patch_ver_pn"}
120 _mysql_mv_patches "${index_file}" "${my_ver}" "${my_test_fx}"
123 _mysql_mv_patches() {
124 local index_file="${1}"
126 local my_test_fx="${3}"
130 # Values for flags are (2^x):
131 # 1 - one patch found
132 # 2 - at least one version range is wrong
133 # 4 - at least one version range is ok
134 # 8 - at least one ${PN} did not match
135 # 16 - at least one ${PN} has been matched
136 local flags=0 pname=""
140 [[ -n "${pname}" ]] \
141 && ${my_test_fx} ${flags} "${pname}" \
142 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
143 flags=1 ; ndsc=0 ; dsc=( )
144 pname=${row#"@patch "}
147 if mysql_check_version_range "${row#"@ver "}" "${my_ver}" ; then
148 flags=$(( ${flags} | 4 ))
150 flags=$(( ${flags} | 2 ))
154 if [[ ${row#"@pn "} == "${PN}" ]] ; then
155 flags=$(( ${flags} | 16 ))
157 flags=$(( ${flags} | 8 ))
162 dsc[$ndsc]="${row#"@@ "}"
166 done < "${index_file}"
168 ${my_test_fx} ${flags} "${pname}" \
169 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
173 # Is $2 (defaults to $MYSQL_VERSION_ID) at least version $1?
174 # (nice) idea from versionator.eclass
176 mysql_version_is_at_least() {
177 local want_s=$(stripdots "$1") have_s=$(stripdots "${2:-${MYSQL_VERSION_ID}}")
178 [[ -z "${want_s}" ]] && die "mysql_version_is_at_least missing value to check"
179 [[ ${want_s} -le ${have_s} ]] && return 0 || return 1
183 # To be called on the live filesystem, reassigning symlinks of each MySQL
184 # library to the best version available.
186 mysql_lib_symlinks() {
188 local d dirlist maxdots libname libnameln libsuffix reldir
189 libsuffix=$(get_libname)
191 einfo "libsuffix = ${libsuffix}"
192 einfo "Updating MySQL libraries symlinks"
195 pushd "${reldir}/usr/$(get_libdir)" &> /dev/null
197 # dirlist must contain the less significative directory left
200 # waste some time in removing and recreating symlinks
201 for d in $dirlist ; do
202 for libname in $( find "${d}" -mindepth 1 -maxdepth 1 -name "*${libsuffix}*" -and -not -type "l" 2>/dev/null ) ; do
203 # maxdot is a limit versus infinite loop
205 libnameln=${libname##*/}
206 # loop in version of the library to link it, similar to how
208 if [[ ${CHOST} == *-darwin* ]] ; then
209 # macho: libname.x.y.z.dylib
210 local libbasename=${libnameln%%.*} # libname
211 local libver=${libnameln#${libbasename}} # .x.y.z.dylib
212 libver=${libver%${libsuffix}} # .x.y.z
213 while [[ -n ${libver} ]] && [[ ${maxdots} -lt 6 ]] ; do
214 libnameln="${libbasename}${libver}${libsuffix}"
216 ln -s "${libname}" "${libnameln}"
220 libnameln="${libbasename}${libsuffix}"
222 ln -s "${libname}" "${libnameln}"
224 # elf: libname.so.x.y.z
225 while [[ ${libnameln:0-3} != '${libsuffix}' ]] && [[ ${maxdots} -lt 6 ]] ; do
227 ln -s "${libname}" "${libnameln}"
229 libnameln="${libnameln%.*}"
232 ln -s "${libname}" "${libnameln}"
240 # @FUNCTION: mysql_init_vars
242 # void mysql_init_vars()
243 # Initialize global variables
244 # 2005-11-19 <vivo@gentoo.org>
246 MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
247 MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
248 MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
249 MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
250 MY_INCLUDEDIR=${MY_INCLUDEDIR="${EPREFIX}/usr/include/mysql"}
251 MY_LIBDIR=${MY_LIBDIR="${EPREFIX}/usr/$(get_libdir)/mysql"}
253 if [[ -z "${MY_DATADIR}" ]] ; then
255 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
256 MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
257 | sed -ne '/datadir/s|^--datadir=||p' \
259 if [[ -z "${MY_DATADIR}" ]] ; then
260 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
261 | sed -e 's/.*=\s*//' \
265 if [[ -z "${MY_DATADIR}" ]] ; then
266 MY_DATADIR="${MY_LOCALSTATEDIR}"
267 einfo "Using default MY_DATADIR"
269 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
271 if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
272 if [[ -e "${MY_DATADIR}" ]] ; then
273 # If you get this and you're wondering about it, see bug #207636
274 elog "MySQL datadir found in ${MY_DATADIR}"
275 elog "A new one will not be created."
276 PREVIOUS_DATADIR="yes"
278 PREVIOUS_DATADIR="no"
280 export PREVIOUS_DATADIR
283 if [[ ${EBUILD_PHASE} == "config" ]]; then
285 new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
286 | sed -ne '/datadir/s|^--datadir=||p' \
289 if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
290 ewarn "MySQL MY_DATADIR has changed"
291 ewarn "from ${MY_DATADIR}"
292 ewarn "to ${new_MY_DATADIR}"
293 MY_DATADIR="${new_MY_DATADIR}"
298 if [ "${MY_SOURCEDIR:-unset}" == "unset" ]; then
299 MY_SOURCEDIR=${SERVER_URI##*/}
300 MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
303 export MY_SHAREDSTATEDIR MY_SYSCONFDIR
304 export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
305 export MY_INCLUDEDIR MY_DATADIR MY_SOURCEDIR