-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkg-vsn.sh
executable file
·138 lines (121 loc) · 3.09 KB
/
pkg-vsn.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env bash
set -euo pipefail
# This script prints the release version for emqx
# ensure dir
cd -P -- "$(dirname -- "$0")"
help() {
echo
echo "$0 PROFILE [options]"
echo
echo "-h|--help: To display this usage information"
echo "--long: Print log vsn number. e.g. 5.0.0-otp24.2.1-1-ubuntu20.04-amd64"
echo " Otherwise short e.g. 5.0.0"
echo "--elixir: Include elixir version in the long version string"
echo " e.g. 5.0.0-elixir1.13.3-otp24.2.1-1-ubuntu20.04-amd64"
echo "--vsn_matcher: For --long option, replace the EMQX version with '*'"
echo " so it can be used in find commands"
}
PROFILE="${1:-}"
if [ -z "$PROFILE" ]; then
echo "ERROR: missing profile"
help
exit 1
fi
shift
while [ "$#" -gt 0 ]; do
case $1 in
-h|--help)
help
exit 0
;;
--long)
LONG_VERSION='yes'
shift 1
;;
--elixir)
shift 1
case ${1:-novalue} in
-*)
# another option
IS_ELIXIR='yes'
;;
yes|no)
IS_ELIXIR="${1}"
shift 1
;;
novalue)
IS_ELIXIR='yes'
;;
*)
echo "ERROR: unknown option: --elixir $2"
exit 1
;;
esac
;;
--vsn_matcher)
IS_MATCHER='yes'
shift 1
;;
*)
echo "WARN: Unknown arg (ignored): $1"
exit 1
;;
esac
done
case "${PROFILE}" in
*enterprise*)
RELEASE_EDITION="EMQX_RELEASE_EE"
GIT_TAG_PREFIX="e"
;;
*)
RELEASE_EDITION="EMQX_RELEASE_CE"
GIT_TAG_PREFIX="v"
;;
esac
## emqx_release.hrl is the single source of truth for release version
RELEASE="$(grep -E "define.+${RELEASE_EDITION}" apps/emqx/include/emqx_release.hrl | cut -d '"' -f2)"
git_exact_vsn() {
local tag
tag="$(git describe --tags --match "${GIT_TAG_PREFIX}*" --exact 2>/dev/null)"
echo "${tag//^[v|e]/}"
}
GIT_EXACT_VSN="$(git_exact_vsn)"
if [ "$GIT_EXACT_VSN" != '' ]; then
if [ "$GIT_EXACT_VSN" != "$RELEASE" ]; then
echo "ERROR: Tagged $GIT_EXACT_VSN, but $RELEASE in include/emqx_release.hrl" 1>&2
exit 1
fi
SUFFIX=''
else
SUFFIX="-$(git rev-parse HEAD | cut -b1-8)"
fi
PKG_VSN="${RELEASE}${SUFFIX}"
if [ "${LONG_VERSION:-}" != 'yes' ]; then
echo "$PKG_VSN"
exit 0
fi
### --long LONG_VERSION handling start
if [ "${IS_MATCHER:-}" = 'yes' ]; then
PKG_VSN='*'
fi
OTP_VSN="${OTP_VSN:-$(./scripts/get-otp-vsn.sh)}"
SYSTEM="$(./scripts/get-distro.sh)"
UNAME="$(uname -m)"
case "$UNAME" in
x86_64)
ARCH='amd64'
;;
aarch64)
ARCH='arm64'
;;
arm*)
ARCH=arm
;;
esac
if [ "${IS_ELIXIR:-}" = "yes" ]; then
ELIXIR_VSN="${ELIXIR_VSN:-$(./scripts/get-elixir-vsn.sh)}"
FULL_VSN="${PKG_VSN}-elixir${ELIXIR_VSN}-otp${OTP_VSN}-${SYSTEM}-${ARCH}"
else
FULL_VSN="${PKG_VSN}-otp${OTP_VSN}-${SYSTEM}-${ARCH}"
fi
echo "${FULL_VSN}"