1 | # $Id$
|
---|
2 |
|
---|
3 | check_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
|
---|
21 | inline_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 | # This saves us the save/restore hassle of the system IFS value
|
---|
31 | local IFS
|
---|
32 |
|
---|
33 | # if echo $ref_version | grep [[:alpha:]] 2>&1 >/dev/null ||
|
---|
34 | # echo $tst_version | grep [[:alpha:]] 2>&1 >/dev/null ;then
|
---|
35 | # echo "Cannot test for text, 0.0.0a, version types, assuming 'success' "
|
---|
36 | # return
|
---|
37 | # fi
|
---|
38 |
|
---|
39 | write_error_and_die() {
|
---|
40 | echo -e "\n\t\t$TXT version -->${tst_version}<-- is too old.
|
---|
41 | This script requires ${ref_version} or greater\n"
|
---|
42 | exit 1
|
---|
43 | }
|
---|
44 |
|
---|
45 | echo -ne "$TXT:\t${L_arrow}${BOLD}${tst_version}${OFF}${R_arrow}"
|
---|
46 | IFS=".-(" # Split up w.x.y.z as well as w.x.y-rc (catch release candidates)
|
---|
47 | set -- $ref_version # set postional parameters to minimum ver values
|
---|
48 | ref_major=$1; ref_minor=$2; ref_revision=$3
|
---|
49 | #
|
---|
50 | set -- $tst_version # Set postional parameters to test version values
|
---|
51 | major=$1; minor=$2; revision=$3
|
---|
52 | #
|
---|
53 | # Compare against minimum acceptable version..
|
---|
54 | (( major > ref_major )) && echo " ..OK" && return
|
---|
55 | (( major < ref_major )) && write_error_and_die
|
---|
56 | # major=ref_major
|
---|
57 | (( minor < ref_minor )) && write_error_and_die
|
---|
58 | (( minor > ref_minor )) && echo " ..OK" && return
|
---|
59 | # minor=ref_minor
|
---|
60 | (( revision >= ref_revision )) && echo " ..OK" && return
|
---|
61 |
|
---|
62 | # oops.. write error msg and die
|
---|
63 | write_error_and_die
|
---|
64 | }
|
---|
65 |
|
---|