-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
102 lines (82 loc) · 3.79 KB
/
deploy.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
#!/bin/bash
# add your chaincode names into this array, and run the code to install all of them
export CHAINCODES=("fabcar" "fabcar2")
# set the folder name (project name) before run
export PROJNAME=fabcar
export CC_VERSION=1.0
export CC_SEQ=1
export PATH=${PWD}/../bin:$PATH
export FABRIC_CFG_PATH=$PWD/../config/
export CC_NAME=""
export CORE_PEER_LOCALMSPID=""
export FABRIC_CFG_PATH=""
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_TLS_ROOTCERT_FILE=""
export CORE_PEER_MSPCONFIGPATH=""
export CORE_PEER_ADDRESS=""
function run() {
peer version
setOrg1
packageForOrgs
installOnOrg
setOrg2
installOnOrg
setPackageID
echo "Packag ID: ${CC_PACKAGE_ID}"
for chaincode in "${arr[@]}"
do
CC_NAME=${chaincode}
echo "Installing ${CC_NAME}"
setOrg1
approveForMyOrg
setOrg2
approveForMyOrg
commitAndCheck
done
}
function setOrg1() {
CORE_PEER_LOCALMSPID="Org1MSP"
FABRIC_CFG_PATH=${PWD}/../config/
CORE_PEER_TLS_ENABLED=true
CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
CORE_PEER_ADDRESS=localhost:7051
}
function setOrg2() {
CORE_PEER_LOCALMSPID="Org2MSP"
FABRIC_CFG_PATH=${PWD}/../config/
CORE_PEER_TLS_ENABLED=true
CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp
CORE_PEER_ADDRESS=localhost:9051
}
function setPackageID() {
CC_PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | jq -r '.installed_chaincodes[0].package_id')
}
function packageForOrgs() {
peer lifecycle chaincode package ${PROJNAME}.tar.gz --path ../chaincode/${PROJNAME}/javascript/ --lang node --label ${PROJNAME}_1
}
function installOnOrg() {
peer lifecycle chaincode install ${PROJNAME}.tar.gz
}
function approveForMyOrg() {
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name $CC_NAME --version $CC_VERSION --package-id $CC_PACKAGE_ID --sequence $CC_SEQ --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
}
function commitAndCheck() {
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name $CC_NAME --version $CC_VERSION --sequence $CC_SEQ --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --output json
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name $CC_NAME --version $CC_VERSION --sequence $CC_SEQ --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
peer lifecycle chaincode querycommitted --channelID mychannel --name $CC_NAME --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
}
## Parse mode
if [[ $# -lt 1 ]] ; then
echo "Add run to execute your command"
exit 0
else
MODE=$1
shift
fi
if [ "${MODE}" == "run" ]; then
run
else
exit 1
fi