possibilité de spécifier la version minimum attendue pour ulib

This commit is contained in:
Jephté Clain 2014-09-15 07:53:08 +04:00
parent d06d8cf7a4
commit b591137e7f
1 changed files with 80 additions and 0 deletions

View File

@ -106,3 +106,83 @@ function ulibsync() {
local __CPNOVCS_RSYNC_ARGS=(-q --delete) local __CPNOVCS_RSYNC_ARGS=(-q --delete)
[ "$destdir/ulib" != "$ULIBDIR" ] && cpdirnovcs "$ULIBDIR" "$destdir/ulib" [ "$destdir/ulib" != "$ULIBDIR" ] && cpdirnovcs "$ULIBDIR" "$destdir/ulib"
} }
function __ulibver_parse_version() {
# copie verbatim de la fonction parseversion() du script ulib dans nutools
if [ -n "$2" ]; then
local version="${1:-${version:-000000000}}"
local major minor patch pversion
else
version="${1:-${version:-000000000}}"
fi
while [ ${#version} -lt 9 ]; do version="0$version"; done
major="${version:0:3}"; while [ ${#major} -gt 1 -a "${major#0}" != "$major" ]; do major="${major#0}"; done
minor="${version:3:3}"; while [ ${#minor} -gt 1 -a "${minor#0}" != "$minor" ]; do minor="${minor#0}"; done
patch="${version:6:3}"; while [ ${#patch} -gt 1 -a "${patch#0}" != "$patch" ]; do patch="${patch#0}"; done
pversion="$major.$minor.$patch"
[ -n "$2" ] && eval "${2}version=\$version; ${2}major=\$major; ${2}minor=\$minor; ${2}patch=\$patch; ${2}pversion=\$pversion"
}
function __ulibver_format_version() {
# copie verbatim de la fonction formatversion() du script ulib dans nutools
local major="${1:-${major:-0}}" minor="${2:-${minor:-0}}" patch="${3:-${patch:-0}}"
while [ ${#major} -lt 3 ]; do major="0$major"; done
while [ ${#minor} -lt 3 ]; do minor="0$minor"; done
while [ ${#patch} -lt 3 ]; do patch="0$patch"; done
echo "$major$minor$patch"
}
function __ulibver_parse_pversion() {
# copie verbatim de la fonction parsepversion() du script ulib dans nutools
local v M m p
if [[ "$1" == *.* ]]; then
local v="$1"; shift
local M=0 m=0 p=0
if [[ "$v" == *.* ]]; then
p="${v##*.}"; v="${v%.*}"
if [[ "$v" == *.* ]]; then
m="${v##*.}"; v="${v%.*}"
if [[ "$v" == *.* ]]; then M="${v##*.}"; v="${v%.*}"
else M="$v"
fi
else m="$v"
fi
else p="$v"
fi
__ulibver_parse_version "$(__ulibver_format_version "$M" "$m" "$p")" "$@"
else
__ulibver_parse_version "$@"
fi
}
function ulibver() {
# Vérifier que la version actuelle de ulib est au moins à la version $1
# (inclue) et éventuellement au plus à la version $2 (exclue)
[ -f "$ULIBDIR/.ulibver" ] || return 1
local version=000000000 major minor patch pversion
__ulibver_parse_version "$(<"$ULIBDIR/.ulibver")"
if [ -n "$1" ]; then
local minversion=000000000 minmajor minminor minpatch minpversion
__ulibver_parse_pversion "$1" min
if [ "$major" -lt "$minmajor" ]; then
return 1
elif [ "$major" -eq "$minmajor" ]; then
if [ "$minor" -lt "$minminor" ]; then
return 1
elif [ "$minor" -eq "$minminor" ]; then
[ "$patch" -lt "$minpatch" ] && return 1
fi
fi
fi
if [ -n "$2" ]; then
local maxversion=000000000 maxmajor maxmaxor maxpatch maxpversion
__ulibver_parse_pversion "$2" max
if [ "$major" -gt "$maxmajor" ]; then
return 1
elif [ "$major" -eq "$maxmajor" ]; then
if [ "$minor" -gt "$maxminor" ]; then
return 1
elif [ "$minor" -eq "$maxminor" ]; then
[ "$patch" -ge "$maxpatch" ] && return 1
fi
fi
fi
return 0
}