Created
March 26, 2020 06:42
-
-
Save rtang03/3e50e62d7884fb0cdcc12fc6fc1f32e6 to your computer and use it in GitHub Desktop.
The install cc script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
############## | |
# Environments | |
############## | |
export RED='\033[0;31m' | |
export GREEN='\033[0;32m' | |
export YELLOW='\033[0;33m' | |
export NC='\033[0m' | |
############## | |
# Functions | |
############## | |
print() { | |
MESSAGE=$1 | |
CODE=$2 | |
if [ $2 -ne 0 ] ; then | |
printf "${RED}[`date +"%Y-%m-%d %H:%M:%S"`] ${MESSAGE} failed${NC}\n" | |
exit -1 | |
fi | |
printf "${GREEN}[`date +"%Y-%m-%d %H:%M:%S"`] Complete ${MESSAGE}${NC}\n\n" | |
sleep 1 | |
} | |
subject() { | |
printf "${YELLOW}" | |
echo '' | |
echo '####' | |
echo '#### ' $1 | |
# echo '#### '[`date +"%Y-%m-%d %H:%M:%S"`] | |
echo '####' | |
echo '' | |
printf "${NC}" | |
} | |
############################# | |
# Build # | |
############################# | |
# | |
subject "Build Chaincode..." | |
# | |
cd chaincode/fabcar | |
#yarn install | |
yarn build | |
print "build fabcar" $? | |
#cd ../op | |
#yarn install | |
#yarn build | |
#print "build op" $? | |
############################# | |
# Package # | |
############################# | |
# | |
subject "Package Chaincode..." | |
# | |
# Package fabcar | |
docker exec \ | |
cli peer lifecycle chaincode package fabcar_1.0.tar.gz --path /opt/gopath/src/github.com/hyperledger/fabric/chaincode/fabcar --lang node --label fabcar_1.0 | |
print "package fabcar" $? | |
############################# | |
# Install # | |
############################# | |
# | |
subject "Install Chaincode..." | |
# | |
# Install fabcar on PccH peer0 | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer0.pcch.net:7051" \ | |
-e "CORE_PEER_LOCALMSPID=PccHMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/PccHMSP/peer0.pcch.net/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/PccHMSP/admin/msp" \ | |
cli peer lifecycle chaincode install fabcar_1.0.tar.gz --peerAddresses peer0.pcch.net:7051 \ | |
--tlsRootCertFiles /var/artifacts/crypto-config/PccHMSP/peer0.pcch.net/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem >& log.txt | |
print "install fabcar on PccH peer0" $? | |
# Extract package ID for fabcar on PccH peer0 | |
PACID_fabcar=$(tail -n 1 "log.txt" | sed 's/.*Chaincode code package identifier: //') | |
printf "${GREEN}Package ID: $PACID_fabcar${NC}\n\n" | |
# List chaincodes on PccH peer0 | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer0.pcch.net:7051" \ | |
-e "CORE_PEER_LOCALMSPID=PccHMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/PccHMSP/peer0.pcch.net/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/PccHMSP/admin/msp" \ | |
cli peer lifecycle chaincode queryinstalled | |
print "list chaincodes on PccH peer0" $? | |
# Install fabcar on PccH peer1 | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer1.pcch.net:7151" \ | |
-e "CORE_PEER_LOCALMSPID=PccHMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/PccHMSP/peer1.pcch.net/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/PccHMSP/admin/msp" \ | |
cli peer lifecycle chaincode install fabcar_1.0.tar.gz --peerAddresses peer1.pcch.net:7151 \ | |
--tlsRootCertFiles /var/artifacts/crypto-config/PccHMSP/peer1.pcch.net/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem >& log.txt | |
print "install fabcar on PccH peer1" $? | |
# Extract package ID for fabcar on PccH peer1 | |
PACID_fabcar=$(tail -n 1 "log.txt" | sed 's/.*Chaincode code package identifier: //') | |
printf "${GREEN}Package ID: $PACID_fabcar${NC}\n\n" | |
# List chaincodes on PccH peer1 | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer1.pcch.net:7151" \ | |
-e "CORE_PEER_LOCALMSPID=PccHMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/PccHMSP/peer1.pcch.net/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/PccHMSP/admin/msp" \ | |
cli peer lifecycle chaincode queryinstalled | |
print "list chaincodes on PccH peer1" $? | |
# Install fabcar on WakandaGov peer0 | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer0.gov.wakanda:7251" \ | |
-e "CORE_PEER_LOCALMSPID=WakandaGovMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/WakandaGovMSP/peer0.gov.wakanda/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/WakandaGovMSP/admin/msp" \ | |
cli peer lifecycle chaincode install fabcar_1.0.tar.gz --peerAddresses peer0.gov.wakanda:7251 \ | |
--tlsRootCertFiles /var/artifacts/crypto-config/WakandaGovMSP/peer0.gov.wakanda/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem >& log.txt | |
print "install fabcar on WakandaGov peer0" $? | |
# Extract package ID for fabcar on WakandaGov peer0 | |
PACID_fabcar=$(tail -n 1 "log.txt" | sed 's/.*Chaincode code package identifier: //') | |
printf "${GREEN}Package ID: $PACID_fabcar${NC}\n\n" | |
# List chaincodes on WakandaGov peer0 | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer0.gov.wakanda:7251" \ | |
-e "CORE_PEER_LOCALMSPID=WakandaGovMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/WakandaGovMSP/peer0.gov.wakanda/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/WakandaGovMSP/admin/msp" \ | |
cli peer lifecycle chaincode queryinstalled | |
print "list chaincodes on WakandaGov peer0" $? | |
# Install fabcar on WakandaGov peer1 | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer1.gov.wakanda:7351" \ | |
-e "CORE_PEER_LOCALMSPID=WakandaGovMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/WakandaGovMSP/peer1.gov.wakanda/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/WakandaGovMSP/admin/msp" \ | |
cli peer lifecycle chaincode install fabcar_1.0.tar.gz --peerAddresses peer1.gov.wakanda:7351 \ | |
--tlsRootCertFiles /var/artifacts/crypto-config/WakandaGovMSP/peer1.gov.wakanda/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem >& log.txt | |
print "install fabcar on WakandaGov peer1" $? | |
# Extract package ID for fabcar on WakandaGov peer1 | |
PACID_fabcar=$(tail -n 1 "log.txt" | sed 's/.*Chaincode code package identifier: //') | |
printf "${GREEN}Package ID: $PACID_fabcar${NC}\n\n" | |
# List chaincodes on WakandaGov peer1 | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer1.gov.wakanda:7351" \ | |
-e "CORE_PEER_LOCALMSPID=WakandaGovMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/WakandaGovMSP/peer1.gov.wakanda/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/WakandaGovMSP/admin/msp" \ | |
cli peer lifecycle chaincode queryinstalled | |
print "list chaincodes on WakandaGov peer1" $? | |
############################# | |
# Approve # | |
############################# | |
# | |
subject "Approve Chaincode..." | |
# | |
# Approve fabcar on PccH peer0 | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer0.pcch.net:7051" \ | |
-e "CORE_PEER_LOCALMSPID=PccHMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/PccHMSP/peer0.pcch.net/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/PccHMSP/admin/msp" \ | |
cli peer lifecycle chaincode approveformyorg \ | |
--tls --cafile /var/artifacts/crypto-config/CBodyMSP/orderer0.cbody.com/assets/tls-ca/tls-ca-cert.pem \ | |
-o orderer0.cbody.com:7050 \ | |
--channelID genericchannel --name fabcar --version 1.0 --package-id $PACID_fabcar --waitForEvent --sequence 1 \ | |
--signature-policy "OR ('PccHMSP.member' ,'WakandaGovMSP.member')" --init-required | |
print "approve fabcar on PccH peer0" $? | |
# Check the chaincode commit readiness | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer0.pcch.net:7051" \ | |
-e "CORE_PEER_LOCALMSPID=PccHMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/PccHMSP/peer0.pcch.net/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/PccHMSP/admin/msp" \ | |
cli peer lifecycle chaincode checkcommitreadiness \ | |
--channelID genericchannel --name fabcar --version 1.0 --sequence 1 --output json \ | |
--signature-policy "OR ('PccHMSP.member' ,'WakandaGovMSP.member')" | |
# Approve fabcar on WakandaGov peer0 | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer0.gov.wakanda:7251" \ | |
-e "CORE_PEER_LOCALMSPID=WakandaGovMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/WakandaGovMSP/peer0.gov.wakanda/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/WakandaGovMSP/admin/msp" \ | |
cli peer lifecycle chaincode approveformyorg \ | |
--tls --cafile /var/artifacts/crypto-config/CBodyMSP/orderer0.cbody.com/assets/tls-ca/tls-ca-cert.pem \ | |
-o orderer0.cbody.com:7050 \ | |
--channelID genericchannel --name fabcar --version 1.0 --package-id $PACID_fabcar --waitForEvent --sequence 1 \ | |
--signature-policy "OR ('PccHMSP.member' ,'WakandaGovMSP.member')" --init-required | |
print "approve fabcar on WakandaGov peer0" $? | |
# Check the chaincode commit readiness | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer0.gov.wakanda:7251" \ | |
-e "CORE_PEER_LOCALMSPID=WakandaGovMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/WakandaGovMSP/peer0.gov.wakanda/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/WakandaGovMSP/admin/msp" \ | |
cli peer lifecycle chaincode checkcommitreadiness \ | |
--channelID genericchannel --name fabcar --version 1.0 --sequence 1 --output json \ | |
--signature-policy "OR ('PccHMSP.member' ,'WakandaGovMSP.member')" | |
############################# | |
# Commit # | |
############################# | |
# | |
subject "Commit Chaincode..." | |
# | |
# Commit fabcar on PccH peer0 | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer0.pcch.net:7051" \ | |
-e "CORE_PEER_LOCALMSPID=PccHMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/PccHMSP/peer0.pcch.net/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/PccHMSP/admin/msp" \ | |
cli peer lifecycle chaincode commit \ | |
--tls --cafile /var/artifacts/crypto-config/CBodyMSP/orderer0.cbody.com/assets/tls-ca/tls-ca-cert.pem \ | |
--peerAddresses peer0.pcch.net:7051 \ | |
--tlsRootCertFiles /var/artifacts/crypto-config/PccHMSP/peer0.pcch.net/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem \ | |
--peerAddresses peer0.gov.wakanda:7251 \ | |
--tlsRootCertFiles /var/artifacts/crypto-config/WakandaGovMSP/peer0.gov.wakanda/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem \ | |
-o orderer0.cbody.com:7050 \ | |
--channelID genericchannel --name fabcar --version 1.0 --sequence 1 \ | |
--signature-policy "OR ('PccHMSP.member' ,'WakandaGovMSP.member')" --init-required | |
print "commit fabcar on PccH peer0" $? | |
# Query the chaincode commit | |
docker exec \ | |
-e "CORE_PEER_ADDRESS=peer0.pcch.net:7051" \ | |
-e "CORE_PEER_LOCALMSPID=PccHMSP" \ | |
-e "CORE_PEER_TLS_ROOTCERT_FILE=/var/artifacts/crypto-config/PccHMSP/peer0.pcch.net/tls-msp/tlscacerts/tls-0-0-0-0-6052.pem" \ | |
-e "CORE_PEER_MSPCONFIGPATH=/var/artifacts/crypto-config/PccHMSP/admin/msp" \ | |
cli peer lifecycle chaincode querycommitted --channelID genericchannel --name fabcar --output json | |
print "query fabcar committed" $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment