-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkg-vsn.sh
executable file
·156 lines (137 loc) · 3.32 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/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 "--release: Print release version from emqx_release.hrl"
echo
echo "--long: Print long vsn number. e.g. 5.0.0-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-elixir-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
;;
--release)
RELEASE_VERSION='yes'
shift 1
;;
--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
# return immediately if version is already set
if [[ "${PKG_VSN:-novalue}" != novalue && "${LONG_VERSION:-novalue}" != 'yes' ]]; then
echo "$PKG_VSN"
exit 0
fi
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)"
if [ "${RELEASE_VERSION:-}" = 'yes' ]; then
echo "$RELEASE"
exit 0
fi
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="-g$(git rev-parse HEAD | cut -b1-8)"
fi
PKG_VSN="${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
SYSTEM="$(./scripts/get-distro.sh)"
UNAME_M="$(uname -m)"
case "$UNAME_M" in
x86_64)
ARCH='amd64'
;;
aarch64)
ARCH='arm64'
;;
arm64)
ARCH='arm64'
;;
arm*)
ARCH='arm'
;;
esac
if [ "${IS_ELIXIR:-}" = "yes" ]; then
infix='-elixir'
else
infix=''
fi
echo "${PKG_VSN}${infix}-${SYSTEM}-${ARCH}"