github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/scripts/bootstrap.sh (about) 1 #!/bin/bash 2 # 3 # Copyright IBM Corp. All Rights Reserved. 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 8 # if version not passed in, default to latest released version 9 VERSION=1.4.4 10 # if ca version not passed in, default to latest released version 11 CA_VERSION=1.4.4 12 # current version of thirdparty images (couchdb, kafka and zookeeper) released 13 THIRDPARTY_IMAGE_VERSION=0.4.18 14 ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')") 15 MARCH=$(uname -m) 16 17 printHelp() { 18 echo "Usage: bootstrap.sh [version [ca_version [thirdparty_version]]] [options]" 19 echo 20 echo "options:" 21 echo "-h : this help" 22 echo "-d : bypass docker image download" 23 echo "-s : bypass fabric-samples repo clone" 24 echo "-b : bypass download of platform-specific binaries" 25 echo 26 echo "e.g. bootstrap.sh 1.4.4 -s" 27 echo "would download docker images and binaries for version 1.4.4" 28 } 29 30 # dockerPull() pulls docker images from fabric and chaincode repositories 31 # note, if a docker image doesn't exist for a requested release, it will simply 32 # be skipped, since this script doesn't terminate upon errors. 33 34 dockerPull() { 35 image_tag=$1 36 shift 37 while [[ $# -gt 0 ]] 38 do 39 image_name="$1" 40 echo "====> hyperledger/fabric-$image_name:$image_tag" 41 docker pull "hyperledger/fabric-$image_name:$image_tag" 42 docker tag "hyperledger/fabric-$image_name:$image_tag" "hyperledger/fabric-$image_name" 43 shift 44 done 45 } 46 47 cloneSamplesRepo() { 48 # clone (if needed) hyperledger/fabric-samples and checkout corresponding 49 # version to the binaries and docker images to be downloaded 50 if [ -d first-network ]; then 51 # if we are in the fabric-samples repo, checkout corresponding version 52 echo "===> Checking out v${VERSION} of hyperledger/fabric-samples" 53 git checkout v${VERSION} 54 elif [ -d fabric-samples ]; then 55 # if fabric-samples repo already cloned and in current directory, 56 # cd fabric-samples and checkout corresponding version 57 echo "===> Checking out v${VERSION} of hyperledger/fabric-samples" 58 cd fabric-samples && git checkout v${VERSION} 59 else 60 echo "===> Cloning hyperledger/fabric-samples repo and checkout v${VERSION}" 61 git clone -b master https://github.com/hyperledger/fabric-samples.git && cd fabric-samples && git checkout v${VERSION} 62 fi 63 } 64 65 # This will download the .tar.gz 66 download() { 67 local BINARY_FILE=$1 68 local URL=$2 69 echo "===> Downloading: " "${URL}" 70 curl -s -L "${URL}" | tar xz || rc=$? 71 if [ -n "$rc" ]; then 72 echo "==> There was an error downloading the binary file." 73 return 22 74 else 75 echo "==> Done." 76 fi 77 } 78 79 pullBinaries() { 80 echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries" 81 download "${BINARY_FILE}" "https://github.com/hyperledger/fabric/releases/download/v${VERSION}/${BINARY_FILE}" 82 if [ $? -eq 22 ]; then 83 echo 84 echo "------> ${FABRIC_TAG} platform specific fabric binary is not available to download <----" 85 echo 86 exit 87 fi 88 89 echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary" 90 download "${CA_BINARY_FILE}" "https://github.com/hyperledger/fabric-ca/releases/download/v${VERSION}/${CA_BINARY_FILE}" 91 if [ $? -eq 22 ]; then 92 echo 93 echo "------> ${CA_TAG} fabric-ca-client binary is not available to download (Available from 1.1.0-rc1) <----" 94 echo 95 exit 96 fi 97 } 98 99 pullDockerImages() { 100 command -v docker >& /dev/null 101 NODOCKER=$? 102 if [ "${NODOCKER}" == 0 ]; then 103 FABRIC_IMAGES=(peer orderer ccenv tools) 104 case "$VERSION" in 105 1.*) 106 FABRIC_IMAGES+=(javaenv) 107 shift 108 ;; 109 2.*) 110 FABRIC_IMAGES+=(nodeenv baseos javaenv) 111 shift 112 ;; 113 esac 114 echo "FABRIC_IMAGES:" "${FABRIC_IMAGES[@]}" 115 echo "===> Pulling fabric Images" 116 dockerPull "${FABRIC_TAG}" "${FABRIC_IMAGES[@]}" 117 echo "===> Pulling fabric ca Image" 118 CA_IMAGE=(ca) 119 dockerPull "${CA_TAG}" "${CA_IMAGE[@]}" 120 echo "===> Pulling thirdparty docker images" 121 THIRDPARTY_IMAGES=(zookeeper kafka couchdb) 122 dockerPull "${THIRDPARTY_TAG}" "${THIRDPARTY_IMAGES[@]}" 123 echo 124 echo "===> List out hyperledger docker images" 125 docker images | grep hyperledger 126 else 127 echo "=========================================================" 128 echo "Docker not installed, bypassing download of Fabric images" 129 echo "=========================================================" 130 fi 131 } 132 133 DOCKER=true 134 SAMPLES=true 135 BINARIES=true 136 137 # Parse commandline args pull out 138 # version and/or ca-version strings first 139 if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then 140 VERSION=$1;shift 141 if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then 142 CA_VERSION=$1;shift 143 if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then 144 THIRDPARTY_IMAGE_VERSION=$1;shift 145 fi 146 fi 147 fi 148 149 # prior to 1.2.0 architecture was determined by uname -m 150 if [[ $VERSION =~ ^1\.[0-1]\.* ]]; then 151 export FABRIC_TAG=${MARCH}-${VERSION} 152 export CA_TAG=${MARCH}-${CA_VERSION} 153 export THIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION} 154 else 155 # starting with 1.2.0, multi-arch images will be default 156 : "${CA_TAG:="$CA_VERSION"}" 157 : "${FABRIC_TAG:="$VERSION"}" 158 : "${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}" 159 fi 160 161 BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.tar.gz 162 CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH}-${CA_VERSION}.tar.gz 163 164 # then parse opts 165 while getopts "h?dsb" opt; do 166 case "$opt" in 167 h|\?) 168 printHelp 169 exit 0 170 ;; 171 d) DOCKER=false 172 ;; 173 s) SAMPLES=false 174 ;; 175 b) BINARIES=false 176 ;; 177 esac 178 done 179 180 if [ "$SAMPLES" == "true" ]; then 181 echo 182 echo "Clone hyperledger/fabric-samples repo" 183 echo 184 cloneSamplesRepo 185 fi 186 if [ "$BINARIES" == "true" ]; then 187 echo 188 echo "Pull Hyperledger Fabric binaries" 189 echo 190 pullBinaries 191 fi 192 if [ "$DOCKER" == "true" ]; then 193 echo 194 echo "Pull Hyperledger Fabric docker images" 195 echo 196 pullDockerImages 197 fi