github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/examples/e2e_cli/generateArtifacts.sh (about) 1 #!/bin/bash +x 2 # 3 # Copyright IBM Corp. All Rights Reserved. 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 8 9 #set -e 10 11 CHANNEL_NAME=$1 12 : ${CHANNEL_NAME:="mychannel"} 13 echo $CHANNEL_NAME 14 15 export FABRIC_ROOT=$PWD/../.. 16 export FABRIC_CFG_PATH=$PWD 17 echo 18 19 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)}') 20 21 ## Using docker-compose template replace private key file names with constants 22 function replacePrivateKey () { 23 ARCH=`uname -s | grep Darwin` 24 if [ "$ARCH" == "Darwin" ]; then 25 OPTS="-it" 26 else 27 OPTS="-i" 28 fi 29 30 cp docker-compose-e2e-template.yaml docker-compose-e2e.yaml 31 32 CURRENT_DIR=$PWD 33 cd crypto-config/peerOrganizations/org1.example.com/ca/ 34 PRIV_KEY=$(ls *_sk) 35 cd $CURRENT_DIR 36 sed $OPTS "s/CA1_PRIVATE_KEY/${PRIV_KEY}/g" docker-compose-e2e.yaml 37 cd crypto-config/peerOrganizations/org2.example.com/ca/ 38 PRIV_KEY=$(ls *_sk) 39 cd $CURRENT_DIR 40 sed $OPTS "s/CA2_PRIVATE_KEY/${PRIV_KEY}/g" docker-compose-e2e.yaml 41 } 42 43 ## Generates Org certs using cryptogen tool 44 function generateCerts (){ 45 CRYPTOGEN=$FABRIC_ROOT/release/$OS_ARCH/bin/cryptogen 46 47 if [ -f "$CRYPTOGEN" ]; then 48 echo "Using cryptogen -> $CRYPTOGEN" 49 else 50 echo "Building cryptogen" 51 make -C $FABRIC_ROOT release 52 fi 53 54 echo 55 echo "##########################################################" 56 echo "##### Generate certificates using cryptogen tool #########" 57 echo "##########################################################" 58 $CRYPTOGEN generate --config=./crypto-config.yaml 59 echo 60 } 61 62 ## Generate orderer genesis block , channel configuration transaction and anchor peer update transactions 63 function generateChannelArtifacts() { 64 65 CONFIGTXGEN=$FABRIC_ROOT/release/$OS_ARCH/bin/configtxgen 66 if [ -f "$CONFIGTXGEN" ]; then 67 echo "Using configtxgen -> $CONFIGTXGEN" 68 else 69 echo "Building configtxgen" 70 make -C $FABRIC_ROOT release 71 fi 72 73 echo "##########################################################" 74 echo "######### Generating Orderer Genesis block ##############" 75 echo "##########################################################" 76 # Note: For some unknown reason (at least for now) the block file can't be 77 # named orderer.genesis.block or the orderer will fail to launch! 78 $CONFIGTXGEN -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block 79 80 echo 81 echo "#################################################################" 82 echo "### Generating channel configuration transaction 'channel.tx' ###" 83 echo "#################################################################" 84 $CONFIGTXGEN -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME 85 86 echo 87 echo "#################################################################" 88 echo "####### Generating anchor peer update for Org1MSP ##########" 89 echo "#################################################################" 90 $CONFIGTXGEN -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP 91 92 echo 93 echo "#################################################################" 94 echo "####### Generating anchor peer update for Org2MSP ##########" 95 echo "#################################################################" 96 $CONFIGTXGEN -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP 97 echo 98 } 99 100 generateCerts 101 replacePrivateKey 102 generateChannelArtifacts 103