source: ipk/ipkg-utils-050831/ipkg-compare-versions.sh@ 6285

Last change on this file since 6285 was 4890, checked in by obi, 15 years ago

[ipk] fix executable rights

  • Property svn:executable set to *
File size: 1.6 KB
Line 
1#!/bin/sh
2set -e
3
4# This is a little experiment to see how expensive it would be to
5# compare versions in a shell script. This script is not done yet
6# and the nasiest part is still left undone, (the fact that in Debian
7# versions all letters compare less than all non-letters).
8#
9# It looks to me like version comprehension might be the feature that pushes
10# ipkg from /bin/sh to compiled C code...
11
12if [ $# -lt 3 ]; then
13 echo "
14usage: ipkg-compare-versions v1 op v2
15 where op in (<<, <=, =, >=, >>)
16Return value is 0 if v1 op v2 is satisfied, 1 otherwise"
17 exit 2
18fi
19
20v1=$1
21op=$2
22v2=$3
23
24# Debian has a little historical problem with operators...
25may_be_equal=0
26case $op in
27'>>')
28 op="-gt"
29;;
30'<<')
31 op="-lt"
32;;
33'>'|'>=')
34 op="-gt"
35 may_be_equal=1
36;;
37'<'|'<=')
38 op="-lt"
39 may_be_equal=1
40;;
41'=')
42 may_be_equal=1
43;;
44*)
45 echo "ipkg_compare_versions: Invalid operator \`$op' valid operators are (<<, <=, =, >=, >>)"
46 exit 1
47;;
48esac
49
50if [ $may_be_equal == 1 -a $v1 == $v2 ]; then
51 exit 0;
52elif [ $op == '=' ]; then
53 exit 1;
54fi
55
56epoch1=`echo $v1 | sed -ne 's/:.*//p'`
57v1=`echo $v1 | sed -e 's/^[^:]*://'`
58epoch2=`echo $v2 | sed -ne 's/:.*//p'`
59v2=`echo $v2 | sed -e 's/^[^:]*://'`
60
61upstream1=`echo $v1 | sed -e '/-/s/\(.*\)-.*/\1/'`
62debian_rev1=`echo $v1 | sed -ne 's/.*-//p'`
63upstream2=`echo $v2 | sed -e '/-/s/\(.*\)-.*/\1/'`
64debian_rev2=`echo $v2 | sed -ne 's/.*-//p'`
65
66echo "$epoch1:$upstream1-$debian_rev1 $op $epoch2:$upstream2-$debian_rev2"
67
68exit 3
69
70[ -z $epoch1 ] && epoch1="0"
71[ -z $epoch2 ] && epoch2="0"
72
73if [ $epoch1 != $epoch2 ]; then
74 exit `[ $epoch1 $op $epoch2 ]`
75fi
76
77exit 3
Note: See TracBrowser for help on using the repository browser.