blob: ba5f06186d2ddf25d6d149b7c54b46631eb52502 (
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
|
#!/usr/bin/env bash
. libremessages
usage() {
print "Usage: %s [-h] PKGNAME [PKGVER]" "${0##*/}" "${0##*/}"
print 'Detect iv a given package (version) is already in the repos'
echo
prose "If a version is specified, it assumedx that you want a greater or
equal version."
echo
prose "Example usage:"
print " $ %s 'pcre' '20'" "${0##*/}"
echo
print "Exit status:"
print " 0: The package is built"
print " 1: The package has not built"
print " >1: There was an error"
}
while getopts 'h' arg; do
case $arg in
h) usage; exit 0 ;;
*) usage >&2; exit 2 ;;
esac
done
if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then
usage >&2
exit 2
fi
pkg=${1}
ver=${2:-0}
pver=$(LC_ALL=C pacman -Sddp --print-format '%v' "${pkg}" 2>/dev/null)
# if pacman fails or returns nothing
r=$?
result=$(vercmp "${pver}" "${ver}")
# result:
# -1 : pver < ver
# 0 : pver = ver
# 1 : pver > ver
if [[ $result -ge 0 ]] && [[ $r -eq 0 ]]; then
exit 0
else
exit 1
fi
|