# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id: mysql.eselect,v 1.12 2006/02/15 02:34:44 vivo Exp $
+# $Id: mysql.eselect,v 1.13 2007/01/02 11:37:13 vivo Exp $
-DESCRIPTION="Manage the /usr/lib/*mysql* links"
+[[ -d "${ROOT}/lib64" ]] && LIBDIR="lib64" || LIBDIR="lib"
+
+DESCRIPTION="Manage the /usr/${LIBDIR}/*mysql* links"
MAINTAINER="vivo@gentoo.org"
-SVN_DATE='$Date: 2006/02/15 02:34:44 $'
+SVN_DATE='$Date: 2007/01/02 11:37:13 $'
VERSION=$(svn_date_to_version "${SVN_DATE}" )
MYSQL_SYMLINK_CHECKDIR="${ROOT}/usr/bin"
ERR_NOT_FOUND="(not-found)"
#
# $1 - version to transform
function version4human() {
- local major=${1:0:1}
- local minor=${1:1:2}
- [[ ${minor:0:1} == "0" ]] && minor=${minor:1:1}
- echo "${major}.${minor}.x"
+ echo "${1//_/.}"
}
# return a integer version
# $1 - version to transform
function version4bash() {
- local minor=${1#*.}
- minor=${minor%%.x*}
- [[ ${#minor} -lt 10 ]] && minor="0${minor}"
- echo "${1%%.*}${minor}"
+ echo "${1//./_}"
}
# Return the versions currently installed
find_versions() {
local versions list
- # "eselect mysql set 1" will always set the best version
- list=$( ls ${MYSQL_SYMLINK_CHECKDIR}/perror-* 2>/dev/null )
+ # TODO: "eselect mysql set 1" will always set the best version
+ list=$( mysql_make_file_list ${MYSQL_SYMLINK_CHECKDIR}/perror 2>/dev/null )
for x in ${list} ; do
versions=( $( version4human ${x##*-}) ${versions[@]} )
done
return ${ret}
}
-# another one inherited from versionator.eclass (version_sort)
# THERE IS A COPY OF THIS ONE IN MYSQL_FX.ECLASS, keep the two synced
mysql_make_file_list() {
- local items= left=0
- items=$( ls -d ${1}-[[:digit:]][[:digit:]][[:digit:]] )
-
- while [[ ${left} -lt ${#items[@]} ]] ; do
- local lowest_idx=${left}
- local idx=$(( ${lowest_idx} + 1 ))
- while [[ ${idx} -lt ${#items[@]} ]] ; do
- [[ "${items[${lowest_idx}]}" > "${items[${idx}]}" ]] \
- && lowest_idx=${idx}
- idx=$(( ${idx} + 1 ))
- done
- local tmp=${items[${lowest_idx}]}
- items[${lowest_idx}]=${items[${left}]}
- items[${left}]=${tmp}
- left=$(( ${left} + 1 ))
- done
- echo ${items[@]}
+ local base="${1}-"
+ local items
+ local ret
+ echo $( for i in $( ls -d ${1}-[[:digit:]]_[[:digit:]]{,[[:digit:]]}_[[:digit:]]{,[[:digit:]]} 2>/dev/null )
+ do
+ n=${i#${base}}
+ n=( ${n//_/ } )
+ echo "$(( ${n[0]} * 10000 + 100 + ${n[1]} * 100 + 100 + ${n[2]} ))$i"
+ done | sort | cut -c 6- )
}
# THERE IS A COPY OF THIS ONE IN ESELECT-MYSQL, keep the two synced
mysql_choose_better_version() {
- local items= better="" i
- items="$( ls -d ${1}-[[:digit:]][[:digit:]][[:digit:]] )"
- for i in ${items} ; do
- if [[ "${i}" > "${better}" ]] ; then
- better="${i}"
- fi
- done
- echo "${better}"
+ local better=$(mysql_make_file_list ${1})
+ echo ${better##* }
}
# void mysql_lib_symlinks()
# THERE IS A COPY OF THIS ONE IN MYSQL_FX.ECLASS, keep the two synced
mysql_lib_symlinks() {
local d dirlist maxdots soname sonameln other better
- pushd "${ROOT}/usr/lib" &> /dev/null
+ pushd "${ROOT}/usr/${LIBDIR}" &> /dev/null
# dirlist must contain the less significative directory left
dirlist="mysql $( mysql_make_file_list mysql )"
# waste some time in removing and recreating symlinks
for d in $dirlist ; do
- for soname
- in $( find "${d}" -name "*.so*" -and -not -type "l" 2>/dev/null)
+ for soname in $( find "${d}" -name "*.so*" -and -not -type "l" 2>/dev/null )
do
# maxdot is a limit versus infinite loop
maxdots=0
popd &> /dev/null
# "include"s and "mysql_config", needed to compile other sw
- for other in "/usr/lib/mysql" "/usr/include/mysql" "/usr/bin/mysql_config" ; do
+ for other in "/usr/${LIBDIR}/mysql" "/usr/include/mysql" "/usr/bin/mysql_config" ; do
pushd "${ROOT}${other%/*}" &> /dev/null
better=$( mysql_choose_better_version "${other##*/}" )
if ! [[ -d "${other##*/}" ]] ; then
link=$(readlink ${MYSQL_SYMLINK_CHECKDIR}/perror)
version=${link##*-}
- if ! is_number "${version}" || [[ "${version}" == "" ]] ; then
+ if ! is_number "${version//_/}" || [[ "${version}" == "" ]] ; then
version="${ERR_UNSET}"
echo "${version}"
else
set_current_version() {
local version=${1}
- is_number "${version}" || die -q "No usable version: ${version}"
+ is_number "${version//_/}" || die -q "No usable version: ${version}"
local CWD=$(pwd)
local lastdir dir linkname
local list=$(< $ROOT/var/lib/eselect/mysql/mysql-${version}.filelist )
- # perform a check on the entire file lis
+ # perform a check on the entire file list
for filename in $list ; do
dir="${ROOT}/$(dirname "${filename}")"
if [[ "${dir}" != "${lastdir}" ]] ; then
remove_current_version() {
local version=${1}
- is_number "${version}" || die -q "No usable version: ${version}"
+ is_number "${version//_/}" || die -q "No usable version: ${version}"
local CWD=$(pwd)
local lastdir dir linkname
local list=$(< $ROOT/var/lib/eselect/mysql/mysql-${version}.filelist )