-
Notifications
You must be signed in to change notification settings - Fork 2
/
version.chevre
100 lines (83 loc) · 1.47 KB
/
version.chevre
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
#!/bin/bash
equal()
{
if [[ "$2" != "$3" ]]; then
echo "$1 version $2 is not equal to $3."
fi
}
first()
{
echo "$1"
}
major()
{
echo "$1" | tr . ' ' | map first
}
equal_major()
{
if [[ "$(major "$2")" != "$3" ]]; then
echo "$1 major version $(major "$2") is not equal to $3."
fi
}
second()
{
echo "$2"
}
minor()
{
echo "$1" | tr . ' ' | map second
}
equal_minor()
{
if [ "$(minor "$2")" != "$3" ]; then
echo "$1 minor version $(minor "$2") is not equal to $3."
fi
}
versions()
{
echo "$2"
echo "$3"
}
minimum()
{
if [[ "$(versions "$@" | sort -V | head -n 1)" != "$3" ]]; then
echo "$1 version $2 is less than minimum version $3."
fi
}
maximum()
{
if [[ "$(versions "$@" | sort -V | head -n 1)" = "$3" ]]; then
echo "$1 version $2 is greater than or equal to maximum version $3."
fi
}
compare()
{
local comparison="$1"
shift
case $comparison in
version) equal "$@";;
major-version) equal_major "$@";;
minor-version) equal_minor "$@";;
min-version) minimum "$@";;
max-version) maximum "$@";;
esac
}
get_version()
{
pkg-config --modversion "$1"
}
package_version()
{
echo "$(echo "$2" | jq -r .key) $1 $(get_version "$1") $(echo "$2" | jq -r .value)" | map compare
}
get_package()
{
echo "$1" | jq -c ".value | to_entries[]" | map package_version "$(echo "$1" | jq -r .key)"
}
exit_on_error()
{
if [[ -n "$(cat)" ]]; then
exit 1
fi
}
echo "$@" | jq -c . | not is_null | jq -c "to_entries[]" | map get_package | tee /dev/stderr | exit_on_error