summaryrefslogtreecommitdiff
path: root/src/is_built
diff options
context:
space:
mode:
Diffstat (limited to 'src/is_built')
-rwxr-xr-xsrc/is_built46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/is_built b/src/is_built
new file mode 100755
index 0000000..80d0719
--- /dev/null
+++ b/src/is_built
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+
+cmd=${0##*/}
+usage() {
+ echo "Usage: $cmd [-h] 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'"
+ echo
+ echo "Exit status:"
+ echo " 0: The package is built"
+ echo " 1: The package has not built"
+ echo " >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