This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
check-version.sh
executable file
·99 lines (80 loc) · 2.44 KB
/
check-version.sh
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
# USAGE: ./bin/check-version.sh [-q|--quiet] [EXECUTOR_NAME]
#
# Returns 0 (true) if the currently-installed cook executor version
# matches the source version, and 1 (false) otherwise.
#
# When using the quiet flag (-q|--quiet), no additional output is printed.
# You can override the default binary name (cook-executor) using
# the optional EXECUTOR_NAME argument.
#
# Note: versions containing the case-insensitive string "dev" never match
# (i.e., they're considered "unstable", and should always require a rebuild).
#
# Parse options
#
if [[ "$1" =~ ^(-q|--quiet)$ ]]; then
shift
verbose=false
else
verbose=true
fi
if [[ $# > 1 ]]; then
echo "USAGE: $0 [-q|--quiet] [EXECUTOR_NAME]"
exit -1
fi
EXECUTOR_NAME="${1:-cook-executor}"
#
# Switch to executor directory
#
executor_bin_dir="$(dirname ${BASH_SOURCE[0]})"
cd "$executor_bin_dir/.."
#
# Get source code version
#
source_version=`python3 -c 'from cook._version import __version__; print(__version__)'`
#
# Check for source code dev version
#
shopt -s nocasematch
if [[ "$source_version" == *dev* ]]; then
if $verbose; then
echo "Detected dev (unstable) version: $source_version"
fi
exit 1
fi
#
# Get installed binary's version
#
binary_app=./dist/${EXECUTOR_NAME}/${EXECUTOR_NAME}
host-libc-matches-container-libc() {
# Check if it's safe to locally run the pyinstaller binaries from docker.
# To get the expected libc version: ldd $binary_app | awk '/libc/ { print $3 }'
libc_path_generic='/lib64/libc.so.6'
libc_path_multiarch='/lib/x86_64-linux-gnu/libc.so.6'
[[ "$(uname -s -p)" == 'Linux x86_64' ]] && [[ -e $libc_path_generic || -e $libc_path_multiarch ]]
}
if ! [ -e "$binary_app" ]; then
# Executor binary not found
installed_version=none
elif host-libc-matches-container-libc; then
# We can run the executor directly on x64 Linux (same as docker platform)
installed_version="$(${binary_app} --version)"
else
# Run the executor directly on all other platforms
installed_version="$(docker run --rm -v $(pwd):/opt/cook python:3.5.9-stretch /opt/cook/${binary_app} --version)"
fi
#
# Compare source vs installed binary versions
#
if [ "$installed_version" == "$source_version" ]; then
if $verbose; then
echo "At most recent version: $installed_version"
fi
exit 0
else
if $verbose; then
echo "Version mismatch: $installed_version installed vs $source_version available"
fi
exit 1
fi