github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/Decentralized-Energy-Composer-master/fabric-dev-servers/fabric-scripts/hlfv12/createPeerAdminCard.sh (about) 1 #!/bin/bash 2 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 Usage() { 16 echo "" 17 echo "Usage: ./createPeerAdminCard.sh [-h host] [-n]" 18 echo "" 19 echo "Options:" 20 echo -e "\t-h or --host:\t\t(Optional) name of the host to specify in the connection profile" 21 echo -e "\t-n or --noimport:\t(Optional) don't import into card store" 22 echo "" 23 echo "Example: ./createPeerAdminCard.sh" 24 echo "" 25 exit 1 26 } 27 28 Parse_Arguments() { 29 while [ $# -gt 0 ]; do 30 case $1 in 31 --help) 32 HELPINFO=true 33 ;; 34 --host | -h) 35 shift 36 HOST="$1" 37 ;; 38 --noimport | -n) 39 NOIMPORT=true 40 ;; 41 esac 42 shift 43 done 44 } 45 46 HOST=localhost 47 Parse_Arguments $@ 48 49 if [ "${HELPINFO}" == "true" ]; then 50 Usage 51 fi 52 53 # Grab the current directory 54 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 55 56 if [ -z "${HL_COMPOSER_CLI}" ]; then 57 HL_COMPOSER_CLI=$(which composer) 58 fi 59 60 echo 61 # check that the composer command exists at a version >v0.16 62 COMPOSER_VERSION=$("${HL_COMPOSER_CLI}" --version 2>/dev/null) 63 COMPOSER_RC=$? 64 65 if [ $COMPOSER_RC -eq 0 ]; then 66 AWKRET=$(echo $COMPOSER_VERSION | awk -F. '{if ($2<20) print "1"; else print "0";}') 67 if [ $AWKRET -eq 1 ]; then 68 echo Cannot use $COMPOSER_VERSION version of composer with fabric 1.2, v0.20 or higher is required 69 exit 1 70 else 71 echo Using composer-cli at $COMPOSER_VERSION 72 fi 73 else 74 echo 'No version of composer-cli has been detected, you need to install composer-cli at v0.20 or higher' 75 exit 1 76 fi 77 78 cat << EOF > DevServer_connection.json 79 { 80 "name": "hlfv1", 81 "x-type": "hlfv1", 82 "x-commitTimeout": 300, 83 "version": "1.0.0", 84 "client": { 85 "organization": "Org1", 86 "connection": { 87 "timeout": { 88 "peer": { 89 "endorser": "300", 90 "eventHub": "300", 91 "eventReg": "300" 92 }, 93 "orderer": "300" 94 } 95 } 96 }, 97 "channels": { 98 "composerchannel": { 99 "orderers": [ 100 "orderer.example.com" 101 ], 102 "peers": { 103 "peer0.org1.example.com": {} 104 } 105 } 106 }, 107 "organizations": { 108 "Org1": { 109 "mspid": "Org1MSP", 110 "peers": [ 111 "peer0.org1.example.com" 112 ], 113 "certificateAuthorities": [ 114 "ca.org1.example.com" 115 ] 116 } 117 }, 118 "orderers": { 119 "orderer.example.com": { 120 "url": "grpc://${HOST}:7050" 121 } 122 }, 123 "peers": { 124 "peer0.org1.example.com": { 125 "url": "grpc://${HOST}:7051" 126 } 127 }, 128 "certificateAuthorities": { 129 "ca.org1.example.com": { 130 "url": "http://${HOST}:7054", 131 "caName": "ca.org1.example.com" 132 } 133 } 134 } 135 EOF 136 137 PRIVATE_KEY="${DIR}"/composer/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/114aab0e76bf0c78308f89efc4b8c9423e31568da0c340ca187a9b17aa9a4457_sk 138 CERT="${DIR}"/composer/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem 139 140 if [ "${NOIMPORT}" != "true" ]; then 141 CARDOUTPUT=/tmp/PeerAdmin@hlfv1.card 142 else 143 CARDOUTPUT=PeerAdmin@hlfv1.card 144 fi 145 146 "${HL_COMPOSER_CLI}" card create -p DevServer_connection.json -u PeerAdmin -c "${CERT}" -k "${PRIVATE_KEY}" -r PeerAdmin -r ChannelAdmin --file $CARDOUTPUT 147 148 if [ "${NOIMPORT}" != "true" ]; then 149 if "${HL_COMPOSER_CLI}" card list -c PeerAdmin@hlfv1 > /dev/null; then 150 "${HL_COMPOSER_CLI}" card delete -c PeerAdmin@hlfv1 151 fi 152 153 "${HL_COMPOSER_CLI}" card import --file /tmp/PeerAdmin@hlfv1.card 154 "${HL_COMPOSER_CLI}" card list 155 echo "Hyperledger Composer PeerAdmin card has been imported, host of fabric specified as '${HOST}'" 156 rm /tmp/PeerAdmin@hlfv1.card 157 else 158 echo "Hyperledger Composer PeerAdmin card has been created, host of fabric specified as '${HOST}'" 159 fi