-
Notifications
You must be signed in to change notification settings - Fork 7
/
generateArtifacts.sh
executable file
·145 lines (127 loc) · 4.26 KB
/
generateArtifacts.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
#!/bin/bash +x
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
#set -e
export FABRIC_ROOT=${PWD}
export FABRIC_CFG_PATH=${PWD}
echo
# Print the usage message
function printHelp () {
echo "Usage: "
echo " generateArtifacts.sh [-c <channel name>] [-d <domain name>] [-o <number of orgs]"
echo " generateArtifacts.sh -h|--help (print this message)"
echo " -c <channel name> - channel name to use (defaults to \"mychannel\")"
echo " -d <domain name> - domain name to use (defaults to \"example.com\")"
echo " -o <number of orgs> - number of organizations to use (defaults to \"2\")"
echo
echo "Taking all defaults:"
echo " generateArtifacts.sh"
}
OS_ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
## Using docker-compose template replace private key file names with constants
function replacePrivateKey () {
ARCH=`uname -s | grep Darwin`
if [ "$ARCH" == "Darwin" ]; then
OPTS="-it"
else
OPTS="-i"
fi
#cp docker-compose-e2e-template.yaml docker-compose-e2e.yaml
#cp hyperledger-swarm-template.yaml hyperledger-swarm.yaml
i=1
while [ "$i" -le "$NUM_ORGS" ]; do
CURRENT_DIR=$PWD
cd crypto-config/peerOrganizations/org${i}.${DOMAIN_NAME}/ca/
PRIV_KEY=$(ls *_sk)
cd $CURRENT_DIR
#sed $OPTS "s/CA1_PRIVATE_KEY/${PRIV_KEY}/g" docker-compose-e2e.yaml
sed $OPTS "s/CA${i}_PRIVATE_KEY/${PRIV_KEY}/g" hyperledger-ca.yaml
i=$(($i + 1))
done
}
## Generates Org certs using cryptogen tool
function generateCerts (){
CRYPTOGEN=$FABRIC_ROOT/bin/cryptogen
which $CRYPTOGEN
if [ "$?" -ne 0 ]; then
echo "cryptogen tool not found. exiting"
exit 1
fi
rm -rf ./crypto-config
echo
echo "##########################################################"
echo "##### Generate certificates using cryptogen tool #########"
echo "##########################################################"
$CRYPTOGEN generate --config=./crypto-config.yaml
if [ "$?" -ne 0 ]; then
echo "Failed to generate certificates..."
exit 1
fi
echo
}
## Generate orderer genesis block , channel configuration transaction and anchor peer update transactions
function generateChannelArtifacts() {
CONFIGTXGEN=$FABRIC_ROOT/bin/configtxgen
which $CONFIGTXGEN
if [ "$?" -ne 0 ]; then
echo "configtxgen tool not found. exiting"
exit 1
fi
# rm -rf ./channel-artifacts
echo "##########################################################"
echo "######### Generating Orderer Genesis block ##############"
echo "##########################################################"
# Note: For some unknown reason (at least for now) the block file can't be
# named orderer.genesis.block or the orderer will fail to launch!
$CONFIGTXGEN -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
if [ "$?" -ne 0 ]; then
echo "Failed to generate orderer genesis block..."
exit 1
fi
echo
echo "#################################################################"
echo "### Generating channel configuration transaction 'channel.tx' ###"
echo "#################################################################"
$CONFIGTXGEN -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
if [ "$?" -ne 0 ]; then
echo "Failed to generate channel configuration transaction..."
exit 1
fi
i=1
while [ "$i" -le "$NUM_ORGS" ]; do
echo
echo "#################################################################"
echo "####### Generating anchor peer update for Org${i}MSP ##########"
echo "#################################################################"
$CONFIGTXGEN -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org${i}MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org${i}MSP
if [ "$?" -ne 0 ]; then
echo "Failed to generate anchor peer update for Org${i}MSP..."
exit 1
fi
i=$(($i + 1))
done
}
CHANNEL_NAME="mychannel"
DOMAIN_NAME="example.com"
NUM_ORGS=2
# Parse commandline args
while getopts "h?c:d:o:" opt; do
case "$opt" in
h|\?)
printHelp
exit 0
;;
c) CHANNEL_NAME=$OPTARG
;;
d) DOMAIN_NAME=$OPTARG
;;
o) NUM_ORGS=$OPTARG
;;
esac
done
generateCerts
replacePrivateKey
generateChannelArtifacts