1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # Author: Francesco Riosa (Retired) <vivo@gentoo.org>
6 # - MySQL Team <mysql-bugs@gentoo.org>
7 # - Luca Longinotti <chtekk@gentoo.org>
12 # Helper function, version (integer) may have sections separated by dots
16 local dotver=${1:-"0"}
19 if [[ "${dotver/./}" != "${dotver}" ]] ; then
20 # dotted version number
21 for i in 1000000 10000 100 1 ; do
23 # remove leading zeroes
24 while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
25 # increment integer version number
26 ret=$(( ${v} * ${i} + ${ret} ))
27 if [[ "${dotver}" == "${dotver/\.}" ]] ; then
37 while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
43 # Check if a version number falls inside a given range.
44 # The range includes the extremes and must be specified as
45 # "low_version to high_version" i.e. "4.1.2 to 5.1.99.99".
46 # Returns true if inside the range.
48 mysql_check_version_range() {
49 local lbound="${1%% to *}" ; lbound=$(stripdots "${lbound}")
50 local rbound="${1#* to }" ; rbound=$(stripdots "${rbound}")
51 local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
52 [[ ${lbound} -le ${my_ver} ]] && [[ ${my_ver} -le ${rbound} ]] && return 0
57 # True if at least one applicable range is found for the patch.
59 _mysql_test_patch_ver_pn() {
60 local allelements=", version, package name"
61 # So that it fails the directory test if none of them exist
62 local filesdir="/dev/null"
63 for d in "${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}" \
64 "${WORKDIR}/mysql-extras" ; do
65 if [ -d "${d}" ]; then
71 [[ -d "${filesdir}" ]] || die "Source dir must be a directory"
72 local flags=$1 pname=$2
73 if [[ $(( $flags & $(( 1 + 4 + 16 )) )) -eq 21 ]] ; then
74 einfo "using '${pname}'"
75 ln -sf "${filesdir}/${pname}" "${EPATCH_SOURCE}" || die "Couldn't move ${pname}"
79 [[ $(( $flags & $(( 2 + 4 )) )) -gt 0 ]] \
80 && allelements="${allelements//", version"}"
82 [[ $(( $flags & $(( 8 + 16 )) )) -gt 0 ]] \
83 && allelements="${allelements//", package name"}"
85 [[ -n "${allelements}" ]] && [[ "${flags}" -gt 0 ]] \
86 && ewarn "QA notice: ${allelements} missing in ${pname} patch"
92 # Parse a "index_file" looking for patches to apply to the
93 # current MySQL version.
94 # If the patch applies, print its description.
97 # So that it fails the directory test if none of them exist
98 local filesdir="/dev/null"
99 if [[ -z "${1}" ]]; then
100 for d in "${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}" \
101 "${WORKDIR}/mysql-extras" ; do
102 if [ -d "${d}" ]; then
107 [[ -d "${filesdir}" ]] || die "No patches directory found!"
110 for i in "$1" "${filesdir}/0000_index.txt" "${filesdir}/000_index.txt" ; do
111 if [ -n "$i" -a -f "$i" ]; then
112 local index_file="$i"
117 local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
118 local my_test_fx=${3:-"_mysql_test_patch_ver_pn"}
119 _mysql_mv_patches "${index_file}" "${my_ver}" "${my_test_fx}"
122 _mysql_mv_patches() {
123 local index_file="${1}"
125 local my_test_fx="${3}"
129 # Values for flags are (2^x):
130 # 1 - one patch found
131 # 2 - at least one version range is wrong
132 # 4 - at least one version range is ok
133 # 8 - at least one ${PN} did not match
134 # 16 - at least one ${PN} has been matched
135 local flags=0 pname=""
139 [[ -n "${pname}" ]] \
140 && ${my_test_fx} ${flags} "${pname}" \
141 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
142 flags=1 ; ndsc=0 ; dsc=( )
143 pname=${row#"@patch "}
146 if mysql_check_version_range "${row#"@ver "}" "${my_ver}" ; then
147 flags=$(( ${flags} | 4 ))
149 flags=$(( ${flags} | 2 ))
153 if [[ ${row#"@pn "} == "${PN}" ]] ; then
154 flags=$(( ${flags} | 16 ))
156 flags=$(( ${flags} | 8 ))
161 dsc[$ndsc]="${row#"@@ "}"
165 done < "${index_file}"
167 ${my_test_fx} ${flags} "${pname}" \
168 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
172 # Is $2 (defaults to $MYSQL_VERSION_ID) at least version $1?
173 # (nice) idea from versionator.eclass
175 mysql_version_is_at_least() {
176 local want_s=$(stripdots "$1") have_s=$(stripdots "${2:-${MYSQL_VERSION_ID}}")
177 [[ -z "${want_s}" ]] && die "mysql_version_is_at_least missing value to check"
178 [[ ${want_s} -le ${have_s} ]] && return 0 || return 1
182 # To be called on the live filesystem, reassigning symlinks of each MySQL
183 # library to the best version available.
185 mysql_lib_symlinks() {
187 local d dirlist maxdots libname libnameln libsuffix reldir
188 libsuffix=$(get_libname)
190 einfo "libsuffix = ${libsuffix}"
191 einfo "Updating MySQL libraries symlinks"
194 pushd "${reldir}/usr/$(get_libdir)" &> /dev/null
196 # dirlist must contain the less significative directory left
199 # waste some time in removing and recreating symlinks
200 for d in $dirlist ; do
201 for libname in $( find "${d}" -mindepth 1 -maxdepth 1 -name "*${libsuffix}*" -and -not -type "l" 2>/dev/null ) ; do
202 # maxdot is a limit versus infinite loop
204 libnameln=${libname##*/}
205 # loop in version of the library to link it, similar to how
207 if [[ ${CHOST} == *-darwin* ]] ; then
208 # macho: libname.x.y.z.dylib
209 local libbasename=${libnameln%%.*} # libname
210 local libver=${libnameln#${libbasename}} # .x.y.z.dylib
211 libver=${libver%${libsuffix}} # .x.y.z
212 while [[ -n ${libver} ]] && [[ ${maxdots} -lt 6 ]] ; do
213 libnameln="${libbasename}${libver}${libsuffix}"
215 ln -s "${libname}" "${libnameln}"
219 libnameln="${libbasename}${libsuffix}"
221 ln -s "${libname}" "${libnameln}"
223 # elf: libname.so.x.y.z
224 while [[ ${libnameln:0-3} != '${libsuffix}' ]] && [[ ${maxdots} -lt 6 ]] ; do
226 ln -s "${libname}" "${libnameln}"
228 libnameln="${libnameln%.*}"
231 ln -s "${libname}" "${libnameln}"
239 # @FUNCTION: mysql_init_vars
241 # void mysql_init_vars()
242 # Initialize global variables
243 # 2005-11-19 <vivo@gentoo.org>
245 MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
246 MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
247 MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
248 MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
249 MY_INCLUDEDIR=${MY_INCLUDEDIR="${EPREFIX}/usr/include/mysql"}
250 MY_LIBDIR=${MY_LIBDIR="${EPREFIX}/usr/$(get_libdir)/mysql"}
252 if [[ -z "${MY_DATADIR}" ]] ; then
254 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
255 MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
256 | sed -ne '/datadir/s|^--datadir=||p' \
258 if [[ -z "${MY_DATADIR}" ]] ; then
259 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
260 | sed -e 's/.*=\s*//' \
264 if [[ -z "${MY_DATADIR}" ]] ; then
265 MY_DATADIR="${MY_LOCALSTATEDIR}"
266 einfo "Using default MY_DATADIR"
268 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
270 if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
271 if [[ -e "${MY_DATADIR}" ]] ; then
272 # If you get this and you're wondering about it, see bug #207636
273 elog "MySQL datadir found in ${MY_DATADIR}"
274 elog "A new one will not be created."
275 PREVIOUS_DATADIR="yes"
277 PREVIOUS_DATADIR="no"
279 export PREVIOUS_DATADIR
282 if [[ ${EBUILD_PHASE} == "config" ]]; then
284 new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
285 | sed -ne '/datadir/s|^--datadir=||p' \
288 if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
289 ewarn "MySQL MY_DATADIR has changed"
290 ewarn "from ${MY_DATADIR}"
291 ewarn "to ${new_MY_DATADIR}"
292 MY_DATADIR="${new_MY_DATADIR}"
297 if [ "${MY_SOURCEDIR:-unset}" == "unset" ]; then
298 MY_SOURCEDIR=${SERVER_URI##*/}
299 MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
302 export MY_SHAREDSTATEDIR MY_SYSCONFDIR
303 export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
304 export MY_INCLUDEDIR MY_DATADIR MY_SOURCEDIR