docker-compose-files/hyperledger_fabric/v1.0.5/scripts/gen_config.sh

88 lines
2.8 KiB
Bash
Raw Normal View History

2017-12-01 17:34:21 +08:00
#! /bin/bash
# Generating
# * crypto-config
# * channel-artifacts
# * orderer.genesis.block
# * channel.tx
# * Org1MSPanchors.tx
# * Org2MSPanchors.tx
[ $# -ne 1 ] && echo_b "Need config path as param" && exit 1
MODE=$1
# Run cmd inside the container
con_exec() {
docker exec -it $GEN_CONTAINER "$@"
}
if [ -f ./func.sh ]; then
source ./func.sh
elif [ -f scripts/func.sh ]; then
source scripts/func.sh
fi
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-05 17:17:05 +08:00
echo_b "Check whether channel-artifacts or crypto-config exist already"
2017-12-06 22:33:08 +08:00
GEN_CRYPTO=true
if [ -d ${CRYPTO_CONFIG} ]; then #already exist, no need to re-gen crypto
echo_b "${CRYPTO_CONFIG} existed, won't regenerate it."
GEN_CRYPTO=false
else
mkdir ${CRYPTO_CONFIG}
fi
GEN_ARTIFACTS=true
if [ -d ${CHANNEL_ARTIFACTS} ]; then
echo_b "${CHANNEL_ARTIFACTS} existed, won't regenerate it."
GEN_ARTIFACTS=false
else
mkdir ${CHANNEL_ARTIFACTS}
fi
if [ "${GEN_CRYPTO}" = "false" -a "${GEN_ARTIFACTS}" = "false" ]; then
echo_g "No need to generate new config, exiting..."
exit 0
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"
con_exec cryptogen generate --config=$FABRIC_CFG_PATH/crypto-config.yaml --output ${FABRIC_CFG_PATH}/crypto-config
fi
2017-12-01 17:34:21 +08:00
2017-12-06 22:33:08 +08:00
if [ "${GEN_ARTIFACTS}" = "true" ]; then
echo_b "Generate genesis block file for system channel using configtx.yaml"
con_exec configtxgen -profile TwoOrgsOrdererGenesis -outputBlock /tmp/${CHANNEL_ARTIFACTS}/${ORDERER_GENESIS}
2017-12-01 17:34:21 +08:00
2017-12-06 22:33:08 +08:00
echo_b "Create the new app channel tx using configtx.yaml"
con_exec configtxgen -profile TwoOrgsChannel -outputCreateChannelTx /tmp/$CHANNEL_ARTIFACTS/channel.tx -channelID ${APP_CHANNEL}
2017-12-01 17:34:21 +08:00
2017-12-06 22:33:08 +08:00
echo_b "Create the anchor peer configuration tx using configtx.yaml"
con_exec configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate /tmp/${CHANNEL_ARTIFACTS}/Org1MSPanchors.tx -channelID ${APP_CHANNEL} -asOrg Org1MSP
con_exec configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate /tmp/${CHANNEL_ARTIFACTS}/Org2MSPanchors.tx -channelID ${APP_CHANNEL} -asOrg Org2MSP
fi
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}"