forked from SuperMap/ATLab-ATLChain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atlchain.sh
executable file
·309 lines (275 loc) · 8.38 KB
/
atlchain.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
#!/bin/bash
export PATH=${PWD}/ATLChain_NETWORK/bin:$PATH
export FABRIC_CFG_PATH=${PWD}/ATLChain_NETWORK
CHANNEL_NAME="atlchannel"
ORG_DOMAIN_NAME="orga.atlchain.com"
#compose files
DOCKER_COMPOSE_FILE_KAFKA="docker-compose-kafka.yaml"
DOCKER_COMPOSE_FILE_ORDERER="docker-compose-orderer.yaml"
DOCKER_COMPOSE_FILE_PEER="docker-compose-peer.yaml"
DOCKER_COMPOSE_FILE_CA="docker-compose-ca.yaml"
DOCKER_COMPOSE_FILE_CLI="docker-compose-cli.yaml"
# default compose project name
export COMPOSE_PROJECT_NAME=atlproj
export DOCKER_COMPOSE_PEER_ADDRESS=peer0.orga.atlchain.com:7051
export DOCKER_COMPOSE_PEER_CC_ADDRESS=peer0.orga.atlchain.com:7052
export DOCKER_COMPOSE_PEER_GOSSIP_BOOTSTRAP=peer0.orga.atlchain.com:7051
export CORE_PEER_ADDRESS=peer0.orga.atlchain.com:7051
export ORERER_ADDRESS=orderer.atlchain.com:7050
function printHelp() {
echo "Usage: "
echo " atlchain.sh <mode> [<node>]"
echo " <mode> - one of 'up', 'down', 'genCerts', 'genArti', 'clean'"
echo " - 'up' - bring up the network with docker-compose up"
echo " - 'down' - clear the network with docker-compose down"
echo " - 'genCerts' - generate crypto material"
echo " - 'genArti' - generate channel artifacts"
echo " - 'clean' - clean files built during network running"
echo " <node> - one of 'orderer', 'peer', 'ca', 'cli'"
echo " - 'orderer' - orderer node"
echo " - 'peer' - peer node"
echo " - 'ca' - ca node"
echo " - 'cli' - tool node, you can run commands in cli container"
echo "e.g."
echo " atlchain.sh genCerts"
echo " atlchain.sh genArti"
echo " atlchain.sh up orderer"
echo " atlchain.sh down peer"
}
# Generates Org certs using cryptogen tool
function genCerts() {
which cryptogen
if [ "$?" -ne 0 ]; then
echo "cryptogen tool not found."
exit 1
fi
echo
echo "##########################################################"
echo "##### Generate certificates using cryptogen tool #########"
echo "##########################################################"
if [ -d "crypto-config" ]; then
rm -rf crypto-config
fi
set -x
cryptogen generate --config=./crypto-config.yaml
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate certificates..."
exit 1
fi
echo
}
# Generate Channel Artifacts used in the network
function genChannelArtifacts() {
which configtxgen
if [ "$?" -ne 0 ]; then
echo "configtxgen tool not found. exiting"
exit 1
fi
if [ ! -d "./channel-artifacts" ]; then
mkdir ./channel-artifacts
fi
echo "##########################################################"
echo "######### Generating Orderer Genesis block ##############"
echo "##########################################################"
set -x
configtxgen -profile OrdererChannel -channelID ordererchannel -outputBlock ./channel-artifacts/genesis.block
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate orderer genesis block..."
exit 1
fi
echo
echo "#################################################################"
echo "### Generating channel configuration transaction 'atlchannel.tx' ###"
echo "#################################################################"
set -x
configtxgen -profile TxChannel -outputCreateChannelTx ./channel-artifacts/atlchannel.tx -channelID $CHANNEL_NAME
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate channel configuration transaction..."
exit 1
fi
echo
echo "#################################################################"
echo "####### Generating anchor peer update for Org ##########"
echo "#################################################################"
set -x
configtxgen -profile TxChannel -outputAnchorPeersUpdate ./channel-artifacts/OrgAanchors.tx -channelID $CHANNEL_NAME -asOrg OrgA
configtxgen -profile TxChannel -outputAnchorPeersUpdate ./channel-artifacts/OrgBanchors.tx -channelID $CHANNEL_NAME -asOrg OrgB
configtxgen -profile TxChannel -outputAnchorPeersUpdate ./channel-artifacts/OrgCanchors.tx -channelID $CHANNEL_NAME -asOrg OrgC
res=$?
set +x
if [ $res -ne 0 ]; then
echo "Failed to generate anchor peer update for Org..."
exit 1
fi
echo
}
function startKafka() {
docker-compose -f ${DOCKER_COMPOSE_FILE_KAFKA} up -d 2>&1
if [ $? -ne 0 ]; then
echo "ERROR !!!! Unable to start kafka"
exit 1
fi
}
function startOrderer() {
docker-compose -f ${DOCKER_COMPOSE_FILE_ORDERER} up -d 2>&1
if [ $? -ne 0 ]; then
echo "ERROR !!!! Unable to start orderer node"
exit 1
fi
}
function startPeer() {
docker-compose -f ${DOCKER_COMPOSE_FILE_PEER} up -d 2>&1
if [ $? -ne 0 ]; then
echo "ERROR !!!! Unable to start peer node"
exit 1
fi
}
function startCA() {
docker-compose -f ${DOCKER_COMPOSE_FILE_CA} up -d 2>&1
if [ $? -ne 0 ]; then
echo "ERROR !!!! Unable to start CA node "
exit 1
fi
}
# Start a CLI peer container for operation
function startCLI() {
docker-compose -f ${DOCKER_COMPOSE_FILE_CLI} up -d 2>&1
if [ $? -ne 0 ]; then
echo "ERROR !!!! Unable to start CLI node"
exit 1
fi
}
# Start a CA container
function startCA() {
docker-compose -f ${DOCKER_COMPOSE_FILE_CA} up -d 2>&1
if [ $? -ne 0 ]; then
echo "ERROR !!!! Unable to start CA node"
exit 1
fi
}
# Remove the files generated
function cleanFiles() {
# rm -rf crypto-config
rm -rf channel-artifacts
rm -rf production
}
function stopOrderer() {
docker-compose -f ${DOCKER_COMPOSE_FILE_ORDERER} down 2>&1
}
function stopKafka() {
docker-compose -f ${DOCKER_COMPOSE_FILE_KAFKA} down 2>&1
}
function stopPeer() {
docker-compose -f ${DOCKER_COMPOSE_FILE_PEER} down 2>&1
}
function stopCA() {
docker-compose -f ${DOCKER_COMPOSE_FILE_CA} down 2>&1
}
function stopCLI() {
docker-compose -f ${DOCKER_COMPOSE_FILE_CLI} down 2>&1
}
function stopCA() {
docker-compose -f ${DOCKER_COMPOSE_FILE_CA} down 2>&1
if [ $? -ne 0 ]; then
echo "ERROR !!!! Unable to stop CA node"
exit 1
fi
}
function startAll() {
startOrderer
startPeer
startCA
startCLI
}
function stopAll() {
stopOrderer
stopPeer
stopCA
stopCLI
}
function addOrg() {
cryptogen generate --config=./orgc-crypto.yaml
configtxgen -printOrg OrgC > ./channel-artifacts/orgc.json
}
# Network config files in ATLChain_NETWORK directory
cd ATLChain_NETWORK
# untar bin package
if [ ! -d "bin" ]
then
echo "extract binary files..."
tar xvf bin.tar.xz
fi
if [ ! -d "production" ];then
mkdir production
fi
MODE=$1
shift
NODE=$1
shift
# Determine whether starting or stopping
if [ "$MODE" == "up" ]; then
if [ "$NODE" == "kafka" ]; then
export COMPOSE_PROJECT_NAME=atlprojk
startKafka
elif [ "$NODE" == "orderer" ]; then
export COMPOSE_PROJECT_NAME=atlprojo
startOrderer
elif [ "$NODE" == "peer" ]; then
export COMPOSE_PROJECT_NAME=atlprojp
startPeer
elif [ "$NODE" == "ca" ]; then
export COMPOSE_PROJECT_NAME=atlprojc
startCA
elif [ "$NODE" == "cli" ]; then
export COMPOSE_PROJECT_NAME=atlprojcl
startCLI
elif [ "$NODE" == "all" ]; then
startAll
else
printHelp
exit 1
fi
elif [ "$MODE" == "down" ]; then
if [ "$NODE" == "kafka" ]; then
export COMPOSE_PROJECT_NAME=atlprojk
stopKafka
elif [ "$NODE" == "orderer" ]; then
export COMPOSE_PROJECT_NAME=atlprojo
stopOrderer
elif [ "$NODE" == "peer" ]; then
export COMPOSE_PROJECT_NAME=atlprojp
stopPeer
elif [ "$NODE" == "ca" ]; then
export COMPOSE_PROJECT_NAME=atlprojc
stopCA
elif [ "$NODE" == "cli" ]; then
export COMPOSE_PROJECT_NAME=atlprojcl
stopCLI
elif [ "$NODE" == "all" ]; then
stopAll
else
printHelp
exit 1
fi
elif [ "$MODE" == "genCerts" ]; then
genCerts
elif [ "$MODE" == "genArti" ]; then
genChannelArtifacts
elif [ "$MODE" == "generate" ]; then
genCerts
genChannelArtifacts
elif [ "$MODE" == "clean" ]; then
cleanFiles
elif [ "$MODE" == "addorg" ]; then
addOrg
else
printHelp
exit 1
fi
cd ..