source: common/func_check_version.sh@ 1b9148c

experimental
Last change on this file since 1b9148c was 1b9148c, checked in by George Boudreau <georgeb@…>, 19 years ago

inital creation of func_ICA.sh & func_check_version.sh

  • Property mode set to 100644
File size: 1.9 KB
Line 
1# $Id$
2
3check_version() {
4: <<inline_doc
5 Tests for a minimum version level. Compares to version numbers and forces an
6 exit if minimum level not met.
7 NOTE: This test will fail on versions containing alpha chars. ie. jpeg 6b
8
9 usage: check_version "2.6.2" "`uname -r`" "KERNEL"
10 check_version "3.0" "$BASH_VERSION" "BASH"
11 check_version "3.0" "`gcc -dumpversion`" "GCC"
12
13 input vars: $1=min acceptable version
14 $2=version to check
15 $3=app name
16 externals: --
17 modifies: --
18 returns: nothing
19 on error: write text to console and dies
20 on success: write text to console and returns
21inline_doc
22
23 declare -i major minor revision change
24 declare -i ref_major ref_minor ref_revision ref_change
25
26 ref_version=$1
27 tst_version=$2
28 TXT=$3
29
30 if echo $ref_version | grep [[:alpha:]] 2>&1 >/dev/null ||
31 echo $tst_version | grep [[:alpha:]] 2>&1 >/dev/null ;then
32 echo "Cannot test for text, 0.0.0a, version types, assuming 'success' "
33 return
34 fi
35
36 write_error_and_die() {
37 echo -e "\n\t\t$TXT version -->${tst_version}<-- is too old.
38 This script requires ${ref_version} or greater\n"
39 exit 1
40 }
41
42 echo -ne "$TXT:\t<${tst_version}>"
43 IFS=".-(" # Split up w.x.y.z as well as w.x.y-rc (catch release candidates)
44 set -- $ref_version # set postional parameters to minimum ver values
45 ref_major=$1; ref_minor=$2; ref_revision=$3
46 #
47 set -- $tst_version # Set postional parameters to test version values
48 major=$1; minor=$2; revision=$3
49 #
50 # Compare against minimum acceptable version..
51 (( major > ref_major )) && echo " ..OK" && return
52 (( major < ref_major )) && write_error_and_die
53 # major=ref_major
54 (( minor < ref_minor )) && write_error_and_die
55 (( minor > ref_minor )) && echo " ..OK" && return
56 # minor=ref_minor
57 (( revision >= ref_revision )) && echo " ..OK" && return
58
59 # oops.. write error msg and die
60 write_error_and_die
61}
62
Note: See TracBrowser for help on using the repository browser.