summaryrefslogtreecommitdiff
path: root/src/is_built
blob: 92b44f882038e98610b1c22c43f5306db89f8826 (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
#!/bin/bash

cmd=${0##*/}
usage() {
	echo "Usage: $cmd pkgname pkgver"
	echo
	echo "Detect if a given package version is already in repos"
	echo "Assuming you want greater or equal"
	echo
	echo "Example usage: $cmd 'pcre' '20'"
}

while getopts 'h' arg; do
	case $arg in
		h) usage; exit 0 ;;
		*) usage >&2; exit 1 ;;
	esac
done
if [[ $# != 2 ]]; then
	usage >&2;
	exit 1
fi

pkg=${1}
ver=${2}
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 >= 0 ]] && [[ $r == 0 ]]; then
	exit 0
else
	exit 1
fi