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

Diff of /eclass/mysql_fx.eclass

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

Revision 1.5 Revision 1.26
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2007 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_fx.eclass,v 1.5 2006/01/24 20:21:37 vivo Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/mysql_fx.eclass,v 1.26 2011/09/30 02:10:24 jmbsvicetto Exp $
4 4
5# Author: Francesco Riosa <vivo at gentoo.org> 5# Author: Francesco Riosa (Retired) <vivo@gentoo.org>
6# Maintainer: Francesco Riosa <vivo at gentoo.org> 6# Maintainer:
7# - MySQL Team <mysql-bugs@gentoo.org>
8# - Luca Longinotti <chtekk@gentoo.org>
7 9
10inherit multilib
11
12#
8# helper function, version (integer) may have section separated by dots 13# Helper function, version (integer) may have sections separated by dots
9# for readbility 14# for readability.
15#
10stripdots() { 16stripdots() {
11 local dotver=${1:-"0"} 17 local dotver=${1:-"0"}
12 while [[ "${dotver/./}" != "${dotver}" ]] ; do dotver="${dotver/./}" ; done 18 local v=""
13 echo "${dotver:-"0"}" 19 local ret=0
20 if [[ "${dotver/./}" != "${dotver}" ]] ; then
21 # dotted version number
22 for i in 1000000 10000 100 1 ; do
23 v=${dotver%%\.*}
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
29 dotver=0
30 else
31 dotver=${dotver#*\.}
32 fi
33 done
34 echo "${ret}"
35 else
36 # already an integer
37 v=${dotver}
38 while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
39 echo "${v}"
40 fi
14} 41}
15 42
16# bool mysql_check_version_range(char * range, int ver=MYSQL_VERSION_ID, int die_on_err=MYSQL_DIE_ON_RANGE_ERROR)
17# 43#
18# Check if a version number fall inside a range. 44# Check if a version number falls inside a given range.
19# the range include the extremes and must be specified as 45# The range includes the extremes and must be specified as
20# "low_version to hi_version" i.e. "4.00.00.00 to 5.01.99.99" 46# "low_version to high_version" i.e. "4.1.2 to 5.1.99.99".
21# Return true if inside the range 47# Returns true if inside the range.
22# 2005-11-19 <vivo at gentoo.org> 48#
23mysql_check_version_range() { 49mysql_check_version_range() {
24 local lbound="${1%% to *}" ; lbound=$(stripdots "${lbound}") 50 local lbound="${1%% to *}" ; lbound=$(stripdots "${lbound}")
25 local rbound="${1#* to }" ; rbound=$(stripdots "${rbound}") 51 local rbound="${1#* to }" ; rbound=$(stripdots "${rbound}")
26 local my_ver="${2:-"${MYSQL_VERSION_ID}"}" 52 local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
27 [[ $lbound -le $my_ver && $my_ver -le $rbound ]] && return 0 53 [[ ${lbound} -le ${my_ver} ]] && [[ ${my_ver} -le ${rbound} ]] && return 0
28 return 1 54 return 1
29} 55}
30 56
31# private bool _mysql_test_patch_easy( int flags, char * pname )
32# 57#
33# true if found at least one appliable range 58# True if at least one applicable range is found for the patch.
34# 2005-11-19 <vivo at gentoo.org> 59#
35_mysql_test_patch_easy() { 60_mysql_test_patch_ver_pn() {
36 local filesdir="${WORKDIR}/mysql-extras" 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
67 filesdir="${d}"
68 break
69 fi
70 done
71
37 [[ -d "${filesdir}" ]] || die 'sourcedir must be a directory' 72 [[ -d "${filesdir}" ]] || die "Source dir must be a directory"
38 local flags=$1 pname=$2 73 local flags=$1 pname=$2
39 if [[ $(( $flags & 5 )) -eq 5 ]] ; then 74 if [[ $(( $flags & $(( 1 + 4 + 16 )) )) -eq 21 ]] ; then
40 einfo "using \"${pname}\"" 75 einfo "using '${pname}'"
41 mv "${filesdir}/${pname}" "${EPATCH_SOURCE}" || die "cannot move ${pname}" 76 ln -sf "${filesdir}/${pname}" "${EPATCH_SOURCE}" || die "Couldn't move ${pname}"
42 return 0 77 return 0
43 fi 78 fi
79
80 [[ $(( $flags & $(( 2 + 4 )) )) -gt 0 ]] \
81 && allelements="${allelements//", version"}"
82
83 [[ $(( $flags & $(( 8 + 16 )) )) -gt 0 ]] \
84 && allelements="${allelements//", package name"}"
85
86 [[ -n "${allelements}" ]] && [[ "${flags}" -gt 0 ]] \
87 && ewarn "QA notice: ${allelements} missing in ${pname} patch"
88
44 return 1 89 return 1
45} 90}
46 91
47# void mysql_mv_patches(char * index_file, char * filesdir, int my_ver)
48# 92#
49# parse a "index_file" looking for patches to apply to current 93# Parse a "index_file" looking for patches to apply to the
50# version. 94# current MySQL version.
51# If the patch apply then print it's description 95# If the patch applies, print its description.
52# 2005-11-19 <vivo at gentoo.org> 96#
53mysql_mv_patches() { 97mysql_mv_patches() {
54 local index_file="${1:-"${WORKDIR}/mysql-extras/index.txt"}" 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
104 filesdir="${d}"
105 break
106 fi
107 done
108 [[ -d "${filesdir}" ]] || die "No patches directory found!"
109 fi
110
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"
114 break
115 fi
116 done
117
55 local my_ver="${2:-"${MYSQL_VERSION_ID}"}" 118 local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
56 local my_test_fx=${3:-"_mysql_test_patch_easy"} 119 local my_test_fx=${3:-"_mysql_test_patch_ver_pn"}
120 _mysql_mv_patches "${index_file}" "${my_ver}" "${my_test_fx}"
121}
122
123_mysql_mv_patches() {
124 local index_file="${1}"
125 local my_ver="${2}"
126 local my_test_fx="${3}"
57 local dsc=(), ndsc=0 i 127 local dsc ndsc=0 i
128 dsc=( )
58 129
59 # values for flags are (2^x): 130 # Values for flags are (2^x):
60 # 1 - one patch found 131 # 1 - one patch found
61 # 2 - at least one version range is wrong 132 # 2 - at least one version range is wrong
62 # 4 - at least one version range is _good_ 133 # 4 - at least one version range is ok
63 local flags=0 pname='' comments='' 134 # 8 - at least one ${PN} did not match
135 # 16 - at least one ${PN} has been matched
136 local flags=0 pname=""
64 while read row; do 137 while read row ; do
65 case "${row}" in 138 case "${row}" in
66 @patch\ *) 139 @patch\ *)
140 [[ -n "${pname}" ]] \
67 ${my_test_fx} $flags "${pname}" \ 141 && ${my_test_fx} ${flags} "${pname}" \
68 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done 142 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
69 flags=1 ; ndsc=0 ; dsc=() 143 flags=1 ; ndsc=0 ; dsc=( )
70 pname=${row#"@patch "} 144 pname=${row#"@patch "}
71 ;; 145 ;;
72 @ver\ *) 146 @ver\ *)
73 if mysql_check_version_range "${row#"@ver "}" "${my_ver}" ; then 147 if mysql_check_version_range "${row#"@ver "}" "${my_ver}" ; then
74 flags=$(( $flags | 4 )) 148 flags=$(( ${flags} | 4 ))
75 else 149 else
76 flags=$(( $flags | 2 )) 150 flags=$(( ${flags} | 2 ))
151 fi
152 ;;
153 @pn\ *)
154 if [[ ${row#"@pn "} == "${PN}" ]] ; then
155 flags=$(( ${flags} | 16 ))
156 else
157 flags=$(( ${flags} | 8 ))
77 fi 158 fi
78 ;; 159 ;;
79 # @use\ *) ;; 160 # @use\ *) ;;
80 @@\ *) 161 @@\ *)
81 dsc[$ndsc]="${row#"@@ "}" 162 dsc[$ndsc]="${row#"@@ "}"
82 (( ++ndsc )) 163 (( ++ndsc ))
83 ;; 164 ;;
84 esac 165 esac
85 done < "${index_file}" 166 done < "${index_file}"
167
86 ${my_test_fx} $flags "${pname}" \ 168 ${my_test_fx} ${flags} "${pname}" \
87 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done 169 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
88} 170}
89 171
90# * char mysql_strip_double_slash()
91# 172#
92# initialize global variables
93# 2005-11-19 <vivo at gentoo.org>
94mysql_strip_double_slash() {
95 local path="${1}"
96 local newpath="${path/\/\///}"
97 while [[ ${path} != ${newpath} ]]; do
98 path=${newpath}
99 newpath="${path/\/\///}"
100 done
101 echo "${newpath}"
102}
103
104# Is $2 (defaults to $MYSQL_VERSION_ID) at least version $1? 173# Is $2 (defaults to $MYSQL_VERSION_ID) at least version $1?
105# (nice) idea from versionator.eclass 174# (nice) idea from versionator.eclass
175#
106mysql_version_is_at_least() { 176mysql_version_is_at_least() {
107 local want_s=$(stripdots "$1") have_s=$( stripdots "${2:-${MYSQL_VERSION_ID}}") 177 local want_s=$(stripdots "$1") have_s=$(stripdots "${2:-${MYSQL_VERSION_ID}}")
108 [[ -z "${want_s}" ]] && die "mysql_version_is_at_least missing value" 178 [[ -z "${want_s}" ]] && die "mysql_version_is_at_least missing value to check"
109 [[ ${want_s} -le ${have_s} ]] && return 0 || return 1 179 [[ ${want_s} -le ${have_s} ]] && return 0 || return 1
110} 180}
111 181
112# another one inherited from versionator.eclass (version_sort) 182#
113mysql_make_file_list() { 183# To be called on the live filesystem, reassigning symlinks of each MySQL
114 local items= left=0 184# library to the best version available.
115 items=( ${1}-[[:digit:]][[:digit:]][[:digit:]] ) 185#
116 [[ "${items}" == "${1}-[[:digit:]][[:digit:]][[:digit:]]" ]] && items=( ) 186mysql_lib_symlinks() {
117 187
118 while [[ ${left} -lt ${#items[@]} ]] ; do 188 local d dirlist maxdots libname libnameln libsuffix reldir
119 local lowest_idx=${left} 189 libsuffix=$(get_libname)
120 local idx=$(( ${lowest_idx} + 1 )) 190
121 while [[ ${idx} -lt ${#items[@]} ]] ; do 191 einfo "libsuffix = ${libsuffix}"
122 [[ "${items[${lowest_idx}]}" > "${items[${idx}]}" ]] \ 192 einfo "Updating MySQL libraries symlinks"
123 && lowest_idx=${idx} 193
124 idx=$(( ${idx} + 1 )) 194 reldir="${1}"
195 pushd "${reldir}/usr/$(get_libdir)" &> /dev/null
196
197 # dirlist must contain the less significative directory left
198 dirlist="mysql"
199
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
204 maxdots=0
205 libnameln=${libname##*/}
206 # loop in version of the library to link it, similar to how
207 # libtool works
208 while [[ ${libnameln:0-3} != '${libsuffix}' ]] && [[ ${maxdots} -lt 6 ]] ; do
209 rm -f "${libnameln}"
210 ln -s "${libname}" "${libnameln}"
211 (( ++maxdots ))
212 libnameln="${libnameln%.*}"
213 done
214 rm -f "${libnameln}"
215 ln -s "${libname}" "${libnameln}"
125 done 216 done
126 local tmp=${items[${lowest_idx}]}
127 items[${lowest_idx}]=${items[${left}]}
128 items[${left}]=${tmp}
129 left=$(( ${left} + 1 ))
130 done 217 done
131 echo ${items[@]}
132}
133 218
134mysql_choose_better_version() {
135 local items= better="" i
136 items="$( ls ${1}-[[:digit:]][[:digit:]][[:digit:]] )"
137 for i in ${items} ; do
138 if [[ "${i}" > "${better}" ]] ; then
139 better="${i}"
140 fi
141 done
142 echo "${better}"
143}
144
145
146# void mysql_lib_symlinks()
147#
148# To be called on the live filesystem, reassign symlinks to each mysql
149# library to the best version avaiable
150# 2005-12-30 <vivo at gentoo.org>
151mysql_lib_symlinks() {
152 local d dirlist maxdots soname sonameln other better
153 pushd "${ROOT}/usr/$(get_libdir)/" &> /dev/null
154 # dirlist must contain the less significative directory left
155 dirlist="mysql $( mysql_make_file_list mysql )"
156
157 # waste some time in removing and recreating symlinks
158 for d in $dirlist ; do
159 for soname in $(find "${d}" -name "*.so*" -and -not -type "l") ; do
160 # maxdot is a limit versus infinite loop
161 maxdots=0
162 sonameln=${soname##*/}
163 # loop in version of the library to link it, similar to the
164 # libtool work
165 while [[ ${sonameln:0-3} != '.so' ]] && [[ ${maxdots} -lt 6 ]]
166 do
167 rm -f "${sonameln}"
168 ln -s "${soname}" "${sonameln}"
169 (( ++maxdots ))
170 sonameln="${sonameln%.*}"
171 done
172 rm -f "${sonameln}"
173 ln -s "${soname}" "${sonameln}"
174 done
175 done
176 popd &> /dev/null 219 popd &> /dev/null
220}
177 221
178 # "include"s and "mysql_config", needed to compile other sw 222# @FUNCTION: mysql_init_vars
179 for other in "/usr/include/mysql" "/usr/bin/mysql_config" ; do 223# @DESCRIPTION:
180 pushd "${ROOT}${other%/*}" &> /dev/null 224# void mysql_init_vars()
181 if ! [[ -d "${other##*/}" ]] ; then 225# Initialize global variables
182 better=$( mysql_choose_better_version "${other##*/}" ) 226# 2005-11-19 <vivo@gentoo.org>
183 [[ -L "${other##*/}" ]] && rm -f "${other##*/}" 227mysql_init_vars() {
184 ! [[ -f "${other##*/}" ]] && ln -sf "${better}" "${other##*/}" 228 MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="/usr/share/mysql"}
229 MY_SYSCONFDIR=${MY_SYSCONFDIR="/etc/mysql"}
230 MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="/var/lib/mysql"}
231 MY_LOGDIR=${MY_LOGDIR="/var/log/mysql"}
232 MY_INCLUDEDIR=${MY_INCLUDEDIR="/usr/include/mysql"}
233 MY_LIBDIR=${MY_LIBDIR="/usr/$(get_libdir)/mysql"}
234
235 if [[ -z "${MY_DATADIR}" ]] ; then
236 MY_DATADIR=""
237 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
238 MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
239 | sed -ne '/datadir/s|^--datadir=||p' \
240 | tail -n1`
241 if [[ -z "${MY_DATADIR}" ]] ; then
242 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
243 | sed -e 's/.*=\s*//' \
244 | tail -n1`
185 fi 245 fi
186 popd &> /dev/null 246 fi
187 done 247 if [[ -z "${MY_DATADIR}" ]] ; then
248 MY_DATADIR="${MY_LOCALSTATEDIR}"
249 einfo "Using default MY_DATADIR"
250 fi
251 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
252
253 if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
254 if [[ -e "${MY_DATADIR}" ]] ; then
255 # If you get this and you're wondering about it, see bug #207636
256 elog "MySQL datadir found in ${MY_DATADIR}"
257 elog "A new one will not be created."
258 PREVIOUS_DATADIR="yes"
259 else
260 PREVIOUS_DATADIR="no"
261 fi
262 export PREVIOUS_DATADIR
263 fi
264 else
265 if [[ ${EBUILD_PHASE} == "config" ]]; then
266 local new_MY_DATADIR
267 new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
268 | sed -ne '/datadir/s|^--datadir=||p' \
269 | tail -n1`
270
271 if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
272 ewarn "MySQL MY_DATADIR has changed"
273 ewarn "from ${MY_DATADIR}"
274 ewarn "to ${new_MY_DATADIR}"
275 MY_DATADIR="${new_MY_DATADIR}"
276 fi
277 fi
278 fi
279
280 if [ "${MY_SOURCEDIR:-unset}" == "unset" ]; then
281 MY_SOURCEDIR=${SERVER_URI##*/}
282 MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
283 fi
284
285 export MY_SHAREDSTATEDIR MY_SYSCONFDIR
286 export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
287 export MY_INCLUDEDIR MY_DATADIR MY_SOURCEDIR
188} 288}

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.26

  ViewVC Help
Powered by ViewVC 1.1.20