-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaliyun-bj.sh
executable file
·291 lines (270 loc) · 9.44 KB
/
aliyun-bj.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
#! /bin/bash
workdir=$(cd $(dirname $0); pwd)
ssh_config="ssh -i $workdir/../aliyun_key/narrator-bj.pem" #Here is your machine's ssh keypair
cluster_size=5
index=0
client_ip="eng_client"
narrator_folder_name="Narrator"
engraft_folder_name="engraft"
raft_cli_folder_name="raft_client"
damysus_folder_name="damysus"
build_narrator_local(){
echo "sending SeverEnclave to ${cloud_ip}";
cd $workdir/../example/ServerEnclave;
rm ./build/ -rf;
mkdir ./build;
cd ./build;
cmake ..;
make -j;
echo "sending AppEnclave to ${cloud_ip}";
cd $workdir/../example/AppEnclave;
rm ./build/ -rf;
mkdir ./build;
cd ./build;
cmake ..;
make -j;
}
send_narrator() {
cloud_ip=$1
echo "sending Narrator to ${cloud_ip}"
time rsync -a -e "$ssh_config" \
$workdir/../example/ \
root@${cloud_ip}:~/${narrator_folder_name}/
}
download_log(){
cloud_ip=$1
echo "Download log ${cloud_ip}"
time rsync -a -e "$ssh_config" root@${cloud_ip}:/tmp/AE1.log /tmp/AE1.log
time rsync -a -e "$ssh_config" root@${cloud_ip}:/tmp/AE2.log /tmp/AE2.log
time rsync -a -e "$ssh_config" root@${cloud_ip}:/tmp/AE3.log /tmp/AE3.log
time rsync -a -e "$ssh_config" root@${cloud_ip}:/tmp/AE4.log /tmp/AE4.log
time rsync -a -e "$ssh_config" root@${cloud_ip}:/tmp/AE5.log /tmp/AE5.log
time rsync -a -e "$ssh_config" root@${cloud_ip}:/tmp/AE6.log /tmp/AE6.log
time rsync -a -e "$ssh_config" root@${cloud_ip}:/tmp/AE7.log /tmp/AE7.log
time rsync -a -e "$ssh_config" root@${cloud_ip}:/tmp/AE8.log /tmp/AE8.log
time rsync -a -e "$ssh_config" root@${cloud_ip}:/tmp/AE9.log /tmp/AE9.log
time rsync -a -e "$ssh_config" root@${cloud_ip}:/tmp/AE10.log /tmp/AE10.log
}
install_oe_sdk() {
cloud_ip=$1
$ssh_config root@${cloud_ip} "
cd ~/aliyun_cloud_cntl/;
chmod +x *;
./init_aliyun.sh;
"
}
install_oe_sdk_back() {
cloud_ip=$1
$ssh_config root@${cloud_ip} "
cd ~/aliyun_cloud_cntl/;
chmod +x *;
./init_aliyun.sh;
rm -rf ~/aliyun_oe_0.17.0/build;
mkdir ~/aliyun_oe_0.17.0/build;
cd ~/aliyun_oe_0.17.0/build;
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/openenclave_0_17;
sudo make -j8 install;
"
}
send_cloud_config() {
cloud_ip=$1
echo "sending cloud_config to ${cloud_ip}"
time rsync -a -e "$ssh_config" \
$workdir/../install_script/ \
root@${cloud_ip}:~/aliyun_cloud_cntl/
}
Clone_Narrator() {
cloud_ip=$1
echo "git clone source to ${cloud_ip} $workdir"
$ssh_config root@${cloud_ip} "
cd ~/;
rm ~/Narrator -rf;
# git clone https://github.com/pw0rld/Narrator.git;
git clone https://gitee.com/pw0rld/Narrator.git;
cd ~/Narrator;
chmod +x init.sh;
./init.sh;
cd ~/Narrator/openenclave17/;
rm -rf ./build;
mkdir ./build;
cd ./build;
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/openenclave_0_17;
sudo make -j8 install;
"
}
Update_host_config(){
cloud_ip=$1
echo '''
Add to /etc/hosts, this step inorder to speed up the access on github
204.232.175.78 http://documentcloud.github.com
207.97.227.239 http://github.com
204.232.175.94 http://gist.github.com
107.21.116.220 http://help.github.com
207.97.227.252 http://nodeload.github.com
199.27.76.130 http://raw.github.com
107.22.3.110 http://status.github.com
204.232.175.78 http://training.github.com
207.97.227.243 http://www.github.com
''';
$ssh_config root@${cloud_ip} "
sudo cat <<EOF>>/etc/hosts
204.232.175.78 http://documentcloud.github.com
207.97.227.239 http://github.com
204.232.175.94 http://gist.github.com
107.21.116.220 http://help.github.com
207.97.227.252 http://nodeload.github.com
199.27.76.130 http://raw.github.com
107.22.3.110 http://status.github.com
204.232.175.78 http://training.github.com
207.97.227.243 http://www.github.com
EOF
"
}
write_conf(){
cloud_ip=$1
echo "Clean current _peer_ip_allowed and _peers"
$ssh_config root@${cloud_ip} "
rm ~/Narrator/ServerEnclave/host/network/_peer_ip_allowed;
rm ~/Narrator/ServerEnclave/host/network/_peers;
"
echo "Write _peer_ip_allowed"
$ssh_config root@${cloud_ip} "
sudo cat <<EOF>>~/Narrator/ServerEnclave/host/network/_peer_ip_allowed
172.25.164.19
172.25.164.20
127.0.0.1
EOF
"
echo "Write _peers"
$ssh_config root@${cloud_ip} "
sudo cat <<EOF>>~/Narrator/ServerEnclave/host/network/_peers
172.25.164.20:3389:1:se_master
172.25.164.19:3388:2:se_slave
172.25.164.19:3389:3:se_slave
172.25.164.19:3387:4:se_slave
127.0.0.1:8707:29:client
127.0.0.1:8706:28:client
127.0.0.1:8705:27:client
127.0.0.1:8704:26:client
127.0.0.1:8703:25:client
127.0.0.1:8702:24:client
127.0.0.1:8701:23:client
127.0.0.1:8708:22:client
127.0.0.1:8709:21:client
127.0.0.1:8700:20:client
EOF
"
echo "Finish!!!"
}
# cd ~/Narrator/ServerEnclave/build/
# ~/Narrator/ServerEnclave/build/host/attestation_host ~/Narrator/ServerEnclave/build/enclave/enclave_a.signed 3386 ~/Narrator/ServerEnclave/host/network/_peers 172.25.164.20
# ~/Narrator/AppEnclave/build/host/attestation_host ~/Narrator/AppEnclave/build/enclave/enclave_a.signed 8707 127.0.0.1 3389 172.25.164.21>> /tmp/AE.log
run_narrator_serverenclave() {
cloud_ip=$1
echo "Shudown Narrator"
$ssh_config root@${cloud_ip} "
ps -ef | grep attestation | grep -v grep | awk '{print \$2}' |sudo xargs kill -9
sleep 1
"
echo "Running ServerEnclave to ${cloud_ip}"
$ssh_config root@${cloud_ip} "
cd ~/$narrator_folder_name/ServerEnclave/build;
nohup ./host/attestation_host ./enclave/enclave_a.signed 3389 ../host/network/_peers \$(hostname -I) &
sleep 1
#nohup ./host/attestation_host ./enclave/enclave_a.signed 3388 ../host/network/_peers \$(hostname -I) >> /tmp/SE1.log 2>&1 &
sleep 1
#nohup ./host/attestation_host ./enclave/enclave_a.signed 3387 ../host/network/_peers \$(hostname -I) >> /tmp/SE2log 2>&1 &
sleep 1
#nohup ./host/attestation_host ./enclave/enclave_a.signed 3386 ../host/network/_peers \$(hostname -I) >> /tmp/SE3log 2>&1 &
sleep 1
# Wlan
# nohup ./host/attestation_host ./enclave/enclave_a.signed 3389 ../host/network/_peers 172.25.164.20 &
# sleep 1
# nohup ./host/attestation_host ./enclave/enclave_a.signed 3388 ../host/network/_peers 172.25.164.20 >> /tmp/SE1log 2>&1 &
# sleep 1
# # nohup ./host/attestation_host ./enclave/enclave_a.signed 3387 ../host/network/_peers 172.25.164.20 >> /tmp/SE2log 2>&1 &
# sleep 1
# # nohup ./host/attestation_host ./enclave/enclave_a.signed 3386 ../host/network/_peers 172.25.164.20 >> /tmp/SE3log 2>&1 &
# sleep 1
# #nohup ./host/attestation_host ./enclave/enclave_a.signed 3385 ../host/network/_peers 172.25.164.20 >> /tmp/SE4log 2>&1 &
# sleep 1
# #nohup ./host/attestation_host ./enclave/enclave_a.signed 3384 ../host/network/_peers 172.25.164.20 >> /tmp/SE5log 2>&1 &
"
}
run_narrator_appenclave() {
cloud_ip=$1
echo "Running Appenclave to ${cloud_ip}"
$ssh_config root@${cloud_ip} "
cd ~/$narrator_folder_name/AppEnclave/build;
rm /tmp/AE* 2>&1;
# nohup ./host/attestation_host ./enclave/enclave_a.signed 8707 127.0.0.1 3389 \$(hostname -I) >> /tmp/AE.log 2>&1 &
# wlan
nohup ./host/attestation_host ./enclave/enclave_a.signed 8709 127.0.0.1 3389 172.25.164.20 >> /tmp/AE1.log 2>&1 &
nohup ./host/attestation_host ./enclave/enclave_a.signed 8708 127.0.0.1 3389 172.25.164.20 >> /tmp/AE2.log 2>&1 &
nohup ./host/attestation_host ./enclave/enclave_a.signed 8707 127.0.0.1 3389 172.25.164.20 >> /tmp/AE3.log 2>&1 &
nohup ./host/attestation_host ./enclave/enclave_a.signed 8706 127.0.0.1 3389 172.25.164.20 >> /tmp/AE4.log 2>&1 &
nohup ./host/attestation_host ./enclave/enclave_a.signed 8705 127.0.0.1 3389 172.25.164.20 >> /tmp/AE5.log 2>&1 &
nohup ./host/attestation_host ./enclave/enclave_a.signed 8704 127.0.0.1 3389 172.25.164.20 >> /tmp/AE6.log 2>&1 &
nohup ./host/attestation_host ./enclave/enclave_a.signed 8703 127.0.0.1 3389 172.25.164.20 >> /tmp/AE7.log 2>&1 &
"
}
build_narrator(){
cloud_ip=$1
echo "Build Narrator ServerEnclave"
$ssh_config root@${cloud_ip} "
cd ~/Narrator/ServerEnclave/;
git reset --hard;
git pull;
rm -rf build;
mkdir build;
cd build;
cmake ..;
make -j;
"
echo "Build Narrator ServerEnclave Successful! Now build the AppEnclave"
$ssh_config root@${cloud_ip} "
cd ~/Narrator/AppEnclave/;
mkdir build;
cd build;
cmake ..;
make -j;
"
echo "Finish!"
}
if [ "$2" == "install" ]
then
echo "Install openenclave and Read for the requirement"
Clone_Narrator $1
write_conf $1
build_narrator $1
elif [ "$2" == "log" ]
then
echo "Fetch the remote log"
download_log $1
# elif [ "$2" == "Tendermint" ]
# then
# # TODO
elif [ "$2" == "Update" ]
then
echo "Update the Serverenclave";
# build_narrator $1
write_conf $1
run_narrator_serverenclave $1
elif [ "$2" == "Appenclave" ]
then
echo "Setup the Appenclave";
run_narrator_appenclave $1
elif [ "$2" == "Appenclave" ]
then
echo "Kill all!!";
$ssh_config root@${1} "
ps -ef | grep attestation | grep -v grep | awk '{print \$2}' |sudo xargs kill -9
sleep 1
"
fi
# send_oe_sdk $1
# send_cloud_config $1
# install_oe_sdk $1
# build_narrator_local
# send_narrator $1
# run_narrator_serverenclave $1