From 19caadc8c931825bd1d1547ae6835e6820fc7b5f Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Tue, 6 Aug 2013 13:50:17 -0400 Subject: [PATCH] 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. :) --- common.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/common.sh b/common.sh index e49316943d..fb0d2f753c 100644 --- a/common.sh +++ b/common.sh @@ -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.