forked from Xuhao-troy/FISCO-BCOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_env.sh
300 lines (267 loc) · 7.77 KB
/
init_env.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
#
# 一键安装脚本说明
#1 build.sh在centos和Ubuntu版本测试成功;
#2 所有Linux发行版本请确保yum或apt、git已安装,并能正常使用;
#3 如遇到中途依赖库下载失败,一般和网络状况有关,请到https://github.com/bcosorg/lib找到相应的库,手动安装成功后,再执行此脚本
#
#!/bin/bash
current_dir=`pwd`
enable_guomi=0
Ubuntu_Platform=0
Centos_Platform=1
LOG_ERROR()
{
content=${1}
echo -e "\033[31m"${content}"\033[0m"
}
LOG_INFO()
{
content=${1}
echo -e "\033[32m"${content}"\033[0m"
}
execute_cmd()
{
command="${1}"
#LOG_INFO "RUN: ${command}"
eval ${command}
ret=$?
if [ $ret -ne 0 ];then
LOG_ERROR "FAILED execution of command: ${command}"
exit 1
else
LOG_INFO "SUCCESS execution of command: ${command}"
fi
}
# get platform: now support debain/ubuntu, fedora/centos, oracle
get_platform()
{
uname -v > /dev/null 2>&1 || { echo >&2 "ERROR - FISCO-BCOS requires 'uname' to identify the platform."; exit 1; }
case $(uname -s) in
Darwin)
LOG_ERROR "FISCO-BCOS V2.0 Don't Support MAC OS Yet!"
exit 1;;
FreeBSD)
LOG_ERROR "FISCO-BCOS V2.0 Don't Support FreeBSD Yet!"
exit 1;;
Linux)
if [ -f "/etc/arch-release" ]; then
LOG_ERROR "FISCO-BCOS V2.0 Don't Support arch-linux Yet!"
elif [ -f "/etc/os-release" ];then
DISTRO_NAME=$(. /etc/os-release; echo $NAME)
case $DISTRO_NAME in
Debian*|Ubuntu)
LOG_INFO "Debian*|Ubuntu Platform"
return ${Ubuntu_Platform};; #ubuntu type
Fedora|CentOS*)
LOG_INFO "Fedora|CentOS* Platform"
return ${Centos_Platform};; #centos type
Oracle*)
LOG_INFO "Oracle Platform"
return ${Centos_Platform};; #oracle type
esac
else
LOG_ERROR "Unsupported Platform"
fi
esac
}
install_ubuntu_package()
{
for i in $@ ;
do
LOG_INFO "install ${i}";
execute_cmd "sudo apt-get -y install ${i}";
done
}
install_centos_package()
{
for i in $@ ;
do
LOG_INFO "install ${i}";
execute_cmd "sudo yum -y install ${i}";
done
}
#install ubuntu package
install_ubuntu_deps()
{
#delete the default nodejs of ubuntu
execute_cmd "sudo apt -y remove nodejs"
install_ubuntu_package "cmake" "openssl" "libssl-dev" "libkrb5-dev" "jq"
execute_cmd "curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -"
execute_cmd "sudo apt-get -y install nodejs"
check_nodejs
cnpm_path=`which cnpm`
if [ -f "${cnpm_path}" ];then
execute_cmd "sudo rm -rf ${cnpm_path}"
fi
execute_cmd "sudo npm set registry https://registry.npm.taobao.org && sudo npm set disturl https://npm.taobao.org/dist && sudo npm cache clean"
execute_cmd "sudo npm install -g cnpm --registry=https://registry.npm.taobao.org"
execute_cmd "sudo cnpm install -g babel-cli babel-preset-es2017"
echo '{ "presets": ["es2017"] }' > ~/.babelrc
execute_cmd "sudo npm install -g secp256k1 --unsafe-perm"
}
# install centos package
install_centos_deps()
{
install_centos_package "cmake3" "gcc-c++" "openssl" "openssl-devel" "nodejs" "npm" "jq"
check_nodejs
execute_cmd "sudo npm install -g cnpm --registry=https://registry.npm.taobao.org"
execute_cmd "sudo cnpm install -g babel-cli babel-preset-es2017"
echo '{ "presets": ["es2017"] }' > ~/.babelrc
}
install_all_deps()
{
get_platform
platform=`echo $?`
if [ ${platform} -eq ${Ubuntu_Platform} ];then
install_ubuntu_deps
if [ $enable_guomi -eq 0 ];then
execute_cmd "sudo cp fisco-solc-ubuntu /usr/bin/fisco-solc && sudo chmod +x /usr/bin/fisco-solc"
else
execute_cmd "sudo cp fisco-solc-guomi-ubuntu /usr/bin/fisco-solc-guomi && sudo chmod +x /usr/bin/fisco-solc-guomi"
fi
elif [ ${platform} -eq ${Centos_Platform} ];then
install_centos_deps
if [ $enable_guomi -eq 0 ];then
execute_cmd "sudo cp fisco-solc /usr/bin/fisco-solc && sudo chmod +x /usr/bin/fisco-solc"
else
execute_cmd "sudo cp fisco-solc-guomi-centos /usr/bin/fisco-solc-guomi && sudo chmod +x /usr/bin/fisco-solc-guomi"
fi
else
LOG_ERROR "Unsupported Platform"
exit 1
fi
execute_cmd "chmod +x scripts/install_deps.sh && sudo ./scripts/install_deps.sh"
execute_cmd "sudo chmod +x /usr/bin/fisco-solc"
#install console
execute_cmd "sudo cnpm install -g ethereum-console"
}
update_configjs()
{
execute_cmd "cd ${current_dir}/web3lib"
sed -i 's/var encryptType = 0;/var encryptType = 1;/g' config.js
execute_cmd "cd ${current_dir}/tools/web3lib"
sed -i 's/var encryptType = 0;/var encryptType = 1;/g' config.js
}
install_nodejs()
{
cd ${current_dir}
execute_cmd "cd ${current_dir}/web3lib && cnpm install"
execute_cmd "cd ${current_dir}/tool && cnpm install"
execute_cmd "cd ${current_dir}/systemcontract && cnpm install"
execute_cmd "cd ${current_dir}/tools/contract && cnpm install"
execute_cmd "cd ${current_dir}/tools/systemcontract && cnpm install"
execute_cmd "cd ${current_dir}/tools/web3lib && cnpm install"
}
init_guomi_nodejs()
{
cd ${current_dir}
execute_cmd "cd ${current_dir}/web3lib && bash guomi.sh"
execute_cmd "cd ${current_dir}/tool && bash guomi.sh"
execute_cmd "cd ${current_dir}/systemcontract && bash guomi.sh"
execute_cmd "cd ${current_dir}/tools/contract && bash guomi.sh"
execute_cmd "cd ${current_dir}/tools/systemcontract && bash guomi.sh"
execute_cmd "cd ${current_dir}/tools/web3lib && bash guomi.sh"
update_configjs
}
build_ubuntu_source()
{
# build source
execute_cmd "mkdir -p build && cd build/"
if [ ${enable_guomi} -eq 0 ];then
execute_cmd "cmake -DEVMJIT=OFF -DTESTS=OFF .. "
else
execute_cmd "cmake -DENCRYPTTYPE=ON -DEVMJIT=OFF -DTESTS=OFF .. "
fi
execute_cmd "make && sudo make install"
}
build_centos_source()
{
# build source
execute_cmd "mkdir -p build && cd build/"
if [ ${enable_guomi} -eq 0 ];then
execute_cmd "cmake3 -DEVMJIT=OFF -DTESTS=OFF .. "
else
execute_cmd "cmake3 -DENCRYPTTYPE=ON -DEVMJIT=OFF -DTESTS=OFF .. "
fi
execute_cmd "make && sudo make install && cd ${current_dir}"
}
build_source()
{
cd ${current_dir}
get_platform
platform=`echo $?`
if [ ${platform} -eq ${Ubuntu_Platform} ];then
build_ubuntu_source
elif [ ${platform} -eq ${Centos_Platform} ];then
build_centos_source
else
LOG_ERROR "Unsupported Platform, Exit"
exit 1
fi
}
nodejs_init()
{
cd ${current_dir}
# install nodejs
install_nodejs
if [ ${enable_guomi} -eq 1 ];then
init_guomi_nodejs
fi
}
#### check fisco-bcos
check_fisco()
{
if [ ! -f "/usr/local/bin/fisco-bcos" ]; then
LOG_ERROR "fisco-bcos build fail!"
else
LOG_INFO "fisco-bcos build SUCCESS! path: /usr/local/bin/fisco-bcos"
fi
}
#### check nodejs
check_nodejs()
{
node=$(node -v)
echo | awk '{if(node < "v6") print "WARNING : fisco need nodejs verion newer than v6(refer to: https://gaoliming123.github.io/2017/07/30/node/) , current version is '$node'"}' node="$node"
if [ "" = "`openssl ecparam -list_curves | grep secp256k1`" ];
then
LOG_ERROR "Current Openssl Don't Support secp256k1 ! Please Upgrade Openssl To OpenSSL 1.0.2k-fips"
exit;
fi
}
check()
{
check_fisco
check_nodejs
}
Usage()
{
LOG_INFO "sudo ./build.sh: \tfisco-bcos build and install"
LOG_INFO "sudo ./build.sh -g: \tguomi-fisco-bcos build and install"
LOG_INFO "sudo ./build.sh -h: \tprint help info"
exit 0
}
check_input_param()
{
if [ $# -ge 1 ] && [ "${1}" != "-g" ] && [ "${1}" != "-g" ] && [ "${1}" != "-h" ] && [ "${1}" != "--help" ];then
Usage
fi
if [ "${1}" = "-h" ] || [ "${1}" = "--help" ];then
Usage
fi
if [ "${1}" = "-g" ] || [ "${1}" = "--guomi" ];then
enable_guomi=1
fi
}
install_all()
{
### install all deps
install_all_deps
### build source
#build_source
### init nodejs
nodejs_init
### check
check
}
check_input_param "$@"
install_all