source: common/func_check_version.sh@ 80f0ea1

experimental
Last change on this file since 80f0ea1 was 80f0ea1, checked in by George Boudreau <georgeb@…>, 18 years ago

Added PATH variable to generated Makefile. /usr/sbin may not be in builders PATH

  • 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 # This saves us the save/restore hassle of the system IFS value
31 local IFS
32
33 write_error_and_die() {
34 echo -e "\n\t\t$TXT version -->${tst_version}<-- is too old.
35 This script requires ${ref_version} or greater\n"
36 exit 1
37 }
38
39 echo -ne "${TXT}${dotSTR:${#TXT}}${L_arrow}${BOLD}${tst_version}${OFF}${R_arrow}"
40
41# echo -ne "$TXT:\t${L_arrow}${BOLD}${tst_version}${OFF}${R_arrow}"
42 IFS=".-(p" # Split up w.x.y.z as well as w.x.y-rc (catch release candidates)
43 set -- $ref_version # set postional parameters to minimum ver values
44 ref_major=$1; ref_minor=$2; ref_revision=$3
45 #
46 set -- $tst_version # Set postional parameters to test version values
47 major=$1; minor=$2; revision=$3
48 #
49 # Compare against minimum acceptable version..
50 (( major > ref_major )) && echo " ..${GREEN}OK${OFF}" && return
51 (( major < ref_major )) && write_error_and_die
52 # major=ref_major
53 (( minor < ref_minor )) && write_error_and_die
54 (( minor > ref_minor )) && echo " ..${GREEN}OK${OFF}" && return
55 # minor=ref_minor
56 (( revision >= ref_revision )) && echo " ..${GREEN}OK${OFF}" && return
57
58 # oops.. write error msg and die
59 write_error_and_die
60}
61
Note: See TracBrowser for help on using the repository browser.