mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
dist/tools/has_minimal_version: add tool to check minimal version
usage: has_minimal_version.sh <version> <minimal_version> [toolname] Checks that version >= minimal_version Version format MAJOR.MINOR.PATCH ex 3.1.4
This commit is contained in:
parent
0c14681a3e
commit
a3c7d26a7d
33
dist/tools/has_minimal_version/has_minimal_version.sh
vendored
Executable file
33
dist/tools/has_minimal_version/has_minimal_version.sh
vendored
Executable file
@ -0,0 +1,33 @@
|
||||
#! /bin/bash
|
||||
#
|
||||
# usage: has_minimal_version.sh <version> <minimal_version> [toolname]
|
||||
# Checks that version >= minimal_version
|
||||
# Version format MAJOR.MINOR.PATCH ex 3.1.4
|
||||
|
||||
# Adapted from https://stackoverflow.com/a/24067243 to have >=
|
||||
# Checking versions with '-rcX' does not work properly due to the usage of
|
||||
# `sort -V`.
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
echo "usage: ${0} <version> <minimal_version> [toolname]" >&2
|
||||
echo " Checks that version >= minimal_version" >&2
|
||||
echo " Version format MAJOR.MINOR.PATCH ex 3.1.4" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
readonly TOOLVERSION="${1}"
|
||||
readonly MINVERSION="${2}"
|
||||
readonly TOOLNAME="${3}"
|
||||
|
||||
if [ "${TOOLNAME}" != "" ]; then
|
||||
readonly TOOLSTR="${TOOLNAME} "
|
||||
else
|
||||
readonly TOOLSTR=""
|
||||
fi
|
||||
|
||||
|
||||
HIGHEST=$(printf "%s\n%s\n" "${TOOLVERSION}" "${MINVERSION}" | sort -rV | head -n 1)
|
||||
test "${HIGHEST}" = "${TOOLVERSION}" && exit 0
|
||||
|
||||
printf "\nInvalid version, found %s%s, minimal required is %s\n\n" "${TOOLSTR}" "${TOOLVERSION}" "${MINVERSION}" >&2
|
||||
exit 1
|
Loading…
Reference in New Issue
Block a user