/[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.2 Revision 1.20
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.2 2006/01/04 20:40:26 vivo Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/mysql_fx.eclass,v 1.20 2007/04/23 19:35:05 swegener 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: Luca Longinotti <chtekk@gentoo.org>
7 7
8inherit multilib
9
10#
8# helper function, version (integer) may have section separated by dots 11# Helper function, version (integer) may have sections separated by dots
9# for readbility 12# for readability.
13#
10stripdots() { 14stripdots() {
11 local dotver=${1:-"0"} 15 local dotver=${1:-"0"}
12 while [[ "${dotver/./}" != "${dotver}" ]] ; do dotver="${dotver/./}" ; done 16 local v=""
13 echo "${dotver:-"0"}" 17 local ret=0
18 if [[ "${dotver/./}" != "${dotver}" ]] ; then
19 # dotted version number
20 for i in 1000000 10000 100 1 ; do
21 v=${dotver%%\.*}
22 # remove leading zeroes
23 while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
24 # increment integer version number
25 ret=$(( ${v} * ${i} + ${ret} ))
26 if [[ "${dotver}" == "${dotver/\.}" ]] ; then
27 dotver=0
28 else
29 dotver=${dotver#*\.}
30 fi
31 done
32 echo "${ret}"
33 else
34 # already an integer
35 v=${dotver}
36 while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
37 echo "${v}"
38 fi
14} 39}
15 40
16# bool mysql_check_version_range(char * range, int ver=MYSQL_VERSION_ID, int die_on_err=MYSQL_DIE_ON_RANGE_ERROR)
17# 41#
18# Check if a version number fall inside a range. 42# Check if a version number falls inside a given range.
19# the range include the extremes and must be specified as 43# 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" 44# "low_version to high_version" i.e. "4.1.2 to 5.1.99.99".
21# Return true if inside the range 45# Returns true if inside the range.
22# 2005-11-19 <vivo at gentoo.org> 46#
23mysql_check_version_range() { 47mysql_check_version_range() {
24 local lbound="${1%% to *}" ; lbound=$(stripdots "${lbound}") 48 local lbound="${1%% to *}" ; lbound=$(stripdots "${lbound}")
25 local rbound="${1#* to }" ; rbound=$(stripdots "${rbound}") 49 local rbound="${1#* to }" ; rbound=$(stripdots "${rbound}")
26 local my_ver="${2:-"${MYSQL_VERSION_ID}"}" 50 local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
27 [[ $lbound -le $my_ver && $my_ver -le $rbound ]] && return 0 51 [[ ${lbound} -le ${my_ver} ]] && [[ ${my_ver} -le ${rbound} ]] && return 0
28 return 1 52 return 1
29} 53}
30 54
31# private bool _mysql_test_patch_easy( int flags, char * pname )
32# 55#
33# true if found at least one appliable range 56# True if at least one applicable range is found for the patch.
34# 2005-11-19 <vivo at gentoo.org> 57#
35_mysql_test_patch_easy() { 58_mysql_test_patch_ver_pn() {
36 local filesdir="${WORKDIR}/mysql-extras" 59 local allelements=", version, package name"
60 # So that it fails the directory test if none of them exist
61 local filesdir="/dev/null"
62 for d in "${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}" \
63 "${WORKDIR}/mysql-extras" ; do
64 if [ -d "${d}" ]; then
65 filesdir="${d}"
66 break
67 fi
68 done
69
37 [[ -d "${filesdir}" ]] || die 'sourcedir must be a directory' 70 [[ -d "${filesdir}" ]] || die "Source dir must be a directory"
38 local flags=$1 pname=$2 71 local flags=$1 pname=$2
39 if [[ $(( $flags & 5 )) -eq 5 ]] ; then 72 if [[ $(( $flags & $(( 1 + 4 + 16 )) )) -eq 21 ]] ; then
40 einfo "using \"${pname}\"" 73 einfo "using '${pname}'"
41 mv "${filesdir}/${pname}" "${EPATCH_SOURCE}" || die "cannot move ${pname}" 74 mv -f "${filesdir}/${pname}" "${EPATCH_SOURCE}" || die "Couldn't move ${pname}"
42 return 0 75 return 0
43 fi 76 fi
77
78 [[ $(( $flags & $(( 2 + 4 )) )) -gt 0 ]] \
79 && allelements="${allelements//", version"}"
80
81 [[ $(( $flags & $(( 8 + 16 )) )) -gt 0 ]] \
82 && allelements="${allelements//", package name"}"
83
84 [[ -n "${allelements}" ]] && [[ "${flags}" -gt 0 ]] \
85 && ewarn "QA notice: ${allelements} missing in ${pname} patch"
86
44 return 1 87 return 1
45} 88}
46 89
47# void mysql_mv_patches(char * index_file, char * filesdir, int my_ver)
48# 90#
49# parse a "index_file" looking for patches to apply to current 91# Parse a "index_file" looking for patches to apply to the
50# version. 92# current MySQL version.
51# If the patch apply then print it's description 93# If the patch applies, print its description.
52# 2005-11-19 <vivo at gentoo.org> 94#
53mysql_mv_patches() { 95mysql_mv_patches() {
54 local index_file="${1:-"${WORKDIR}/mysql-extras/index.txt"}" 96 # So that it fails the directory test if none of them exist
97 local filesdir="/dev/null"
98 if [[ -z "${1}" ]]; then
99 for d in "${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}" \
100 "${WORKDIR}/mysql-extras" ; do
101 if [ -d "${d}" ]; then
102 filesdir="${d}"
103 break
104 fi
105 done
106 [[ -d "${filesdir}" ]] || die "No patches directory found!"
107 fi
108
109 local index_file="${1:-"${filesdir}/000_index.txt"}"
55 local my_ver="${2:-"${MYSQL_VERSION_ID}"}" 110 local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
56 local my_test_fx=${3:-"_mysql_test_patch_easy"} 111 local my_test_fx=${3:-"_mysql_test_patch_ver_pn"}
112 _mysql_mv_patches "${index_file}" "${my_ver}" "${my_test_fx}"
113}
114
115_mysql_mv_patches() {
116 local index_file="${1}"
117 local my_ver="${2}"
118 local my_test_fx="${3}"
57 local dsc=(), ndsc=0 i 119 local dsc ndsc=0 i
120 dsc=( )
58 121
59 # values for flags are (2^x): 122 # Values for flags are (2^x):
60 # 1 - one patch found 123 # 1 - one patch found
61 # 2 - at least one version range is wrong 124 # 2 - at least one version range is wrong
62 # 4 - at least one version range is _good_ 125 # 4 - at least one version range is ok
63 local flags=0 pname='' comments='' 126 # 8 - at least one ${PN} did not match
127 # 16 - at least one ${PN} has been matched
128 local flags=0 pname=""
64 while read row; do 129 while read row ; do
65 case "${row}" in 130 case "${row}" in
66 @patch\ *) 131 @patch\ *)
132 [[ -n "${pname}" ]] \
67 ${my_test_fx} $flags "${pname}" \ 133 && ${my_test_fx} ${flags} "${pname}" \
68 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done 134 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
69 flags=1 ; ndsc=0 ; dsc=() 135 flags=1 ; ndsc=0 ; dsc=( )
70 pname=${row#"@patch "} 136 pname=${row#"@patch "}
71 ;; 137 ;;
72 @ver\ *) 138 @ver\ *)
73 if mysql_check_version_range "${row#"@ver "}" "${my_ver}" ; then 139 if mysql_check_version_range "${row#"@ver "}" "${my_ver}" ; then
74 flags=$(( $flags | 4 )) 140 flags=$(( ${flags} | 4 ))
75 else 141 else
76 flags=$(( $flags | 2 )) 142 flags=$(( ${flags} | 2 ))
143 fi
144 ;;
145 @pn\ *)
146 if [[ ${row#"@pn "} == "${PN}" ]] ; then
147 flags=$(( ${flags} | 16 ))
148 else
149 flags=$(( ${flags} | 8 ))
77 fi 150 fi
78 ;; 151 ;;
79 # @use\ *) ;; 152 # @use\ *) ;;
80 @@\ *) 153 @@\ *)
81 dsc[$ndsc]="${row#"@@ "}" 154 dsc[$ndsc]="${row#"@@ "}"
82 (( ++ndsc )) 155 (( ++ndsc ))
83 ;; 156 ;;
84 esac 157 esac
85 done < "${index_file}" 158 done < "${index_file}"
159
86 ${my_test_fx} $flags "${pname}" \ 160 ${my_test_fx} ${flags} "${pname}" \
87 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done 161 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
88} 162}
89 163
90
91# void mysql_init_vars()
92# 164#
93# initialize global variables
94# 2005-11-19 <vivo at gentoo.org>
95mysql_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>
146mysql_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? 165# Is $2 (defaults to $MYSQL_VERSION_ID) at least version $1?
157# (nice) idea from versionator.eclass 166# (nice) idea from versionator.eclass
167#
158mysql_version_is_at_least() { 168mysql_version_is_at_least() {
159 local want_s=$(stripdots "$1") have_s=$( stripdots "${2:-${MYSQL_VERSION_ID}}") 169 local want_s=$(stripdots "$1") have_s=$(stripdots "${2:-${MYSQL_VERSION_ID}}")
160 [[ -z "${want_s}" ]] && die "mysql_version_is_at_least missing value" 170 [[ -z "${want_s}" ]] && die "mysql_version_is_at_least missing value to check"
161 [[ ${want_s} -le ${have_s} ]] && return 0 || return 1 171 [[ ${want_s} -le ${have_s} ]] && return 0 || return 1
162} 172}
163 173
164# void mysql_lib_symlinks()
165# 174#
166# To be called on the live filesystem, reassign symlinks to each mysql 175# To be called on the live filesystem, reassigning symlinks of each MySQL
167# library to the best version avaiable 176# library to the best version available.
168# 2005-12-30 <vivo at gentoo.org> 177#
169mysql_lib_symlinks() { 178mysql_lib_symlinks() {
170 local d dirlist maxdots soname sonameln 179 local d dirlist maxdots soname sonameln reldir
171 pushd "${ROOT}/usr/$(get_libdir)/" 180 reldir="${1}"
181 pushd "${reldir}/usr/$(get_libdir)" &> /dev/null
172 # dirlist must contain the less significative directory left 182 # dirlist must contain the less significative directory left
173 dirlist="mysql $(ls -d mysql-[[:digit:]][[:digit:]][[:digit:]] | sort)" 183 dirlist="mysql"
174 184
175 # waste some time in removing and recreating symlinks 185 # waste some time in removing and recreating symlinks
176 for d in $dirlist ; do 186 for d in $dirlist ; do
177 for soname in $(find "${d}" -name "*.so*" -and -not -type "l") ; do 187 for soname in $( find "${d}" -name "*.so*" -and -not -type "l" 2>/dev/null ) ; do
178 # maxdot is a limit versus infinite loop 188 # maxdot is a limit versus infinite loop
179 maxdots=0 189 maxdots=0
180 sonameln=${soname##*/} 190 sonameln=${soname##*/}
181 # loop in version of the library to link it, similar to the 191 # loop in version of the library to link it, similar to how
182 # libtool work 192 # libtool works
183 while [[ ${sonameln:(-3)} != '.so' ]] && [[ ${maxdots} -lt 6 ]] 193 while [[ ${sonameln:0-3} != '.so' ]] && [[ ${maxdots} -lt 6 ]] ; do
184 do
185 rm -f "${sonameln}" 194 rm -f "${sonameln}"
186 ln -s "${soname}" "${sonameln}" 195 ln -s "${soname}" "${sonameln}"
187 (( ++maxdots )) 196 (( ++maxdots ))
188 sonameln="${sonameln%.*}" 197 sonameln="${sonameln%.*}"
189 done 198 done
190 rm -f "${sonameln}" 199 rm -f "${sonameln}"
191 ln -s "${soname}" "${sonameln}" 200 ln -s "${soname}" "${sonameln}"
192 done 201 done
193 done 202 done
194 popd 203 popd &> /dev/null
195} 204}

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.20

  ViewVC Help
Powered by ViewVC 1.1.20