-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade.sh
executable file
·248 lines (219 loc) · 6.96 KB
/
upgrade.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
source ./.env
export PATH=${PWD}/bin:${PWD}:$PATH
# FUNCTION TO CHECK RESULTS
function checkResult(){
res=$?
if [ $res -ne 0 ]
then
echo "!!!!! ERROR !!!!!"
if [ "${IGNORE_ERRORS}" != "true" ]; then
exit 1
fi
else
echo "----- SUCCESS -----"
echo
fi
}
# FUNCTION TO PRINT HELP
function printhelp(){
echo
echo "Usage:"
echo " upgrade.sh [-n <name>] [-l <lable>] [-v <version>] [-s <sequence>] [-p <path>] [-h]"
echo " -v <version> - Version of The chaincode"
echo " -s <sequence> - sequence of chaincodes"
echo " -p <path> - Path inside the container"
echo " -n <name> - Name of the Chaincode"
echo " -l <lable> - Lable to be given"
echo " -h - Get Help"
echo
echo " Without any options it will run with defaults."
echo
exit 0
}
while getopts "h?n:l:v:s:p:" opt; do
case "$opt" in
h | \?)
printhelp
;;
n)
CC_NAME=$OPTARG
;;
l)
CC_LABLE=$OPTARG
;;
v)
CC_VERSION=$OPTARG
;;
s)
CC_SEQUENCE=$OPTARG
;;
p)
CC_SRC_PATH=$OPTARG
esac
done
CONFIG_ROOT=/root/crypto
#----------------------------------#
ORG1_MSPCONFIGPATH=${CONFIG_ROOT}/peerOrganizations/org1.eapproval.com/users/Admin@org1.eapproval.com/msp
ORG2_MSPCONFIGPATH=${CONFIG_ROOT}/peerOrganizations/org2.eapproval.com/users/Admin@org2.eapproval.com/msp
ORG1_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/peerOrganizations/org1.eapproval.com/peers/peer0.org1.eapproval.com/tls/ca.crt
ORG2_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/peerOrganizations/org2.eapproval.com/peers/peer0.org2.eapproval.com/tls/ca.crt
#----------------------------------#
DEFAULT_ORDERER=orderer.eapproval.com:7050
ORDERER_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/ordererOrganizations/eapproval.com/orderers/orderer.eapproval.com/msp/tlscacerts/tlsca.eapproval.com-cert.pem
#----------------------------------#
PEER0_ORG1="docker exec
-e CORE_PEER_LOCALMSPID=Org1MSP
-e CORE_PEER_ADDRESS=peer0.org1.eapproval.com:7051
-e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH}
-e CORE_PEER_TLS_ROOTCERT_FILE=${ORG1_TLS_ROOTCERT_FILE}
cli
peer
--tls=true
--cafile=${ORDERER_TLS_ROOTCERT_FILE}
--orderer=${DEFAULT_ORDERER}
"
PEER0_ORG2="docker exec
-e CORE_PEER_LOCALMSPID=Org2MSP
-e CORE_PEER_ADDRESS=peer0.org2.eapproval.com:9051
-e CORE_PEER_MSPCONFIGPATH=${ORG2_MSPCONFIGPATH}
-e CORE_PEER_TLS_ROOTCERT_FILE=${ORG2_TLS_ROOTCERT_FILE}
cli
peer
--tls=true
--cafile=${ORDERER_TLS_ROOTCERT_FILE}
--orderer=${DEFAULT_ORDERER}
"
# echo "Vendoring Go dependencies ..."
# pushd ./configs/chaincode/fabcar2/go
# GO111MODULE=on go mod vendor
# popd
# echo
echo
echo "##############################################################"
echo "####### PACKAGING CHAINCODE ON peer0.org1.eapproval.com ########"
echo "##############################################################"
${PEER0_ORG1} lifecycle chaincode package \
${CC_NAME}.tar.gz \
--path "${CC_SRC_PATH}" \
--lang "${CC_RUNTIME_LANGUAGE}" \
--label ${CC_LABLE}
checkResult
echo
echo
echo "##############################################################"
echo "####### INSTALLING CHAINCODE ON peer0.org1.eapproval.com #######"
echo "##############################################################"
${PEER0_ORG1} lifecycle chaincode install \
${CC_NAME}.tar.gz
checkResult
echo
REGEX="Package ID: ${CC_LABLE}:(.*), Label: ${CC_LABLE}"
if [[ `${PEER0_ORG1} lifecycle chaincode queryinstalled` =~ $REGEX ]]; then
PACKAGE_ID_ORG1=${CC_LABLE}:${BASH_REMATCH[1]}
echo $PACKAGE_ID_ORG1
else
echo Could not find package ID for ${CC_LABLE} chaincode on peer0.org1.eapproval.com
exit 1
fi
echo
echo "########################################################"
echo "####### APPROVING CHAINCODE DEFINITION FOR ORG1 ########"
echo "########################################################"
${PEER0_ORG1} lifecycle chaincode approveformyorg \
--package-id ${PACKAGE_ID_ORG1} \
--channelID mychannel \
--name ${CC_NAME} \
--version ${CC_VERSION} \
--signature-policy "AND('Org1MSP.member','Org2MSP.member')" \
--sequence ${CC_SEQUENCE} \
--waitForEvent
checkResult
echo
echo
echo "##############################################################"
echo "####### PACKAGING CHAINCODE ON peer0.org2.eapproval.com ########"
echo "##############################################################"
${PEER0_ORG2} lifecycle chaincode package \
${CC_NAME}.tar.gz \
--path "$CC_SRC_PATH" \
--lang "$CC_RUNTIME_LANGUAGE" \
--label ${CC_LABLE}
checkResult
echo
echo
echo "##############################################################"
echo "####### INSTALLING CHAINCODE ON peer0.org2.eapproval.com #######"
echo "##############################################################"
${PEER0_ORG2} lifecycle chaincode install ${CC_NAME}.tar.gz
checkResult
echo
REGEX="Package ID: ${CC_LABLE}:(.*), Label: ${CC_LABLE}"
if [[ `${PEER0_ORG2} lifecycle chaincode queryinstalled` =~ $REGEX ]]; then
PACKAGE_ID_ORG2=${CC_LABLE}:${BASH_REMATCH[1]}
echo $PACKAGE_ID_ORG2
else
echo Could not find package ID for ${CC_LABLE} chaincode on peer0.org2.eapproval.com
exit 1
fi
echo
echo "########################################################"
echo "####### APPROVING CHAINCODE DEFINITION FOR ORG2 ########"
echo "########################################################"
${PEER0_ORG2} lifecycle chaincode approveformyorg \
--package-id ${PACKAGE_ID_ORG2} \
--channelID mychannel \
--name ${CC_NAME} \
--version ${CC_VERSION} \
--signature-policy "AND('Org1MSP.member','Org2MSP.member')" \
--sequence ${CC_SEQUENCE} \
--waitForEvent
checkResult
echo
sleep 2
echo
echo "################################################"
echo "####### COMMITING CHAINCODE DEFINITION ########"
echo "################################################"
${PEER0_ORG1} lifecycle chaincode commit \
--channelID mychannel \
--name ${CC_NAME} \
--version ${CC_VERSION} \
--signature-policy "AND('Org1MSP.member','Org2MSP.member')" \
--sequence ${CC_SEQUENCE} \
--waitForEvent \
--peerAddresses peer0.org1.eapproval.com:7051 \
--peerAddresses peer0.org2.eapproval.com:9051 \
--tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE} \
--tlsRootCertFiles ${ORG2_TLS_ROOTCERT_FILE}
checkResult
echo
echo
echo "######################################################"
echo "####### INVOKING INIT IN CHAINCODE DEFINITION ########"
echo "######################################################"
${PEER0_ORG1} chaincode invoke \
-C mychannel \
-n ${CC_NAME} \
-c '{"function":"initLedger","Args":[]}' \
--waitForEvent \
--waitForEventTimeout 300s \
--peerAddresses peer0.org1.eapproval.com:7051 \
--peerAddresses peer0.org2.eapproval.com:9051 \
--tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE} \
--tlsRootCertFiles ${ORG2_TLS_ROOTCERT_FILE}
checkResult
echo
echo
echo "###################################"
echo "####### QUERYING CHAINCODE ########"
echo "###################################"
${PEER0_ORG1} chaincode query \
-C mychannel \
-n ${CC_NAME} \
-c '{"function":"getTotalRequests","Args":[]}' \
--peerAddresses peer0.org1.eapproval.com:7051 \
--tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE}
checkResult
echo
# ${PEER0_ORG1} lifecycle chaincode queryinstalled
# ${PEER0_ORG2} lifecycle chaincode queryinstalled