-
Notifications
You must be signed in to change notification settings - Fork 10
/
gen_configtx_cfg.sh
executable file
·353 lines (305 loc) · 9.88 KB
/
gen_configtx_cfg.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
#
# usage: ./gen_configtx_cfg.sh [opt] [value]
#
HostIP1="0.0.0.0"
HostPort=7050
ordererPort=5005
kafkaPort=9092
peerPort=7061
function printHelp {
echo "Usage: "
echo " ./gen_configtx_cfg.sh [opt] [value] "
echo " -o: number of orderers, default=1"
echo " -k: number of kafka, default=0"
echo " -p: number of peers per organization, default=1"
echo " -h: hash type, default=SHA2"
echo " -r: number of organization, default=1"
echo " -s: security service type, default=256"
echo " -t: orderer service [solo|kafka], default=solo"
echo " -f: profile name, default=test"
echo " -b: MSP directory, default=$GOPATH/src/github.com/hyperledger/fabric-test/fabric/common/tools/cryptogen/crypto-config"
echo " -w: host ip 1, default=0.0.0.0"
echo " -c: batch timeout, default=2s"
echo " -B: batch size, default=10"
echo " -v: array of organization name, default=0"
echo " -C: company name, default=example.com"
echo " "
echo "Example:"
echo " ./gen_configtx_cfg.sh -o 1 -k 1 -p 2 -r 2 -h SHA2 -s 256 -t kafka -b $GOPATH/src/github.com/hyperledger/fabric-test/fabric/common/tools/cryptogen/crypto-config -w 10.120.223.35 -v 1 -v 3"
exit
}
function getIP {
ik=0
io=0
ip=0
while IFS= read line
do
t1=$(echo $line | awk '{print $1}')
t2=$(echo $line | awk '{print $2}')
t3=$(echo $line | awk '{print $3}')
#echo " $t1 $t2 $t3"
if [ "$t1" == "kafka" ]; then
ik=$[ ik + 1 ]
kafkaIP[$ik]=$t2
kafkaPort[$ik]=$t3
elif [ "$t1" == "orderer" ]; then
io=$[ io + 1 ]
ordererIP[$io]=$t2
ordererPort[$io]=$t3
elif [ "$t1" == "peer" ]; then
ip=$[ ip + 1 ]
peerIP[$ip]=$t2
peerPort[$ip]=$t3
fi
done < input.txt
for (( i=1; i <= ${#kafkaIP[@]}; i++ ))
do
echo "Kafka: ${kafkaIP[$i]}: ${kafkaPort[$i]}"
done
for (( i=1; i <= ${#ordererIP[@]}; i++ ))
do
echo "orderer: ${ordererIP[$i]}: ${ordererPort[$i]}"
done
for (( i=1; i <= ${#peerIP[@]}; i++ ))
do
echo "peer: ${peerIP[$i]}: ${peerPort[$i]}"
done
}
####getIP
CWD=$PWD
#default vars
inFile=$CWD"/configtx.yaml-in"
cfgOutFile=$CWD"/configtx.yaml"
nOrderer=1
nKafka=0
ordServType="solo"
SecTypenOrderer=1
nOrg=1
peersPerOrg=1
hashType="SHA2"
SecType="256"
PROFILE_STRING="test"
MSPBaseDir=$GOPATH"/src/github.com/hyperledger/fabric-test/fabric/common/tools/cryptogen/crypto-config"
comName="example.com"
batchTimeOut="2s"
batchSize=10
k=0
while getopts ":o:k:p:s:h:r:t:f:b:w:v:c:B:C:" opt; do
case $opt in
# number of orderers
o)
nOrderer=$OPTARG
echo "nOrderer: $nOrderer"
;;
# number of kafka
k)
nKafka=$OPTARG
echo "nKafka: $nKafka"
;;
# number of peers
p)
peersPerOrg=$OPTARG
echo "peersPerOrg: $peersPerOrg"
;;
h)
hashType=$OPTARG
echo "hashType: $hashType"
;;
r)
nOrg=$OPTARG
echo "nOrg: $nOrg"
;;
s)
SecType=$OPTARG
echo "SecType: $SecType"
;;
t)
ordServType=$OPTARG
echo "ordServType: $ordServType"
;;
f)
PROFILE_STRING=$OPTARG
echo "PROFILE_STRING: $PROFILE_STRING"
;;
b)
MSPBaseDir=$OPTARG
echo "MSPBaseDir: $MSPBaseDir"
;;
w)
HostIP1=$OPTARG
KafkaAIP=$OPTARG
peerIP=$OPTARG
echo "HostIP1: $HostIP1"
;;
v)
k=$[ k + 1 ]
OrgArray[$k]=$OPTARG
echo "k: $k, ${#OrgArray[@]}, OrgArray=${OrgArray[@]}"
;;
c)
batchTimeOut=$OPTARG
echo "batchTimeOut: $batchTimeOut"
;;
B)
batchSize=$OPTARG
echo "batchSize: $batchSize"
;;
C)
comName=$OPTARG
echo "comName: $comName"
;;
# else
\?)
echo "Invalid option: -$OPTARG" >&2
printHelp
;;
:)
echo "Option -$OPTARG requires an argument." >&2
printHelp
;;
esac
done
echo "nOrderer=$nOrderer, peersPerOrg=$peersPerOrg, ordServType=$ordServType, nOrg=$nOrg, hashType=$hashType, SecType=$SecType"
echo "MSPBaseDir=$MSPBaseDir"
echo "Host IP=$HostIP1, Port=$HostPort"
echo "Kafka IP=$KafkaAIP, $KafkaBIP, $KafkaCIP"
echo "inFile=$inFile"
echo "cfgOutFile=$cfgOutFile"
echo "OrgArray length=${#OrgArray[@]}, OrgArray=${OrgArray[@]}"
# sanity check on OrgArray
if (( ${#OrgArray[@]} > $nOrg )); then
echo "invalid number of org "
exit
elif [ ${#OrgArray[@]} = 0 ]; then
for (( i=1; i <= $nOrg; i++ ))
do
OrgArray[$i]=$i
done
fi
#echo "after loop OrgArray length=${#OrgArray[@]}, OrgArray=${OrgArray[@]}"
#begin process
#remove existing cfgOutFile
rm -f $cfgOutFile
#begin process
while IFS= read line
do
t1=$(echo $line | awk '{print $1}')
t2=$(echo $line | awk '{print $2}')
#echo "$line"
#echo "t1:t2=$t1:$t2"
#Profiles
if [ "$t2" == "*PeerOrg" ]; then
for (( i=1; i<=${#OrgArray[@]}; i++ ))
do
tmp=${OrgArray[$i]}
echo " - $t2$tmp" >> $cfgOutFile
done
elif [ "$t1" == "OrdererType:" ]; then
echo " $t1 $ordServType" >> $cfgOutFile
elif [ "$t1" == "&ProfileOrderString" ]; then
tmp=$PROFILE_STRING"OrgsOrdererGenesis"
echo " $tmp:" >> $cfgOutFile
elif [ "$t1" == "&ProfileOrgString" ]; then
tmp=$PROFILE_STRING"orgschannel"
echo " $tmp:" >> $cfgOutFile
elif [ "$t1" == "Addresses:" ]; then
echo "$line" >> $cfgOutFile
#echo " - $peerIP":"$ordererPort, $peerIP":"$[ ordererPort + 1 ], $peerIP":"$[ ordererPort + 2 ]" >> $cfgOutFile
#tmp="orderer1."$comName":"$ordererPort
tmpPort=$ordererPort
for (( i=1; i<=$nOrderer; i++ ))
do
j=$[ i - 1 ]
tmpAddr="orderer"$j"."$comName
tmp=$tmpAddr":7050"
echo " - $tmp" >> $cfgOutFile
done
elif [ "$t1" == "Brokers:" ]; then
echo " $t1" >> $cfgOutFile
for (( i=0; i<$nKafka; i++ ))
do
echo " - kafka"$i":"$kafkaPort >> $cfgOutFile
done
elif [ "$t1" == "BatchTimeout:" ]; then
echo " $t1 $batchTimeOut" >> $cfgOutFile
elif [ "$t1" == "MaxMessageCount:" ]; then
echo " $t1 $batchSize" >> $cfgOutFile
elif [ "$t2" == "*OrdererOrg" ]; then
echo "*OrdererOrg ... "
#Save this idea for later; the cryptogen tool version only supports one OrdererOrg for now.
#for (( i=1; i<=$nOrderer; i++ ))
for (( i=1; i<=1; i++ ))
do
echo " - $t2" >> $cfgOutFile
#echo " - $t2$i" >> $cfgOutFile
done
elif [ "$t2" == "&OrdererOrg" ]; then
echo "&OrdererOrg ... "
#Save this idea for later; the cryptogen tool version only supports one OrdererOrg for now.
#We will have to figure out which Orderers are in which Orgs - the same way cryptogen does it.
#for (( i=1; i<=$nOrderer; i++ ))
for (( i=1; i<=1; i++ ))
do
j=$[ peersPerOrg * ( i - 1 ) + 1 ]
#tmp="OrdererOrg"$i
tmp="OrdererOrg"
tt="Orderer"$i"MSP"
echo " - &$tmp" >> $cfgOutFile
echo " Name: $tmp" >> $cfgOutFile
echo " ID: $tmp" >> $cfgOutFile
#echo " ID: $tt" >> $cfgOutFile
ordDir=$MSPBaseDir"/ordererOrganizations/"$comName"/msp"
echo " MSPDir: $ordDir" >> $cfgOutFile
echo " #AdminPrincipal: Role.MEMBER" >> $cfgOutFile
echo "" >> $cfgOutFile
# echo " BCCSP:" >> $cfgOutFile
# echo " Default: SW" >> $cfgOutFile
# echo " SW:" >> $cfgOutFile
# echo " Hash: $hashType" >> $cfgOutFile
# echo " Security: $SecType" >> $cfgOutFile
# echo " FileKeyStore:" >> $cfgOutFile
# echo " KeyStore:" >> $cfgOutFile
echo "" >> $cfgOutFile
done
elif [ "$t2" == "&PeerOrg" ]; then
for (( i=1; i<=$nOrg; i++ ))
do
j=$[ peersPerOrg * ( i - 1 ) + 1 ]
tt="PeerOrg"$i
echo " - &$tt" >> $cfgOutFile
tmp="Peer"$i"MSP"
echo " Name: $tt" >> $cfgOutFile
echo " ID: $tt" >> $cfgOutFile
#echo " ID: $tmp" >> $cfgOutFile
peerDir=$MSPBaseDir"/peerOrganizations/org"$i"."$comName"/msp"
echo " MSPDir: $peerDir" >> $cfgOutFile
echo " #AdminPrincipal: Role.MEMBER" >> $cfgOutFile
echo "" >> $cfgOutFile
# echo " BCCSP:" >> $cfgOutFile
# echo " Default: SW" >> $cfgOutFile
# echo " SW:" >> $cfgOutFile
# echo " Hash: $hashType" >> $cfgOutFile
# echo " Security: $SecType" >> $cfgOutFile
# echo " FileKeyStore:" >> $cfgOutFile
# echo " KeyStore:" >> $cfgOutFile
echo "" >> $cfgOutFile
#tmpPort=$[ HostPort + peersPerOrg * ( i - 1 ) ]
#tmpPort=$[ peerPort + peersPerOrg * ( i - 1 ) ]
tmpPort=7051
tmpHost="peer0.org"$i"."$comName
echo " AnchorPeers:" >> $cfgOutFile
echo " - Host: $tmpHost" >> $cfgOutFile
echo " Port: $tmpPort" >> $cfgOutFile
echo "" >> $cfgOutFile
done
else
echo "$line" >> $cfgOutFile
fi
done < "$inFile"
exit