-
Notifications
You must be signed in to change notification settings - Fork 25
/
compile.sh
executable file
·207 lines (189 loc) · 6.25 KB
/
compile.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
#!/bin/bash
source ./common/script/common.inc
source run.config
set -e
if [[ "$@" == "--offline" ]];then
OFFLINE_MODE="1"
echo "Compile in offline mode.."
fi
if [[ "$@" == "cn" || "$@" == "en" ]];then
sed -i "/^repoType/crepoType=$1" gradle.properties
fi
if [ ! -d dist/ ];then
mkdir dist
fi
if [ ! -d dist/lib ];then
mkdir dist/lib
fi
#SOURCE_CODE_DIR=$(pwd)
FISCO_XML_CONFIG_TPL=${SOURCE_CODE_DIR}/common/script/tpl/fisco.properties.tpl
FISCO_XML_CONFIG=${SOURCE_CODE_DIR}/common/script/tpl/fisco.properties
FISCO_XML_CONFIG_TMP=${SOURCE_CODE_DIR}/common/script/tpl/fisco.properties.tmp
WEIDENTITY_CONFIG_TPL=${SOURCE_CODE_DIR}/common/script/tpl/weidentity.properties.tpl
WEIDENTITY_CONFIG=${SOURCE_CODE_DIR}/common/script/tpl/weidentity.properties
function clean_config()
{
cd ${SOURCE_CODE_DIR}
echo "begin to clean config..."
if [ -d bin/ ];then
rm -rf bin/
fi
if [ -d ${SOURCE_CODE_DIR}/script/src/ ];then
rm -rf ${SOURCE_CODE_DIR}/script/src/
fi
if [ -d build/ ];then
rm -rf build/
fi
echo "clean finished..."
}
function compile()
{
echo "begin to compile build tools..."
cd ${SOURCE_CODE_DIR}
#if more than one blockchain node exist, use this to seperate them
OLD_IFS="$IFS"
IFS=","
array=($blockchain_address)
IFS="$OLD_IFS"
#fill with ip and port of blockchain nodes
declare -i num
num=1
for var in ${array[@]}
do
declare -i length
length=${#array[@]}
if [ "${blockchain_fiscobcos_version}" = "2" ] || [ "${blockchain_fiscobcos_version}" = "3" ];then
if [ $num -lt $length ];then
content="${content}$var,"
fi
if [ $num -eq $length ];then
content="${content}$var"
fi
else
echo "currently FISCO BCOS ${blockchain_fiscobcos_version}.x is not supported."
fi
num=${num}+1
done
export BLOCKCHIAN_NODE_INFO=$(echo -e ${content})
export MASTER_GROUP_ID=${group_id}
export SDK_SM_CRYPTO=${sm_crypto}
export CNS_PROFILE_ACTIVE=${cns_profile_active}
export FISCO_BCOS_VERSION=${blockchain_fiscobcos_version}
FISCOVAS='${MASTER_GROUP_ID}:${SDK_SM_CRYPTO}:${FISCO_BCOS_VERSION}:${CNS_PROFILE_ACTIVE}'
envsubst ${FISCOVAS}} < ${FISCO_XML_CONFIG_TPL} >${FISCO_XML_CONFIG}
if [ -f ${FISCO_XML_CONFIG_TMP} ];then
rm ${FISCO_XML_CONFIG_TMP}
fi
#cp ${SOURCE_CODE_DIR}/script/tpl/log4j2.xml ${SOURCE_CODE_DIR}/resources
#cp -rf ${SOURCE_CODE_DIR}/resources ${SOURCE_CODE_DIR}/src/main/
#modify weidentity properties
export DEPLOY_STYLE='blockchain'
export CRYPTO_TYPE=${sm_crypto}
export ORG_ID=${org_id}
export AMOP_ID=${amop_id}
export CHAIN_ID=${chain_id}
export CHAIN_TYPE='FISCO_BCOS'
export PERSISTENCE_TYPE=${persistence_type}
export MYSQL_ADDRESS=${mysql_address}
export MYSQL_DATABASE=${mysql_database}
export MYSQL_USERNAME=${mysql_username}
export MYSQL_PASSWORD=${mysql_password}
VARS='${DEPLOY_STYLE}:${CRYPTO_TYPE}:${BLOCKCHIAN_NODE_INFO}:${ORG_ID}:${CHAIN_ID}:${AMOP_ID}:${CHAIN_TYPE}:${PERSISTENCE_TYPE}:${MYSQL_ADDRESS}:${MYSQL_DATABASE}:${MYSQL_USERNAME}:${MYSQL_PASSWORD}'
envsubst ${VARS} < ${WEIDENTITY_CONFIG_TPL} >${WEIDENTITY_CONFIG}
if [ -f build.gradle ]; then
chmod u+x gradlew
if [ -d ${SOURCE_CODE_DIR}/dist/app ];then
rm -rf ${SOURCE_CODE_DIR}/dist/app
fi
if [[ ${OFFLINE_MODE} == "1" ]];then
./gradlew clean build --offline
else
./gradlew clean build
fi
fi
cp ${WEIDENTITY_CONFIG} ${SOURCE_CODE_DIR}/resources
cp ${FISCO_XML_CONFIG} ${SOURCE_CODE_DIR}/resources
build_classpath
echo "compile finished."
}
function setup()
{
if [ "${blockchain_fiscobcos_version}" = "2" ] || [ "${blockchain_fiscobcos_version}" = "3" ] ;then
cp ${SOURCE_CODE_DIR}/script/tpl/deploy_code/DeployContract.java-${blockchain_fiscobcos_version}.x ${SOURCE_CODE_DIR}/src/main/java/com/webank/weid/command/DeployContract.java
cp ${SOURCE_CODE_DIR}/script/tpl/deploy_code/DeploySystemCpt.java-${blockchain_fiscobcos_version}.x ${SOURCE_CODE_DIR}/src/main/java/com/webank/weid/command/DeploySystemCpt.java
else
echo "currently FISCO BCOS ${blockchain_fiscobcos_version}.x is not supported."
exit 1
fi
}
function check_parameter()
{
if [ -z ${blockchain_address} ];then
echo "blockchain address is empty, please check the config."
exit 1
fi
if [ -z ${blockchain_fiscobcos_version} ];then
echo "blockchain version config is illegal, please check the config."
exit 1
fi
if [ -z ${org_id} ];then
echo "org id is empty, please check the config."
exit 1
fi
#if [ -z ${amop_id} ];then
# echo "amop id is empty, please check the config."
# exit 1
#fi
if [ -z ${chain_id} ];then
echo "chain id is empty, please check the config."
exit 1
fi
if [ -z ${group_id} ];then
echo "group id is empty, please check the config."
exit 1
fi
# if [ -z ${mysql_address} ];then
# echo "mysql_address is empty, please check the config."
# exit 1
# fi
# if [ -z ${mysql_database} ];then
# echo "mysql_database is empty, please check the config."
# exit 1
# fi
# if [ -z ${mysql_username} ];then
# echo "mysql_username is empty, please check the config."
# exit 1
# fi
# if [ -z ${mysql_password} ];then
# echo "mysql_password is empty, please check the config."
# exit 1
# fi
if [ -z ${cns_profile_active} ];then
echo "cns_profile_active is empty, please check the config."
exit 1
fi
# if [ "${cns_profile_active}" != "prd" ] && [ "${cns_profile_active}" != "stg" ] && [ "${cns_profile_active}" != "dev" ];then
# echo "the value of cns_profile_active error, please input: prd, stg, dev"
# exit 1
# fi
}
function check_font()
{
md5file=`cat ext/NotoSansCJKtc-Regular.md5`
md5font=`md5sum ext/NotoSansCJKtc-Regular.ttf | cut -d ' ' -f1`
if [ "$md5file" != "$md5font" ];then
echo "font file is broken."
exit 1
fi
echo "font check successs."
}
function main()
{
# check_font
check_parameter
# setup
check_jdk
compile
clean_config
}
main