This repository was archived by the owner on Feb 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcheck_docker-compose.sh
More file actions
executable file
·56 lines (46 loc) · 1.53 KB
/
check_docker-compose.sh
File metadata and controls
executable file
·56 lines (46 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# Exit values
# 0 correct version installed
# 3 not installed
# 4 older than required minimum version
# 5 newer than required maximum version
# 6 conflicting installs, both compose @v1 and @v2 are installed
# verify that docker-compose is executable
if [ ! -x "$(command -v docker-compose)" ]; then
exit 3
fi
# verify that the alias works if it exists (will succeed for v1 installs)
if ! docker-compose version > /dev/null 2>&1 ; then
exit 3
fi
# verify that docker compose (v2) is callable
if ! docker compose version > /dev/null 2>&1 ; then
exit 4
fi
# verify that docker compose & docker-compose aren't both installed
if docker-compose version | grep -q '^docker-compose .* [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*' ; then
exit 6
fi
MIN_VERSION_MAJOR=2
MIN_VERSION_MINOR=0
MAX_VERSION_MAJOR=2
MAX_VERSION_MINOR=17
pushd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null
source ../acmlib.sh
popd > /dev/null
require_executable_tmp_dir # docker-compose requires TMPDIR to be mounted without noexec
VERSION="$(docker compose version | sed 's/^.* v\?\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/\1 \2 \3/')"
VERSION_MAJOR="$(echo $VERSION | cut -d' ' -f1)"
VERSION_MINOR="$(echo $VERSION | cut -d' ' -f2)"
# check if major version is an integer
if [[ ! "$VERSION_MAJOR" =~ ^[0-9]+$ ]]; then
exit 4
fi
if [ "$VERSION_MAJOR" -lt "$MIN_VERSION_MAJOR" ] ||
[ "$VERSION_MAJOR" -eq "$MIN_VERSION_MAJOR" -a "$VERSION_MINOR" -lt "$MIN_VERSION_MINOR" ]; then
exit 4
elif [ "$VERSION_MAJOR" -gt "$MAX_VERSION_MAJOR" ]; then
exit 5
else
exit 0
fi