summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-05-30 22:49:32 -0600
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-06-05 19:44:27 -0600
commit4f340d30b75b9ae5344bc2ab18a897ff37f89b03 (patch)
treee0685635a20d3c80cb196c7da6740592ab8080ed /src
parent8449ab5e3a57c96ea8a7f88e45cac030be5fe377 (diff)
is_built: touch up
Diffstat (limited to 'src')
-rwxr-xr-xsrc/is_built45
1 files changed, 25 insertions, 20 deletions
diff --git a/src/is_built b/src/is_built
index 1fa79d2..92b44f8 100755
--- a/src/is_built
+++ b/src/is_built
@@ -1,36 +1,41 @@
#!/bin/bash
+
+cmd=${0##*/}
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'"
+ 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; exit 1 ;;
- esac
+ case $arg in
+ h) usage; exit 0 ;;
+ *) usage >&2; exit 1 ;;
+ esac
done
+if [[ $# != 2 ]]; then
+ usage >&2;
+ exit 1
+fi
-ver=${2}
pkg=${1}
-pver=$(LC_ALL=C pacman -Sddp --print-format "%v" "${pkg}" 2>/dev/null)
+ver=${2}
+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}")
+# result:
+# -1 : pver < ver
+# 0 : pver = ver
+# 1 : pver > ver
-# if vercmp > 1 means our version is bigger
-if [ ${result} -ge 0 -a ${r} -eq 0 ]; then
- exit 0
+if [[ $result >= 0 ]] && [[ $r == 0 ]]; then
+ exit 0
else
- exit 1
+ exit 1
fi
-
-# just in case
-exit 1