-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathutils.sh
126 lines (101 loc) · 5.22 KB
/
utils.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
if ! [ -x "$(command -v jq)" ]; then
echo 'Error: jq is not installed.' >&2
exit 1
fi
echo "Good to Go!!"
function retrieve_current_config()
{
BASE_DOWNLOAD_PATH=/config
WORKING_DIR=$BASE_DOWNLOAD_PATH/$2_$1
CHANNEL=$2
MSPID=$3
MSPPATH=$4
ORDERER=$5
ORDERER_TLS_CERT=$6
echo "Retrieve $CHANNEL latest config block.."
docker exec -e "WORKING_DIR=$WORKING_DIR" cli sh -c 'mkdir $WORKING_DIR'
docker exec -e "WORKING_DIR=$WORKING_DIR" \
-e "CORE_PEER_LOCALMSPID=$MSPID" \
-e "CORE_PEER_MSPCONFIGPATH=$MSPPATH" \
-e "ORDERER=$ORDERER" \
-e "CORE_PEER_TLS_ROOTCERT_FILE=$ORDERER_TLS_CERT" \
-e "CHANNEL=$CHANNEL" cli \
sh -c 'peer channel fetch config $WORKING_DIR/current_config.pb -o $ORDERER --tls --cafile $CORE_PEER_TLS_ROOTCERT_FILE -c $CHANNEL'
echo "Convert the config block into JSON format.."
docker exec -e "WORKING_DIR=$WORKING_DIR" cli sh -c 'configtxlator proto_decode --input $WORKING_DIR/current_config.pb --type common.Block --output $WORKING_DIR/current_config_block.json'
echo "Stripping headers.."
docker exec -e "WORKING_DIR=$WORKING_DIR" cli sh -c 'jq .data.data[0].payload.data.config $WORKING_DIR/current_config_block.json > $WORKING_DIR/current_config.json'
}
function prepare_unsigned_modified_config()
{
BASE_DOWNLOAD_PATH=/config
WORKING_DIR=$BASE_DOWNLOAD_PATH/$2_$1
CHANNEL=$2
echo "Preparing unsigned protobuf update.."
echo "Step 1/6"
docker exec -e "WORKING_DIR=$WORKING_DIR" cli sh -c 'configtxlator proto_encode --input $WORKING_DIR/current_config.json --type common.Config --output $WORKING_DIR/current_config.pb'
echo "Step 2/6"
docker exec -e "WORKING_DIR=$WORKING_DIR" cli sh -c 'configtxlator proto_encode --input $WORKING_DIR/modified_config.json --type common.Config --output $WORKING_DIR/modified_config.pb'
echo "Step 3/6"
docker exec -e "WORKING_DIR=$WORKING_DIR" -e "CHANNEL=$CHANNEL" cli sh -c 'configtxlator compute_update --channel_id $CHANNEL --original $WORKING_DIR/current_config.pb --updated $WORKING_DIR/modified_config.pb --output $WORKING_DIR/config_update.pb'
echo "Step 4/6"
docker exec -e "WORKING_DIR=$WORKING_DIR" cli sh -c 'configtxlator proto_decode --input $WORKING_DIR/config_update.pb --type common.ConfigUpdate --output $WORKING_DIR/config_update.json'
echo "Step 5/6"
docker exec -e "WORKING_DIR=$WORKING_DIR" -e "CHANNEL=$CHANNEL" cli sh -c 'echo "{\"payload\":{\"header\":{\"channel_header\":{\"channel_id\":\"$CHANNEL\", \"type\":2}},\"data\":{\"config_update\":"$(cat $WORKING_DIR/config_update.json)"}}}" | jq . > $WORKING_DIR/config_update_in_envelope.json'
echo "Step 6/6"
docker exec -e "WORKING_DIR=$WORKING_DIR" cli sh -c 'configtxlator proto_encode --input $WORKING_DIR/config_update_in_envelope.json --type common.Envelope --output $WORKING_DIR/config_update_in_envelope.pb'
}
function sign_config_update()
{
BASE_DOWNLOAD_PATH=/config
WORKING_DIR=$BASE_DOWNLOAD_PATH/$2_$1
CHANNEL=$2
MSPID=$3
MSPPATH=$4
echo "Signing config update as $MSPPATH from $MSPID.."
docker exec -e "WORKING_DIR=$WORKING_DIR" \
-e "CORE_PEER_LOCALMSPID=$MSPID" \
-e "CORE_PEER_MSPCONFIGPATH=$MSPPATH" cli \
sh -c 'peer channel signconfigtx -f $WORKING_DIR/config_update_in_envelope.pb'
}
function send_config_update()
{
BASE_DOWNLOAD_PATH=/config
WORKING_DIR=$BASE_DOWNLOAD_PATH/$2_$1
CHANNEL=$2
MSPID=$3
MSPPATH=$4
ORDERER=$5
ORDERER_TLS_CERT=$6
echo "Sending config update as $MSPATH from $MSPID.."
docker exec -e "WORKING_DIR=$WORKING_DIR" \
-e "CORE_PEER_LOCALMSPID=$MSPID" \
-e "CORE_PEER_MSPCONFIGPATH=$MSPPATH" \
-e "ORDERER=$ORDERER" \
-e "CORE_PEER_TLS_ROOTCERT_FILE=$ORDERER_TLS_CERT" \
-e "CHANNEL=$CHANNEL" cli \
sh -c 'peer channel update -f $WORKING_DIR/config_update_in_envelope.pb -o $ORDERER --tls --cafile $CORE_PEER_TLS_ROOTCERT_FILE -c $CHANNEL'
}
function retrieve_updated_config()
{
BASE_DOWNLOAD_PATH=/config
WORKING_DIR=$BASE_DOWNLOAD_PATH/$2_$1
CHANNEL=$2
MSPID=$3
MSPPATH=$4
ORDERER=$5
ORDERER_TLS_CERT=$6
echo "Retrieve $CHANNEL latest config block.."
docker exec -e "WORKING_DIR=$WORKING_DIR" \
-e "CORE_PEER_LOCALMSPID=$MSPID" \
-e "CORE_PEER_MSPCONFIGPATH=$MSPPATH" \
-e "ORDERER=$ORDERER" \
-e "CORE_PEER_TLS_ROOTCERT_FILE=$ORDERER_TLS_CERT" \
-e "CHANNEL=$CHANNEL" cli \
sh -c 'peer channel fetch config $WORKING_DIR/updated_config.pb -o $ORDERER --tls --cafile $CORE_PEER_TLS_ROOTCERT_FILE -c $CHANNEL'
echo "Convert the config block into JSON format.."
docker exec -e "WORKING_DIR=$WORKING_DIR" cli sh -c 'configtxlator proto_decode --input $WORKING_DIR/updated_config.pb --type common.Block --output $WORKING_DIR/updated_config_block.json'
echo "Stripping headers.."
docker exec -e "WORKING_DIR=$WORKING_DIR" cli sh -c 'jq .data.data[0].payload.data.config $WORKING_DIR/updated_config_block.json > $WORKING_DIR/updated_config.json'
}