-
Notifications
You must be signed in to change notification settings - Fork 5
/
opkg-compare-versions.sh
executable file
·77 lines (65 loc) · 1.55 KB
/
opkg-compare-versions.sh
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
#!/bin/sh
set -e
# This is a little experiment to see how expensive it would be to
# compare versions in a shell script. This script is not done yet
# and the nasiest part is still left undone, (the fact that in Debian
# versions all letters compare less than all non-letters).
#
# It looks to me like version comprehension might be the feature that pushes
# opkg from /bin/sh to compiled C code...
if [ $# -lt 3 ]; then
echo "
usage: opkg-compare-versions v1 op v2
where op in (<<, <=, =, >=, >>)
Return value is 0 if v1 op v2 is satisfied, 1 otherwise"
exit 2
fi
v1=$1
op=$2
v2=$3
# Debian has a little historical problem with operators...
may_be_equal=0
case $op in
'>>')
op="-gt"
;;
'<<')
op="-lt"
;;
'>'|'>=')
op="-gt"
may_be_equal=1
;;
'<'|'<=')
op="-lt"
may_be_equal=1
;;
'=')
may_be_equal=1
;;
*)
echo "opkg_compare_versions: Invalid operator \`$op' valid operators are (<<, <=, =, >=, >>)"
exit 1
;;
esac
if [ $may_be_equal == 1 -a $v1 == $v2 ]; then
exit 0;
elif [ $op == '=' ]; then
exit 1;
fi
epoch1=`echo $v1 | sed -ne 's/:.*//p'`
v1=`echo $v1 | sed -e 's/^[^:]*://'`
epoch2=`echo $v2 | sed -ne 's/:.*//p'`
v2=`echo $v2 | sed -e 's/^[^:]*://'`
upstream1=`echo $v1 | sed -e '/-/s/\(.*\)-.*/\1/'`
debian_rev1=`echo $v1 | sed -ne 's/.*-//p'`
upstream2=`echo $v2 | sed -e '/-/s/\(.*\)-.*/\1/'`
debian_rev2=`echo $v2 | sed -ne 's/.*-//p'`
echo "$epoch1:$upstream1-$debian_rev1 $op $epoch2:$upstream2-$debian_rev2"
exit 3
[ -z $epoch1 ] && epoch1="0"
[ -z $epoch2 ] && epoch2="0"
if [ $epoch1 != $epoch2 ]; then
exit `[ $epoch1 $op $epoch2 ]`
fi
exit 3