2017-12-01 17:34:21 +08:00
|
|
|
#! /bin/bash
|
|
|
|
# Generating
|
2017-12-19 14:40:39 +08:00
|
|
|
# * crypto-config/*
|
2017-12-01 17:34:21 +08:00
|
|
|
# * channel-artifacts
|
|
|
|
# * orderer.genesis.block
|
|
|
|
# * channel.tx
|
|
|
|
# * Org1MSPanchors.tx
|
|
|
|
# * Org2MSPanchors.tx
|
|
|
|
|
|
|
|
if [ -f ./func.sh ]; then
|
|
|
|
source ./func.sh
|
|
|
|
elif [ -f scripts/func.sh ]; then
|
|
|
|
source scripts/func.sh
|
2017-12-19 14:40:39 +08:00
|
|
|
else
|
|
|
|
echo "Cannot find the func.sh files, pls check"
|
|
|
|
exit 1
|
2017-12-01 17:34:21 +08:00
|
|
|
fi
|
|
|
|
|
2017-12-19 14:40:39 +08:00
|
|
|
[ $# -ne 1 ] && echo_r "[Usage] $0 solo|kafka" && exit 1 || MODE=$1
|
|
|
|
|
2017-12-06 22:33:08 +08:00
|
|
|
echo_b "Generating artifacts for ${MODE}"
|
2017-12-01 17:34:21 +08:00
|
|
|
|
|
|
|
echo_b "Clean existing container $GEN_CONTAINER"
|
|
|
|
[ "$(docker ps -a | grep $GEN_CONTAINER)" ] && docker rm -f $GEN_CONTAINER
|
|
|
|
|
|
|
|
pushd ${MODE}
|
|
|
|
|
2017-12-19 14:40:39 +08:00
|
|
|
echo_b "Check whether crypto-config exist already"
|
2017-12-06 22:33:08 +08:00
|
|
|
GEN_CRYPTO=true
|
2017-12-19 14:40:39 +08:00
|
|
|
if [ -d ${CRYPTO_CONFIG} ]; then # already exist, no need to re-gen crypto
|
2017-12-06 22:33:08 +08:00
|
|
|
echo_b "${CRYPTO_CONFIG} existed, won't regenerate it."
|
|
|
|
GEN_CRYPTO=false
|
|
|
|
else
|
2017-12-19 14:40:39 +08:00
|
|
|
echo_b "${CRYPTO_CONFIG} not exists, generate later."
|
|
|
|
mkdir -p ${CRYPTO_CONFIG}
|
2017-12-06 22:33:08 +08:00
|
|
|
fi
|
|
|
|
|
2017-12-19 14:40:39 +08:00
|
|
|
echo_b "Make sure channel-artifacts dir exists already"
|
|
|
|
if [ ! -d ${CHANNEL_ARTIFACTS} ]; then
|
|
|
|
echo_b "${CHANNEL_ARTIFACTS} not exists, create it."
|
|
|
|
mkdir -p ${CHANNEL_ARTIFACTS}
|
2017-12-06 22:33:08 +08:00
|
|
|
fi
|
2017-12-01 17:34:21 +08:00
|
|
|
|
|
|
|
echo_b "Starting container $GEN_CONTAINER in background"
|
|
|
|
docker run \
|
|
|
|
-d -it \
|
|
|
|
--name $GEN_CONTAINER \
|
2017-12-06 22:33:08 +08:00
|
|
|
-e "CONFIGTX_LOGGING_LEVEL=DEBUG" \
|
|
|
|
-e "CONFIGTX_LOGGING_FORMAT=%{color}[%{id:03x} %{time:01-02 15:04:05.00 MST}] [%{longpkg}] %{callpath} -> %{level:.4s}%{color:reset} %{message}" \
|
|
|
|
-v $PWD/configtx.yaml:${FABRIC_CFG_PATH}/configtx.yaml \
|
|
|
|
-v $PWD/crypto-config.yaml:${FABRIC_CFG_PATH}/crypto-config.yaml \
|
2017-12-01 17:34:21 +08:00
|
|
|
-v $PWD/${CRYPTO_CONFIG}:${FABRIC_CFG_PATH}/${CRYPTO_CONFIG} \
|
|
|
|
-v $PWD/${CHANNEL_ARTIFACTS}:/tmp/${CHANNEL_ARTIFACTS} \
|
2017-12-06 22:33:08 +08:00
|
|
|
${GEN_IMG} bash -c 'while true; do sleep 20171001; done'
|
2017-12-01 17:34:21 +08:00
|
|
|
|
2017-12-06 22:33:08 +08:00
|
|
|
if [ "${GEN_CRYPTO}" = "true" ]; then
|
|
|
|
echo_b "Generating crypto-config"
|
2017-12-19 14:40:39 +08:00
|
|
|
gen_con_exec cryptogen generate --config=$FABRIC_CFG_PATH/crypto-config.yaml --output ${FABRIC_CFG_PATH}/${CRYPTO_CONFIG}
|
2017-12-06 22:33:08 +08:00
|
|
|
fi
|
2017-12-01 17:34:21 +08:00
|
|
|
|
2017-12-19 14:40:39 +08:00
|
|
|
echo_b "Generate genesis block for system channel using configtx.yaml"
|
|
|
|
[ -f ${CHANNEL_ARTIFACTS}/${ORDERER_GENESIS} ] || gen_con_exec configtxgen -profile ${ORDERER_PROFILE} -outputBlock /tmp/${CHANNEL_ARTIFACTS}/${ORDERER_GENESIS}
|
2017-12-01 17:34:21 +08:00
|
|
|
|
2017-12-19 14:40:39 +08:00
|
|
|
echo_b "Create the new app channel tx using configtx.yaml"
|
|
|
|
[ -f ${CHANNEL_ARTIFACTS}/${APP_CHANNEL_TX} ] || gen_con_exec configtxgen -profile TwoOrgsChannel -outputCreateChannelTx /tmp/$CHANNEL_ARTIFACTS/${APP_CHANNEL_TX} -channelID ${APP_CHANNEL}
|
2017-12-01 17:34:21 +08:00
|
|
|
|
2017-12-19 14:40:39 +08:00
|
|
|
echo_b "Create the anchor peer configuration tx using configtx.yaml"
|
|
|
|
[ -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
|
|
|
|
[ -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
|
2017-12-01 17:34:21 +08:00
|
|
|
|
|
|
|
echo_b "Remove the container $GEN_CONTAINER" && docker rm -f $GEN_CONTAINER
|
|
|
|
|
2017-12-06 22:33:08 +08:00
|
|
|
echo_g "Generated artifacts for ${MODE}"
|
|
|
|
|