github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/examples/configtxupdate/reconfig_membership/script.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright IBM Corp. All Rights Reserved.
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  
     8  CDIR=$(dirname $(basename "$0"))
     9  
    10  # Defaults
    11  : ${CHANNEL:="example"}
    12  : ${OUTDIR:="example_output"}
    13  mkdir -p ${OUTDIR} || die "could not create output dir ${OUTDIR}"
    14  
    15  CONFIG_BLOCK_PB="${OUTDIR}/config_block.pb"
    16  CONFIG_BLOCK_JSON="${OUTDIR}/config_block.json"
    17  CONFIG_JSON="${OUTDIR}/config.json"
    18  CONFIG_PB="${OUTDIR}/config.pb"
    19  UPDATED_CONFIG_JSON="${OUTDIR}/updated_config.json"
    20  UPDATED_CONFIG_PB="${OUTDIR}/updated_config.pb"
    21  CONFIG_UPDATE_PB="${OUTDIR}/config_update.pb"
    22  CONFIG_UPDATE_JSON="${OUTDIR}/config_update.json"
    23  CONFIG_UPDATE_IN_ENVELOPE_PB="${OUTDIR}/config_update_in_envelope.pb"
    24  CONFIG_UPDATE_IN_ENVELOPE_JSON="${OUTDIR}/config_update_in_envelope.json"
    25  
    26  CHANNEL_CREATE_TX=${OUTDIR}/channel_create_tx.pb
    27  
    28  . ${CDIR}/../common_scripts/common.sh
    29  
    30  bigMsg "Beginning config update membership example"
    31  
    32  findPeer || die "could not find peer binary"
    33  
    34  findConfigtxgen || die "could not find configtxgen binary"
    35  
    36  echo -e "Executing:\n\tconfigtxgen -channelID '${CHANNEL}' -outputCreateChannelTx '${CHANNEL_CREATE_TX}' -profile SampleSingleMSPChannel"
    37  ${CONFIGTXGEN} -channelID "${CHANNEL}" -outputCreateChannelTx "${CHANNEL_CREATE_TX}" -profile SampleSingleMSPChannel || die "error creating channel create tx"
    38  
    39  assertFileContainsProto "${CHANNEL_CREATE_TX}"
    40  
    41  bigMsg "Submitting channel create tx to orderer"
    42  
    43  createChannel "${CHANNEL}" "${CHANNEL_CREATE_TX}"
    44  
    45  bigMsg "Renaming current config block"
    46  
    47  echo -e "Executing:\n\tmv '${CHANNEL}.block' '${CONFIG_BLOCK_PB}'"
    48  mv "${CHANNEL}.block" "${CONFIG_BLOCK_PB}"
    49  
    50  bigMsg "Decoding current config block"
    51  
    52  decode common.Block "${CONFIG_BLOCK_PB}" "${CONFIG_BLOCK_JSON}"
    53  
    54  bigMsg "Isolating current config"
    55  
    56  echo -e "Executing:\tjq .data.data[0].payload.data.config '${CONFIG_BLOCK_JSON}' > '${CONFIG_JSON}'"
    57  jq .data.data[0].payload.data.config "${CONFIG_BLOCK_JSON}" > "${CONFIG_JSON}" || die "Unable to extract config from config block"
    58  
    59  pauseIfInteractive
    60  
    61  bigMsg "Generating new config"
    62  
    63  jq '. * {"channel_group":{"groups":{"Application":{"groups":{"ExampleOrg": .channel_group.groups.Application.groups.SampleOrg}}}}}'  "${CONFIG_JSON}"  | jq '.channel_group.groups.Application.groups.ExampleOrg.values.MSP.value.config.name = "ExampleOrg"' > "${UPDATED_CONFIG_JSON}"
    64  
    65  echo "Used JQ to write new config with 'ExampleOrg' defined to ${UPDATED_CONFIG_JSON}"
    66  
    67  pauseIfInteractive
    68  
    69  bigMsg "Translating original config to proto"
    70  
    71  encode common.Config "${CONFIG_JSON}" "${CONFIG_PB}"
    72  
    73  bigMsg "Translating updated config to proto"
    74  
    75  encode common.Config "${UPDATED_CONFIG_JSON}" "${UPDATED_CONFIG_PB}"
    76  
    77  bigMsg "Computing config update"
    78  
    79  computeUpdate "${CHANNEL}" "${CONFIG_PB}" "${UPDATED_CONFIG_PB}" "${CONFIG_UPDATE_PB}"
    80  
    81  bigMsg "Decoding config update"
    82  
    83  decode common.ConfigUpdate "${CONFIG_UPDATE_PB}" "${CONFIG_UPDATE_JSON}"
    84  
    85  bigMsg "Generating config update envelope"
    86  
    87  wrapConfigEnvelope "${CONFIG_UPDATE_JSON}" "${CONFIG_UPDATE_IN_ENVELOPE_JSON}"
    88  
    89  bigMsg "Encoding config update envelope"
    90  
    91  encode common.Envelope "${CONFIG_UPDATE_IN_ENVELOPE_JSON}" "${CONFIG_UPDATE_IN_ENVELOPE_PB}"
    92  
    93  bigMsg "Sending config update to channel"
    94  
    95  updateConfig ${CHANNEL} "${CONFIG_UPDATE_IN_ENVELOPE_PB}"
    96  
    97  bigMsg "Config Update Successful!"