forked from WeBankBlockchain/WeIdentity-Blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-info.sh
310 lines (285 loc) · 7.13 KB
/
check-info.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/bin/bash
JAVA_OPTS='-Djdk.tls.namedGroups="secp256r1,secp256k1"'
classpathDir="./dist/conf"
libDir="./dist/lib"
set -- `getopt c:l: "$@"`
while [ -n "$1" ]
do
case "$1" in
-c)
classpathDir=$2
shift ;;
-l)
libDir=$2
shift ;;
esac
shift
done
# check the command is exists
function checkCommand(){
if type $1 >/dev/null 2>&1
then
return 1
else
return 0
fi
}
# check the os version
function check_os_version() {
echo "----------------------------"
echo "1. OS Version"
echo "----------------------------"
checkCommand uname
if [ $? == 1 ] ; then
uname -a
else
echo "ERROR: no 'uname' command could be found in your OS."
fi
}
# check the jdk version
function check_jdk_version() {
echo "----------------------------"
echo "2. JDK Version"
echo "----------------------------"
checkCommand java
if [ $? == 1 ] ; then
java -version
else
echo "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
}
# check the gradle version
function check_gradle_version() {
echo "----------------------------"
echo "3. Gradle Version"
echo "----------------------------"
checkCommand gradle
if [ $? == 1 ] ; then
gradle -version
else
echo "WARN: GRADLE_HOME is not set and no 'gradle' command could be found in your PATH.
Please set the GRADLE_HOME variable in your environment to match the
location of your Gradle installation."
fi
}
# check the fisco-solc version
function check_fisco_solc_version() {
echo "----------------------------"
echo "4. FISCO-SOLC Version"
echo "----------------------------"
checkCommand fisco-solc
if [ $? == 1 ] ; then
fisco-solc --version
else
echo "WARN: no 'fisco-solc' command could be found in your PATH."
fi
}
# check the os version
check_os_version
# check the jdk version
check_jdk_version
# check the gradle version
check_gradle_version
# check the fisco-solc version
check_fisco_solc_version
if [ ! -d "$classpathDir" ];
then
echo "ERROR: you need use -c to specify your right classpath."
exit 0
fi
if [ ! -d "$libDir" ];
then
echo "ERROR: you need use -l to specify your libDir."
exit 0
fi
fisco_properties="$classpathDir/fisco.properties"
weidentity_properties="$classpathDir/weidentity.properties"
ca_crt="$classpathDir/ca.crt"
client_keystore="$classpathDir/client.keystore"
sdk_crt="$classpathDir/sdk.crt"
sdk_key="$classpathDir/sdk.key"
sdk_version=
# check the user configure
function check_user_config() {
echo "----------------------------"
echo "5. User Config"
echo "----------------------------"
if [ ! -f "$fisco_properties" ];
then
echo "ERROR: the fisco.properties does not exists."
else
echo "the fisco.properties is exists."
fi
if [ ! -f "$weidentity_properties" ];
then
echo "ERROR: the weidentity.properties does not exists."
else
echo "the weidentity.properties is exists."
fi
if [ ! -f "$ca_crt" ];
then
echo "ERROR: the ca.crt does not exists."
else
echo "the ca.crt is exists and the MD5 is `md5sum $ca_crt | cut -d " " -f1`"
fi
bcos_version=$(grep "bcos\.version" $fisco_properties |awk -F"=" '{print $2}')
if [[ $bcos_version == 1* ]];
then
if [ ! -f "$client_keystore" ];
then
echo "ERROR: the client.keystore does not exists."
else
echo "the client.keystore is exists and the MD5 is `md5sum $client_keystore | cut -d " " -f1`"
fi
elif [[ $bcos_version == 2* ]];
then
if [ ! -f "$sdk_crt" ];
then
echo "ERROR: the sdk.crt does not exists."
else
echo "the sdk.crt is exists and the MD5 is `md5sum $sdk_crt | cut -d " " -f1`"
fi
if [ ! -f "$sdk_key" ];
then
echo "ERROR: the sdk.key does not exists."
else
echo "the sdk.key is exists and the MD5 is `md5sum $sdk_key | cut -d " " -f1`"
fi
else
echo "ERROR: the bcos.version value is invalid."
fi
blockchain_orgid=$(grep "blockchain\.orgid=" $weidentity_properties |awk -F"=" '{print $2}')
echo "the current orgid: $blockchain_orgid"
nodes=$(grep "nodes=" $weidentity_properties |awk -F"=" '{print $2}')
echo "the current nodes: $nodes"
OLD_IFS="$IFS"
IFS=","
array=($nodes)
IFS="$OLD_IFS"
for var in ${array[@]}
do
var=${var##*@}
echo begin test $var
ip=`echo $var | cut -d : -f 1`
port=`echo $var | cut -d : -f 2`
result=`echo -e "\n" | timeout 5 telnet $ip $port 2>/dev/null | grep Connected | wc -l`
if [ $result -eq 1 ]; then
echo "Network is Open."
else
echo "Network is Closed."
fi
done
}
# check the jar version
function check_jar_version() {
echo "----------------------------"
echo "6. Dependencies Jar Version"
echo "----------------------------"
bcos_version=$(grep "bcos\.version" $fisco_properties |awk -F"=" '{print $2}')
echo "the bcos version: $bcos_version"
isSdk=1
for file in $libDir/*
do
file=${file##*/}
if [[ $file == weid-contract-java* ]];
then
echo "the weid contract jar: "$file
fi
if [[ $file == weid-java-sdk* ]];
then
isSdk=0
echo "the weid java sdk jar: "$file
fi
if [[ $file == web3sdk*-1.* ]];
then
if [[ $bcos_version == 1* ]];
then
echo "the web3sdk jar: "$file
fi
fi
if [[ $file == web3sdk*-2.* ]];
then
if [[ $bcos_version == 2* ]];
then
echo "the web3sdk jar: "$file
fi
fi
done
if [[ $isSdk == 1 ]];
then
if [ -d "./dist/app/" ];
then
for file in ./dist/app/*
do
file=${file##*/}
if [[ $file == weid-java-sdk-*.jar ]];
then
echo "the weid java sdk jar: $file"
fi
done
fi
fi
}
# check the node version
function check_node_version() {
echo "----------------------------"
echo "7. FISCO BCOS Version"
echo "----------------------------"
isSdk=1
version_default=2.9
for file in $libDir/*
do
file=${file##*/}
if [[ $file == weid-java-sdk* ]];
then
isSdk=0
echo "your project includes the weid-java-sdk, this is: "$file
get_the_version $file
if [[ $(echo "${sdk_version} < ${version_default}" | bc) -eq 1 ]]
then
echo "WARN: the current version of SDK does not support to check the node version, minimum version 1.4.0"
else
java ${JAVA_OPTS} -cp $libDir/*:$classpathDir/ com.webank.weid.app.AppCommand --checkversion test
fi
fi
done
if [[ $isSdk == 1 ]];
then
if [ -d "./dist/app/" ];
then
for file in ./dist/app/*
do
file=${file##*/}
if [[ $file == weid-java-sdk-*.jar ]];
then
get_the_version $file
if [[ $(echo "${sdk_version} < ${version_default}" | bc) -eq 1 ]]
then
echo "WARN: the current version of SDK does not support to check the node version, minimum version 1.4.0"
else
currentDir=`pwd`
java ${JAVA_OPTS} -cp $currentDir/dist/lib/*:$currentDir/dist/app/*:$currentDir/dist/conf/ com.webank.weid.app.AppCommand --checkversion test
fi
fi
done
fi
fi
}
function get_the_version() {
sdk_version=$1
sdk_version=${sdk_version/.rc-/}
sdk_version=${sdk_version##*-}
sdk_version=${sdk_version%.jar}
sdk_version=${sdk_version%.*}
}
function main() {
# check the user config
check_user_config
# check the jar version
check_jar_version
# check the node version
check_node_version
}
main