summaryrefslogtreecommitdiff
path: root/tests/version.inc.sh
blob: 4155296941c858658a7136c63cbd79a7a30e71ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Version comparison shell functions
#
###############################################################################
#
# Copyright (C) 2005, 2013 Red Hat, Inc. All Rights Reserved.
# Written by David Howells (dhowells@redhat.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
###############################################################################

###############################################################################
#
# compare version numbers to see if the first is less (older) than the second
#
###############################################################################
function version_less_than ()
{
    a=$1
    b=$2

    if [ "$a" = "$b" ]
    then
	return 1
    fi

    # grab the leaders
    a_version=${a%%-*} a_release=${a#*-}
    b_version=${b%%-*} b_release=${b#*-}

    if [ "$a_version" = "$b_version" ]
    then
	case "$a_release" in
	    rc[0-9]*)
		case "$b_release" in
		    rc[0-9]*)
			__version_less_than_dot "${a_release#rc}" "${b_release#rc}"
			return $?
			;;
		    *)
			return 0;
			;;
		esac
		;;
	esac

	case "$b_release" in
	    rc[0-9]*)
		return 1;
		;;
	esac

	if [ "$a_version" = "$a" -o "$b_version" = "$b" ]
	then
	    if [ "$a_version" = "$b_version" ]
	    then
		[ "$a_version" = "$a" ]
	    else
		__version_less_than_dot "$a_version" "$b_version"
	    fi
	fi
    else
	__version_less_than_dot "$a_version" "$b_version"
    fi
}

function __version_less_than_dot ()
{
    a=$1
    b=$2

    if [ "$a" = "$b" ]
    then
	return 1
    fi

    # grab the leaders
    x=${a%%.*}
    y=${b%%.*}

    if [ "$x" = "$a" -o "$y" = "$b" ]
    then
	if [ "$x" = "$y" ]
	then
	    [ "$x" = "$a" ]
	else
	    expr "$x" \< "$y" >/dev/null
	fi
    elif [ "$x" = "$y" ]
    then
	__version_less_than_dot "${a#*.}" "${b#*.}"
    else
	expr "$x" \< "$y" >/dev/null
    fi
}

###############################################################################
#
# Return true if the keyutils package being tested is older than the given
# version.
#
###############################################################################
function keyutils_older_than ()
{
    version_less_than $KEYUTILSVER $1
}

###############################################################################
#
# Return true if the keyutils package being tested is at or later than the
# given version.
#
###############################################################################
function keyutils_at_or_later_than ()
{
    ! keyutils_older_than $1
}

###############################################################################
#
# Return true if the keyutils package being tested is newer than the given
# version.
#
###############################################################################
function keyutils_newer_than ()
{
    version_less_than $1 $KEYUTILSVER
}

###############################################################################
#
# Return true if the keyutils package being tested is at or older than the
# given version.
#
###############################################################################
function keyutils_at_or_older_than ()
{
    ! keyutils_newer_than $1
}

###############################################################################
#
# Return true if the kernel being tested is older than the given version.
#
###############################################################################
function kernel_older_than ()
{
    version_less_than $KERNELVER $1
}

###############################################################################
#
# Return true if the kernel being tested is at or later than the given version.
#
###############################################################################
function kernel_at_or_later_than ()
{
    ! kernel_older_than $1
}