From 7887f99d234b4c88c3833c294869e307d2757787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joshua=20Ismael=20Haase=20Hern=C3=A1ndez?= Date: Wed, 25 Jan 2012 12:12:21 -0600 Subject: is_built: faster (from fauno's branch) updated calls to is_built --- is_built | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'is_built') diff --git a/is_built b/is_built index 60f24e9..2a90d65 100755 --- a/is_built +++ b/is_built @@ -2,9 +2,10 @@ usage() { echo "$0 " echo - echo "Detect is a package is installed or in a database" + echo "Detect if a given package version is already in repos" + echo "Assuming you want greater or equal" echo - echo "Example usage: is_built \"pcre>=20\"" + echo "Example usage: is_built 'pcre' '20'" } while getopts 'h' arg; do @@ -14,12 +15,24 @@ while getopts 'h' arg; do esac done -# Checks for package, if -T returns non-zero output, egrep will return 0 -# because it finds it, so we negate the value to say it's not built. -# -Sp works backwards, it will print output only when the package already -# exists +set -x -!(sudo pacman -T "$1" | egrep "*" >/dev/null) || \ -sudo pacman -Sp "$1" --print-format "%n-%v" 2>/dev/null | egrep "*" >/dev/null +ver=${2} +pkg=${1} +pver=$(LC_ALL=C pacman -Sdp --print-format "%v" "${pkg}" 2>/dev/null) -exit $? +# if pacman fails or returns nothing +r=$? +[ "${pver}" = " there is nothing to do" ] && r=1 + +result=$(vercmp "${pver}" "${ver}") + +# if vercmp > 1 means our version is bigger +if [ ${result} -ge 0 -a ${r} -eq 0 ]; then + exit 0 +else + exit 1 +fi + +# just in case +exit 1 -- cgit v1.2.2