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

73 lines
2.2 KiB
Bash
Raw Normal View History

2018-10-11 13:53:01 +08:00
#! /bin/bash
# Generating
# * crypto-config/*
# * 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
else
echo "Cannot find the func.sh files, pls check"
exit 1
fi
[ $# -ne 1 ] && echo_r "[Usage] $0 solo|kafka" && exit 1 || MODE=$1
echo_b "Generating artifacts for ${MODE}"
echo_b "Clean existing container $GEN_CONTAINER"
[ "$(docker ps -a | grep $GEN_CONTAINER)" ] && docker rm -f $GEN_CONTAINER
2018-10-12 11:33:24 +08:00
[ ! -d ${CRYPTO_CONFIG} ] && mkdir -p ${CRYPTO_CONFIG}
[ ! -d org3/${CRYPTO_CONFIG} ] && mkdir -p org3/${CRYPTO_CONFIG}
2018-10-11 13:53:01 +08:00
echo_b "Make sure crypto-config dir exists already"
2018-10-12 11:33:24 +08:00
if [ ! -d ${CRYPTO_CONFIG} -o -z "$(ls -A ${CRYPTO_CONFIG})" ]; then # need to re-gen crypto
2018-10-11 13:53:01 +08:00
echo_g "Path ${CRYPTO_CONFIG} not exists, re-generating it."
docker run \
--rm -it \
--name ${GEN_CONTAINER} \
-e "CONFIGTX_LOGGING_LEVEL=DEBUG" \
2018-10-12 11:33:24 +08:00
-v $PWD/${CRYPTO_CONFIG}:/tmp/${CRYPTO_CONFIG} \
2018-10-11 13:53:01 +08:00
-v $PWD/crypto-config.yaml:/tmp/crypto-config.yaml \
-v $PWD/org3:/tmp/org3 \
2018-10-12 11:33:24 +08:00
-v $PWD/scripts/gen_cryptoArtifacts.sh:/scripts/gen_cryptoArtifacts.sh \
${GEN_IMG} sh -c 'sleep 1; bash /scripts/gen_cryptoArtifacts.sh'
[ $? -ne 0 ] && exit 1
2018-10-11 13:53:01 +08:00
else
echo_b "${CRYPTO_CONFIG} exists, ignore."
fi
2018-10-12 11:33:24 +08:00
cp -r org3/${CRYPTO_CONFIG}/* ${CRYPTO_CONFIG}/
[ ! -d ${MODE}/${CHANNEL_ARTIFACTS} ] && mkdir -p ${MODE}/${CHANNEL_ARTIFACTS}
2018-10-11 13:53:01 +08:00
echo_b "Make sure channel-artifacts dir exists already"
2018-10-12 11:33:24 +08:00
if [ ! -d ${MODE}/${CHANNEL_ARTIFACTS} -o -z "$(ls -A ${MODE}/${CHANNEL_ARTIFACTS})" ]; then
2018-10-11 13:53:01 +08:00
echo_g "Path ${CHANNEL_ARTIFACTS} not exists, generating it."
2018-10-12 11:33:24 +08:00
#TODO: no need crypto-config path
2018-10-11 13:53:01 +08:00
docker run \
--rm -it \
--name ${GEN_CONTAINER} \
-e "CONFIGTX_LOGGING_LEVEL=DEBUG" \
2018-10-12 11:33:24 +08:00
-v $PWD/${CRYPTO_CONFIG}:/tmp/${CRYPTO_CONFIG} \
-v $PWD/${MODE}/configtx.yaml:/tmp/configtx.yaml \
2018-10-11 13:53:01 +08:00
-v $PWD/${MODE}/${CHANNEL_ARTIFACTS}:/tmp/${CHANNEL_ARTIFACTS} \
-v $PWD/org3:/tmp/org3 \
2018-10-12 11:33:24 +08:00
-v $PWD/scripts/variables.sh:/scripts/variables.sh \
-v $PWD/scripts/gen_channelArtifacts.sh:/scripts/gen_channelArtifacts.sh \
${GEN_IMG} sh -c 'sleep 1; bash /scripts/gen_channelArtifacts.sh'
2018-10-11 13:53:01 +08:00
else
echo_b "${CHANNEL_ARTIFACTS} exists, ignore."
fi