-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathversion.sh
executable file
·156 lines (137 loc) · 5.44 KB
/
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
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
#!/bin/bash
RETVAL=0
. check_lock.sh
check_lock
RETVAL=$?
if [[ ${RETVAL} -ne 0 ]]; then
exit 0;
fi
PROTO_FILE="$(dirname "$0")/libs/libupmqprotocol/protocol.proto"
SERVER_NAME=""
SERVER_MAJOR=""
SERVER_MINOR=""
CLIENT_MAJOR=""
CLIENT_MINOR=""
get_versions()
{
OLD_IFS=$IFS # save the field separator
IFS=$'\n' # new field separator, the end of line
echo "protofile path ${1}"
# shellcheck disable=SC2013
for line in $(cat "${1}")
do
case ${line} in
*"server_vendor_id"*)
# shellcheck disable=SC2001
SERVER_NAME=$(sed -e 's#.*=\(\)#\1#' <<< "${line}")
SERVER_NAME=$(sed -e 's/^[^"]*"//; s/".*//' <<< "${SERVER_NAME}")
;;
*"server_major_version"*)
# shellcheck disable=SC2001
SERVER_MAJOR=$(sed -e 's#.*=\(\)#\1#' <<< "${line}")
# shellcheck disable=SC2001
SERVER_MAJOR=$(sed -e 's/[^0-9]*//g' <<< "${SERVER_MAJOR}")
;;
*"server_minor_version"*)
# shellcheck disable=SC2001
SERVER_MINOR=$(sed -e 's#.*=\(\)#\1#' <<< "${line}")
# shellcheck disable=SC2001
SERVER_MINOR=$(sed -e 's/[^0-9]*//g' <<< "${SERVER_MINOR}")
;;
*"client_major_version"*)
# shellcheck disable=SC2001
CLIENT_MAJOR=$(sed -e 's#.*=\(\)#\1#' <<< "${line}")
# shellcheck disable=SC2001
CLIENT_MAJOR=$(sed -e 's/[^0-9]*//g' <<< "${CLIENT_MAJOR}")
;;
*"client_minor_version"*)
# shellcheck disable=SC2001
CLIENT_MINOR=$(sed -e 's#.*=\(\)#\1#' <<< "${line}")
# shellcheck disable=SC2001
CLIENT_MINOR=$(sed -e 's/[^0-9]*//g' <<< "${CLIENT_MINOR}")
;;
esac
done
if [[ -z ${SERVER_NAME} ]]; then
SERVER_NAME=upmq;
fi
if [[ -z ${SERVER_MAJOR} ]]; then
SERVER_MAJOR=0;
fi
if [[ -z ${SERVER_MINOR} ]]; then
SERVER_MINOR=0;
fi
if [[ -z ${CLIENT_MAJOR} ]]; then
CLIENT_MAJOR=0;
fi
if [[ -z ${CLIENT_MINOR} ]]; then
CLIENT_MINOR=0;
fi
IFS=${OLD_IFS} # restore default field separator
}
get_versions "${PROTO_FILE}"
# shellcheck disable=SC2230
if which git >/dev/null; then
FILE_NAME_VER_PROP="$(dirname "$0")/VERSION.txt"
FILE_NAME_COMMIT_PROP="$(dirname "$0")/COMMIT.txt"
FILE_NAME="$(dirname "$0")/share/Version.hpp"
rm -f "${FILE_NAME}"
BUILD_VER=$(git log --oneline | wc -l)
# shellcheck disable=SC2021
BUILD_VER=$(echo -e "${BUILD_VER}" | tr -d '[[:space:]]')
COMMITTER_FULLSHA=$(git log -n 1 "--pretty=format:%H")
COMMITTER_SHORTSHA=$(git log -n 1 "--pretty=format:%h")
COMMITTER_NAME=$(git log -n 1 "--pretty=format:%cn")
COMMITTER_EMAIL=$(git log -n 1 "--pretty=format:%ce")
COMMITTER_DATE=$(git log -n 1 "--pretty=format:%ci")
COMMITTER_NOTE=$(git log -n 1 "--pretty=format:%s")
echo "SERVER NAME : ${SERVER_NAME}"
echo "SERVER VERSION : ${SERVER_MAJOR}.${SERVER_MINOR}.${BUILD_VER}"
echo "CLIENT VERSION : ${CLIENT_MAJOR}.${CLIENT_MINOR}.${BUILD_VER}"
# shellcheck disable=SC2129
echo "#ifndef VERSION_H" >> "${FILE_NAME}"
echo "#define VERSION_H" >> "${FILE_NAME}"
echo "" >> "${FILE_NAME}"
# shellcheck disable=SC2129
echo "#include <string>" >> "${FILE_NAME}"
# shellcheck disable=SC2086
# shellcheck disable=SC2129
echo "#include <sstream>" >> ${FILE_NAME}
# shellcheck disable=SC2129
echo "" >> "${FILE_NAME}"
echo "" >> "${FILE_NAME}"
# shellcheck disable=SC2129
echo "#define MQ_VERSION_MAJOR ${SERVER_MAJOR}" >> "${FILE_NAME}"
echo "#define MQ_VERSION_MINOR ${SERVER_MINOR}" >> "${FILE_NAME}"
echo "#define MQ_VERSION_REVISION ${BUILD_VER}" >> "${FILE_NAME}"
echo "" >> "${FILE_NAME}"
echo "#define MQ_COMMITTER_NAME \"$COMMITTER_NAME\"" >> "${FILE_NAME}"
echo "#define MQ_COMMITTER_EMAIL \"$COMMITTER_EMAIL\"" >> "${FILE_NAME}"
echo "" >> "${FILE_NAME}"
# shellcheck disable=SC2129
echo "#define MQ_COMMITTER_FULLSHA \"$COMMITTER_FULLSHA\"" >> "${FILE_NAME}"
echo "#define MQ_COMMITTER_SHORTSHA \"$COMMITTER_SHORTSHA\"" >> "${FILE_NAME}"
echo "#define MQ_COMMITTER_DATE \"$COMMITTER_DATE\"" >> "${FILE_NAME}"
echo "#define MQ_COMMITTER_NOTE \"$COMMITTER_NOTE\"" >> "${FILE_NAME}"
echo "" >> "${FILE_NAME}"
echo "#endif // VERSION_H" >> "${FILE_NAME}"
echo "Version file : ${FILE_NAME}"
echo "Version number: ${BUILD_VER}"
echo "COMMITTER SHA : $COMMITTER_FULLSHA"
echo "COMMITTER SHA : $COMMITTER_SHORTSHA"
echo "COMMITTER name : $COMMITTER_NAME"
echo "COMMITTER email: $COMMITTER_EMAIL"
echo "COMMITTER date : $COMMITTER_DATE"
rm -f "${FILE_NAME_VER_PROP}"
echo "${SERVER_MAJOR}.${SERVER_MINOR}.${BUILD_VER}" >> "${FILE_NAME_VER_PROP}"
rm -f "${FILE_NAME_COMMIT_PROP}"
echo "${COMMITTER_SHORTSHA}" >> "${FILE_NAME_COMMIT_PROP}"
else
echo "{--------------------------------------------------}"
echo "{ }"
echo "{ }"
echo "{ Please set the Path variable in your environment }"
echo "{ to match the location of git }"
echo "{ }"
echo "{--------------------------------------------------}"
fi