summaryrefslogtreecommitdiff
path: root/src/is_built
diff options
context:
space:
mode:
authorJoshua I. Haase H. (xihh) <hahj87@gmail.com>2012-12-04 21:19:22 -0600
committerJoshua I. Haase H. (xihh) <hahj87@gmail.com>2012-12-04 21:19:22 -0600
commitacc2c792c423c5aa81aa95f0516de7724dba3ab9 (patch)
tree73cacea8eff5cdfd23f42b740597b5498d152509 /src/is_built
parentd11741d73bbf6940c45ee0f2cadea980e9e40785 (diff)
parent098d7430e6447c4658704c3bcf88ea1ed7a5206b (diff)
Merge branch 'master' of gitpar:libretools
Conflicts: librechroot libremakepkg
Diffstat (limited to 'src/is_built')
-rwxr-xr-xsrc/is_built36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/is_built b/src/is_built
new file mode 100755
index 0000000..1fa79d2
--- /dev/null
+++ b/src/is_built
@@ -0,0 +1,36 @@
+#!/bin/bash
+usage() {
+ echo "$0 "
+ echo
+ 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'"
+}
+
+while getopts 'h' arg; do
+ case $arg in
+ h) usage; exit 0 ;;
+ *) usage; exit 1 ;;
+ esac
+done
+
+ver=${2}
+pkg=${1}
+pver=$(LC_ALL=C pacman -Sddp --print-format "%v" "${pkg}" 2>/dev/null)
+
+# 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