Skip to content

Commit eb4d709

Browse files
authored
ref: use sort -V to check minimum versions (#1553)
1 parent cf794b5 commit eb4d709

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

install/check-minimum-requirements.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@ echo "${_group}Checking minimum requirements ..."
22

33
source "$(dirname $0)/_min-requirements.sh"
44

5-
# Compare dot-separated strings - function below is inspired by https://stackoverflow.com/a/37939589/808368
6-
function ver () { echo "$@" | awk -F. '{ printf("%d%03d%03d", $1,$2,$3); }'; }
5+
# Check the version of $1 is greater than or equal to $2 using sort. Note: versions must be stripped of "v"
6+
function vergte () { printf "%s\n%s" $1 $2 | sort --version-sort --check=quiet --reverse; }
7+
78

8-
DOCKER_VERSION=$(docker version --format '{{.Server.Version}}')
99

10+
DOCKER_VERSION=$(docker version --format '{{.Server.Version}}')
1011
if [[ -z "$DOCKER_VERSION" ]]; then
1112
echo "FAIL: Unable to get docker version, is the docker daemon running?"
1213
exit 1
1314
fi
1415

15-
if [[ "$(ver $DOCKER_VERSION)" -lt "$(ver $MIN_DOCKER_VERSION)" ]]; then
16+
if [[ "$(vergte ${DOCKER_VERSION//v} $MIN_DOCKER_VERSION)" ]]; then
1617
echo "FAIL: Expected minimum docker version to be $MIN_DOCKER_VERSION but found $DOCKER_VERSION"
1718
exit 1
1819
fi
1920
echo "Found Docker version $DOCKER_VERSION"
2021

2122
COMPOSE_VERSION=$($dc_base version --short)
22-
if [[ "$(ver ${COMPOSE_VERSION//v})" -lt "$(ver $MIN_COMPOSE_VERSION)" ]]; then
23+
if [[ "$(vergte ${COMPOSE_VERSION//v} $MIN_COMPOSE_VERSION)" ]]; then
2324
echo "FAIL: Expected minimum $dc_base version to be $MIN_COMPOSE_VERSION but found $COMPOSE_VERSION"
2425
exit 1
2526
fi

0 commit comments

Comments
 (0)