diff options
Diffstat (limited to 'src/is_built')
-rwxr-xr-x | src/is_built | 45 |
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 |