summaryrefslogtreecommitdiff
path: root/src/is_built
diff options
context:
space:
mode:
Diffstat (limited to 'src/is_built')
-rwxr-xr-xsrc/is_built52
1 files changed, 28 insertions, 24 deletions
diff --git a/src/is_built b/src/is_built
index d8a0eb1..22c67a7 100755
--- a/src/is_built
+++ b/src/is_built
@@ -38,31 +38,35 @@ usage() {
print " >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
+main() {
+ 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}
+ pkg=${1}
+ ver=${2:-0}
-r=0
-pver=$(LC_ALL=C pacman -Sddp --print-format '%v' "${pkg}" 2>/dev/null) || r=$?
+ r=0
+ pver=$(LC_ALL=C pacman -Sddp --print-format '%v' "${pkg}" 2>/dev/null) || r=$?
-result=$(vercmp "${pver}" "${ver}")
-# result:
-# -1 : pver < ver
-# 0 : pver = ver
-# 1 : pver > ver
+ 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
+ if [[ $result -ge 0 ]] && [[ $r -eq 0 ]]; then
+ exit 0
+ else
+ exit 1
+ fi
+}
+
+main "$@"