2006-03-09 04:38:59 +01:00
|
|
|
# $Id$
|
|
|
|
|
|
|
|
check_version() {
|
|
|
|
: <<inline_doc
|
|
|
|
Tests for a minimum version level. Compares to version numbers and forces an
|
|
|
|
exit if minimum level not met.
|
|
|
|
NOTE: This test will fail on versions containing alpha chars. ie. jpeg 6b
|
|
|
|
|
|
|
|
usage: check_version "2.6.2" "`uname -r`" "KERNEL"
|
|
|
|
check_version "3.0" "$BASH_VERSION" "BASH"
|
|
|
|
check_version "3.0" "`gcc -dumpversion`" "GCC"
|
|
|
|
|
|
|
|
input vars: $1=min acceptable version
|
|
|
|
$2=version to check
|
|
|
|
$3=app name
|
|
|
|
externals: --
|
|
|
|
modifies: --
|
|
|
|
returns: nothing
|
|
|
|
on error: write text to console and dies
|
|
|
|
on success: write text to console and returns
|
|
|
|
inline_doc
|
|
|
|
|
|
|
|
declare -i major minor revision change
|
|
|
|
declare -i ref_major ref_minor ref_revision ref_change
|
|
|
|
|
|
|
|
ref_version=$1
|
|
|
|
tst_version=$2
|
|
|
|
TXT=$3
|
|
|
|
|
2006-03-10 02:44:55 +01:00
|
|
|
# This saves us the save/restore hassle of the system IFS value
|
|
|
|
local IFS
|
|
|
|
|
2006-03-09 04:38:59 +01:00
|
|
|
write_error_and_die() {
|
|
|
|
echo -e "\n\t\t$TXT version -->${tst_version}<-- is too old.
|
|
|
|
This script requires ${ref_version} or greater\n"
|
|
|
|
exit 1
|
|
|
|
}
|
2006-03-15 22:50:40 +01:00
|
|
|
|
2006-09-15 23:19:27 +02:00
|
|
|
echo -ne "${TXT}${dotSTR:${#TXT}}${L_arrow}${BOLD}${tst_version}${OFF}${R_arrow}"
|
|
|
|
|
|
|
|
# echo -ne "$TXT:\t${L_arrow}${BOLD}${tst_version}${OFF}${R_arrow}"
|
2006-09-12 23:31:29 +02:00
|
|
|
IFS=".-(p" # Split up w.x.y.z as well as w.x.y-rc (catch release candidates)
|
2006-03-09 04:38:59 +01:00
|
|
|
set -- $ref_version # set postional parameters to minimum ver values
|
|
|
|
ref_major=$1; ref_minor=$2; ref_revision=$3
|
|
|
|
#
|
|
|
|
set -- $tst_version # Set postional parameters to test version values
|
|
|
|
major=$1; minor=$2; revision=$3
|
|
|
|
#
|
|
|
|
# Compare against minimum acceptable version..
|
2006-09-15 23:19:27 +02:00
|
|
|
(( major > ref_major )) && echo " ..${GREEN}OK${OFF}" && return
|
2006-03-09 04:38:59 +01:00
|
|
|
(( major < ref_major )) && write_error_and_die
|
|
|
|
# major=ref_major
|
|
|
|
(( minor < ref_minor )) && write_error_and_die
|
2006-09-15 23:19:27 +02:00
|
|
|
(( minor > ref_minor )) && echo " ..${GREEN}OK${OFF}" && return
|
2006-03-09 04:38:59 +01:00
|
|
|
# minor=ref_minor
|
2006-09-15 23:19:27 +02:00
|
|
|
(( revision >= ref_revision )) && echo " ..${GREEN}OK${OFF}" && return
|
2006-03-09 04:38:59 +01:00
|
|
|
|
|
|
|
# oops.. write error msg and die
|
|
|
|
write_error_and_die
|
|
|
|
}
|
|
|
|
|