2
0

gen_config.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #! /bin/bash
  2. # Generating
  3. # * crypto-config/*
  4. # * channel-artifacts
  5. # * orderer.genesis.block
  6. # * channel.tx
  7. # * Org1MSPanchors.tx
  8. # * Org2MSPanchors.tx
  9. if [ -f ./func.sh ]; then
  10. source ./func.sh
  11. elif [ -f scripts/func.sh ]; then
  12. source scripts/func.sh
  13. else
  14. echo "Cannot find the func.sh files, pls check"
  15. exit 1
  16. fi
  17. [ $# -ne 1 ] && echo_r "[Usage] $0 solo|kafka" && exit 1 || MODE=$1
  18. echo_b "Generating artifacts for ${MODE}"
  19. echo_b "Clean existing container $GEN_CONTAINER"
  20. [ "$(docker ps -a | grep $GEN_CONTAINER)" ] && docker rm -f $GEN_CONTAINER
  21. pushd ${MODE}
  22. echo_b "Check whether crypto-config exist already"
  23. GEN_CRYPTO=true
  24. if [ -d ${CRYPTO_CONFIG} ]; then # already exist, no need to re-gen crypto
  25. echo_b "${CRYPTO_CONFIG} existed, won't regenerate it."
  26. GEN_CRYPTO=false
  27. else
  28. echo_b "${CRYPTO_CONFIG} not exists, generate later."
  29. mkdir -p ${CRYPTO_CONFIG}
  30. fi
  31. echo_b "Make sure channel-artifacts dir exists already"
  32. if [ ! -d ${CHANNEL_ARTIFACTS} ]; then
  33. echo_b "${CHANNEL_ARTIFACTS} not exists, create it."
  34. mkdir -p ${CHANNEL_ARTIFACTS}
  35. fi
  36. echo_b "Starting container $GEN_CONTAINER in background"
  37. docker run \
  38. -d -it \
  39. --name $GEN_CONTAINER \
  40. -e "CONFIGTX_LOGGING_LEVEL=DEBUG" \
  41. -e "CONFIGTX_LOGGING_FORMAT=%{color}[%{id:03x} %{time:01-02 15:04:05.00 MST}] [%{longpkg}] %{callpath} -> %{level:.4s}%{color:reset} %{message}" \
  42. -v $PWD/configtx.yaml:${FABRIC_CFG_PATH}/configtx.yaml \
  43. -v $PWD/crypto-config.yaml:${FABRIC_CFG_PATH}/crypto-config.yaml \
  44. -v $PWD/${CRYPTO_CONFIG}:${FABRIC_CFG_PATH}/${CRYPTO_CONFIG} \
  45. -v $PWD/${CHANNEL_ARTIFACTS}:/tmp/${CHANNEL_ARTIFACTS} \
  46. ${GEN_IMG} bash -c 'while true; do sleep 20171001; done'
  47. if [ "${GEN_CRYPTO}" = "true" ]; then
  48. echo_b "Generating crypto-config"
  49. gen_con_exec cryptogen generate --config=$FABRIC_CFG_PATH/crypto-config.yaml --output ${FABRIC_CFG_PATH}/${CRYPTO_CONFIG}
  50. fi
  51. echo_b "Generate genesis block for system channel using configtx.yaml"
  52. [ -f ${CHANNEL_ARTIFACTS}/${ORDERER_GENESIS} ] || gen_con_exec configtxgen -profile ${ORDERER_PROFILE} -outputBlock /tmp/${CHANNEL_ARTIFACTS}/${ORDERER_GENESIS}
  53. echo_b "Create the new app channel tx using configtx.yaml"
  54. [ -f ${CHANNEL_ARTIFACTS}/${APP_CHANNEL_TX} ] || gen_con_exec configtxgen -profile TwoOrgsChannel -outputCreateChannelTx /tmp/$CHANNEL_ARTIFACTS/${APP_CHANNEL_TX} -channelID ${APP_CHANNEL}
  55. echo_b "Create the anchor peer configuration tx using configtx.yaml"
  56. [ -f ${CHANNEL_ARTIFACTS}/${UPDATE_ANCHOR_ORG1_TX} ] || gen_con_exec configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate /tmp/${CHANNEL_ARTIFACTS}/${UPDATE_ANCHOR_ORG1_TX} -channelID ${APP_CHANNEL} -asOrg Org1MSP
  57. [ -f ${CHANNEL_ARTIFACTS}/${UPDATE_ANCHOR_ORG2_TX} ] || gen_con_exec configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate /tmp/${CHANNEL_ARTIFACTS}/${UPDATE_ANCHOR_ORG2_TX} -channelID ${APP_CHANNEL} -asOrg Org2MSP
  58. echo_b "Remove the container $GEN_CONTAINER" && docker rm -f $GEN_CONTAINER
  59. echo_g "Generated artifacts for ${MODE}"