mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-10 06:26:57 +02:00
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:
parent
9794ab32b1
commit
19caadc8c9
13
common.sh
13
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.
|
||||
|
Loading…
Reference in New Issue
Block a user