feat(common): Add simple version comparison function.

Relies on sort for version comparison which should generally be good
enough. Not a proper semver tool but good enough for dirty scripts. :)
This commit is contained in:
Michael Marineau 2013-08-06 13:50:17 -04:00
parent 9794ab32b1
commit 19caadc8c9

View File

@ -159,6 +159,19 @@ die_notrace() {
exit 1
}
# Simple version comparison routine
# Note: not a true semver comparison and build revisions are ignored
cmp_ver() {
local rev a="${2%%+*}" b="${3%%+*}"
case "$1" in
le) rev="" ;;
ge) rev="-R" ;;
*) die "Invalid operator $1" ;;
esac
printf '%s\n%s\n' "$a" "$b" | sort --version-sort --check=quiet $rev
return $?
}
# Directory locations inside the dev chroot; try the new default,
# falling back to user specific paths if the upgrade has yet to
# happen.