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

Contents of /eclass/mysql_fx.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Sat Jan 14 19:00:32 2006 UTC (12 years, 5 months ago) by vivo
Branch: MAIN
Changes since 1.2: +50 -4 lines
upgraded patch tarball, better management for client packages that will need to compile against mysql

1 # Copyright 1999-2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/mysql_fx.eclass,v 1.2 2006/01/04 20:40:26 vivo Exp $
4
5 # Author: Francesco Riosa <vivo at gentoo.org>
6 # Maintainer: Francesco Riosa <vivo at gentoo.org>
7
8 # helper function, version (integer) may have section separated by dots
9 # for readbility
10 stripdots() {
11 local dotver=${1:-"0"}
12 while [[ "${dotver/./}" != "${dotver}" ]] ; do dotver="${dotver/./}" ; done
13 echo "${dotver:-"0"}"
14 }
15
16 # bool mysql_check_version_range(char * range, int ver=MYSQL_VERSION_ID, int die_on_err=MYSQL_DIE_ON_RANGE_ERROR)
17 #
18 # Check if a version number fall inside a range.
19 # the range include the extremes and must be specified as
20 # "low_version to hi_version" i.e. "4.00.00.00 to 5.01.99.99"
21 # Return true if inside the range
22 # 2005-11-19 <vivo at gentoo.org>
23 mysql_check_version_range() {
24 local lbound="${1%% to *}" ; lbound=$(stripdots "${lbound}")
25 local rbound="${1#* to }" ; rbound=$(stripdots "${rbound}")
26 local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
27 [[ $lbound -le $my_ver && $my_ver -le $rbound ]] && return 0
28 return 1
29 }
30
31 # private bool _mysql_test_patch_easy( int flags, char * pname )
32 #
33 # true if found at least one appliable range
34 # 2005-11-19 <vivo at gentoo.org>
35 _mysql_test_patch_easy() {
36 local filesdir="${WORKDIR}/mysql-extras"
37 [[ -d "${filesdir}" ]] || die 'sourcedir must be a directory'
38 local flags=$1 pname=$2
39 if [[ $(( $flags & 5 )) -eq 5 ]] ; then
40 einfo "using \"${pname}\""
41 mv "${filesdir}/${pname}" "${EPATCH_SOURCE}" || die "cannot move ${pname}"
42 return 0
43 fi
44 return 1
45 }
46
47 # void mysql_mv_patches(char * index_file, char * filesdir, int my_ver)
48 #
49 # parse a "index_file" looking for patches to apply to current
50 # version.
51 # If the patch apply then print it's description
52 # 2005-11-19 <vivo at gentoo.org>
53 mysql_mv_patches() {
54 local index_file="${1:-"${WORKDIR}/mysql-extras/index.txt"}"
55 local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
56 local my_test_fx=${3:-"_mysql_test_patch_easy"}
57 local dsc=(), ndsc=0 i
58
59 # values for flags are (2^x):
60 # 1 - one patch found
61 # 2 - at least one version range is wrong
62 # 4 - at least one version range is _good_
63 local flags=0 pname='' comments=''
64 while read row; do
65 case "${row}" in
66 @patch\ *)
67 ${my_test_fx} $flags "${pname}" \
68 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
69 flags=1 ; ndsc=0 ; dsc=()
70 pname=${row#"@patch "}
71 ;;
72 @ver\ *)
73 if mysql_check_version_range "${row#"@ver "}" "${my_ver}" ; then
74 flags=$(( $flags | 4 ))
75 else
76 flags=$(( $flags | 2 ))
77 fi
78 ;;
79 # @use\ *) ;;
80 @@\ *)
81 dsc[$ndsc]="${row#"@@ "}"
82 (( ++ndsc ))
83 ;;
84 esac
85 done < "${index_file}"
86 ${my_test_fx} $flags "${pname}" \
87 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
88 }
89
90
91 # void mysql_init_vars()
92 #
93 # initialize global variables
94 # 2005-11-19 <vivo at gentoo.org>
95 mysql_init_vars() {
96
97 if [[ ${SLOT} -eq 0 ]] ; then
98 MY_SUFFIX=""
99 else
100 MY_SUFFIX=${MY_SUFFIX:-"-${SLOT}"}
101 fi
102 MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR:-"/usr/share/mysql${MY_SUFFIX}"}
103 MY_SYSCONFDIR=${MY_SYSCONFDIR="/etc/mysql${MY_SUFFIX}"}
104 MY_LIBDIR=${MY_LIBDIR="/usr/$(get_libdir)/mysql${MY_SUFFIX}"}
105 MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="/var/lib/mysql${MY_SUFFIX}"}
106 MY_LOGDIR=${MY_LOGDIR="/var/log/mysql${MY_SUFFIX}"}
107 MY_INCLUDEDIR=${MY_INCLUDEDIR="/usr/include/mysql${MY_SUFFIX}"}
108
109 if [ -z "${DATADIR}" ]; then
110 DATADIR=""
111 if [ -f "${SYSCONFDIR}/my.cnf" ] ; then
112 DATADIR=`"my_print_defaults${MY_SUFFIX}" mysqld 2>/dev/null | sed -ne '/datadir/s|^--datadir=||p' | tail -n1`
113 if [ -z "${DATADIR}" ]; then
114 DATADIR=`grep ^datadir "${SYSCONFDIR}/my.cnf" | sed -e 's/.*=\s*//'`
115 fi
116 fi
117 if [ -z "${DATADIR}" ]; then
118 DATADIR="${MY_LOCALSTATEDIR}"
119 einfo "Using default DATADIR"
120 fi
121 einfo "MySQL DATADIR is ${DATADIR}"
122
123 if [ -z "${PREVIOUS_DATADIR}" ] ; then
124 if [ -a "${DATADIR}" ] ; then
125 ewarn "Previous datadir found, it's YOUR job to change"
126 ewarn "ownership and have care of it"
127 PREVIOUS_DATADIR="yes"
128 export PREVIOUS_DATADIR
129 else
130 PREVIOUS_DATADIR="no"
131 export PREVIOUS_DATADIR
132 fi
133 fi
134 fi
135
136 export MY_SUFFIX MY_SHAREDSTATEDIR MY_SYSCONFDIR
137 export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
138 export MY_INCLUDEDIR
139 export DATADIR
140 }
141
142 # void mysql_init_vars()
143 #
144 # initialize global variables
145 # 2005-11-19 <vivo at gentoo.org>
146 mysql_strip_double_slash() {
147 local path="${1}"
148 local newpath="${path/\/\///}"
149 while [[ ${path} != ${newpath} ]]; do
150 path=${newpath}
151 newpath="${path/\/\///}"
152 done
153 echo "${newpath}"
154 }
155
156 # Is $2 (defaults to $MYSQL_VERSION_ID) at least version $1?
157 # (nice) idea from versionator.eclass
158 mysql_version_is_at_least() {
159 local want_s=$(stripdots "$1") have_s=$( stripdots "${2:-${MYSQL_VERSION_ID}}")
160 [[ -z "${want_s}" ]] && die "mysql_version_is_at_least missing value"
161 [[ ${want_s} -le ${have_s} ]] && return 0 || return 1
162 }
163
164 # another one inherited from versionator.eclass (version_sort)
165 mysql_make_file_list() {
166 local items= left=0
167 items=( ${1}-[[:digit:]][[:digit:]][[:digit:]] )
168 [[ "${items}" == "${1}-[[:digit:]][[:digit:]][[:digit:]]" ]] && items=( )
169
170 while [[ ${left} -lt ${#items[@]} ]] ; do
171 local lowest_idx=${left}
172 local idx=$(( ${lowest_idx} + 1 ))
173 while [[ ${idx} -lt ${#items[@]} ]] ; do
174 [[ "${items[${lowest_idx}]}" > "${items[${idx}]}" ]] \
175 && lowest_idx=${idx}
176 idx=$(( ${idx} + 1 ))
177 done
178 local tmp=${items[${lowest_idx}]}
179 items[${lowest_idx}]=${items[${left}]}
180 items[${left}]=${tmp}
181 left=$(( ${left} + 1 ))
182 done
183 echo ${items[@]}
184 }
185
186 mysql_choose_better_version() {
187 local items= better="" i
188 items=${1}-[[:digit:]][[:digit:]][[:digit:]]
189 [[ "${items}" == "${1}-[[:digit:]][[:digit:]][[:digit:]]" ]] && items=""
190 for i in ${items} ; do
191 if [[ "${i}" > "${better}" ]] ; then
192 better="${i}"
193 fi
194 done
195 echo "${better}"
196 }
197
198
199 # void mysql_lib_symlinks()
200 #
201 # To be called on the live filesystem, reassign symlinks to each mysql
202 # library to the best version avaiable
203 # 2005-12-30 <vivo at gentoo.org>
204 mysql_lib_symlinks() {
205 local d dirlist maxdots soname sonameln other better
206 pushd "${ROOT}/usr/$(get_libdir)/"
207 # dirlist must contain the less significative directory left
208 dirlist="mysql (mysql_make_file_list mysql)"
209
210 # waste some time in removing and recreating symlinks
211 for d in $dirlist ; do
212 for soname in $(find "${d}" -name "*.so*" -and -not -type "l") ; do
213 # maxdot is a limit versus infinite loop
214 maxdots=0
215 sonameln=${soname##*/}
216 # loop in version of the library to link it, similar to the
217 # libtool work
218 while [[ ${sonameln:0-3} != '.so' ]] && [[ ${maxdots} -lt 6 ]]
219 do
220 rm -f "${sonameln}"
221 ln -s "${soname}" "${sonameln}"
222 (( ++maxdots ))
223 sonameln="${sonameln%.*}"
224 done
225 rm -f "${sonameln}"
226 ln -s "${soname}" "${sonameln}"
227 done
228 done
229 popd
230
231 # "include"s and "mysql_config", needed to compile other sw
232 for other in "/usr/include/mysql" "/usr/bin/mysql_config" ; do
233 pushd "${ROOT}${other%/*}" &> /dev/null
234 if ! [[ -d "${other##*/}" ]] ; then
235 better=$( mysql_choose_better_version "${other##*/}" )
236 [[ -L "${other##*/}" ]] && rm -f "${other##*/}"
237 ! [[ -f "${other##*/}" ]] && ln -sf "${better}" "${other##*/}"
238 fi
239 popd &> /dev/null
240 done
241 }

  ViewVC Help
Powered by ViewVC 1.1.20