github.com/sykesm/fabric@v1.1.0-preview.0.20200129034918-2aa12b1a0181/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 #three_digit_image_tag is passed in, e.g. "1.4.4" 36 three_digit_image_tag=$1 37 shift 38 #two_digit_image_tag is derived, e.g. "1.4", especially useful as a local tag for two digit references to most recent baseos, ccenv, javaenv, nodeenv patch releases 39 two_digit_image_tag=$(echo $three_digit_image_tag | cut -d'.' -f1,2) 40 while [[ $# -gt 0 ]] 41 do 42 image_name="$1" 43 echo "====> hyperledger/fabric-$image_name:$three_digit_image_tag" 44 docker pull "hyperledger/fabric-$image_name:$three_digit_image_tag" 45 docker tag "hyperledger/fabric-$image_name:$three_digit_image_tag" "hyperledger/fabric-$image_name" 46 docker tag "hyperledger/fabric-$image_name:$three_digit_image_tag" "hyperledger/fabric-$image_name:$two_digit_image_tag" 47 shift 48 done 49 } 50 51 cloneSamplesRepo() { 52 # clone (if needed) hyperledger/fabric-samples and checkout corresponding 53 # version to the binaries and docker images to be downloaded 54 if [ -d first-network ]; then 55 # if we are in the fabric-samples repo, checkout corresponding version 56 echo "===> Checking out v${VERSION} of hyperledger/fabric-samples" 57 git checkout v${VERSION} 58 elif [ -d fabric-samples ]; then 59 # if fabric-samples repo already cloned and in current directory, 60 # cd fabric-samples and checkout corresponding version 61 echo "===> Checking out v${VERSION} of hyperledger/fabric-samples" 62 cd fabric-samples && git checkout v${VERSION} 63 else 64 echo "===> Cloning hyperledger/fabric-samples repo and checkout v${VERSION}" 65 git clone -b master https://github.com/hyperledger/fabric-samples.git && cd fabric-samples && git checkout v${VERSION} 66 fi 67 } 68 69 # This will download the .tar.gz 70 download() { 71 local BINARY_FILE=$1 72 local URL=$2 73 echo "===> Downloading: " "${URL}" 74 wget "${URL}" || rc=$? 75 tar xvzf "${BINARY_FILE}" || rc=$? 76 rm "${BINARY_FILE}" 77 if [ -n "$rc" ]; then 78 echo "==> There was an error downloading the binary file." 79 return 22 80 else 81 echo "==> Done." 82 fi 83 } 84 85 pullBinaries() { 86 echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries" 87 download "${BINARY_FILE}" "https://github.com/hyperledger/fabric/releases/download/v${VERSION}/${BINARY_FILE}" 88 if [ $? -eq 22 ]; then 89 echo 90 echo "------> ${FABRIC_TAG} platform specific fabric binary is not available to download <----" 91 echo 92 exit 93 fi 94 95 echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary" 96 download "${CA_BINARY_FILE}" "https://github.com/hyperledger/fabric-ca/releases/download/v${CA_VERSION}/${CA_BINARY_FILE}" 97 if [ $? -eq 22 ]; then 98 echo 99 echo "------> ${CA_TAG} fabric-ca-client binary is not available to download (Available from 1.1.0-rc1) <----" 100 echo 101 exit 102 fi 103 } 104 105 pullDockerImages() { 106 command -v docker >& /dev/null 107 NODOCKER=$? 108 if [ "${NODOCKER}" == 0 ]; then 109 FABRIC_IMAGES=(peer orderer ccenv tools) 110 case "$VERSION" in 111 1.*) 112 FABRIC_IMAGES+=(javaenv) 113 shift 114 ;; 115 2.*) 116 FABRIC_IMAGES+=(nodeenv baseos javaenv) 117 shift 118 ;; 119 esac 120 echo "FABRIC_IMAGES:" "${FABRIC_IMAGES[@]}" 121 echo "===> Pulling fabric Images" 122 dockerPull "${FABRIC_TAG}" "${FABRIC_IMAGES[@]}" 123 echo "===> Pulling fabric ca Image" 124 CA_IMAGE=(ca) 125 dockerPull "${CA_TAG}" "${CA_IMAGE[@]}" 126 echo "===> Pulling thirdparty docker images" 127 THIRDPARTY_IMAGES=(zookeeper kafka couchdb) 128 dockerPull "${THIRDPARTY_TAG}" "${THIRDPARTY_IMAGES[@]}" 129 echo 130 echo "===> List out hyperledger docker images" 131 docker images | grep hyperledger 132 else 133 echo "=========================================================" 134 echo "Docker not installed, bypassing download of Fabric images" 135 echo "=========================================================" 136 fi 137 } 138 139 DOCKER=true 140 SAMPLES=true 141 BINARIES=true 142 143 # Parse commandline args pull out 144 # version and/or ca-version strings first 145 if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then 146 VERSION=$1;shift 147 if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then 148 CA_VERSION=$1;shift 149 if [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then 150 THIRDPARTY_IMAGE_VERSION=$1;shift 151 fi 152 fi 153 fi 154 155 # prior to 1.2.0 architecture was determined by uname -m 156 if [[ $VERSION =~ ^1\.[0-1]\.* ]]; then 157 export FABRIC_TAG=${MARCH}-${VERSION} 158 export CA_TAG=${MARCH}-${CA_VERSION} 159 export THIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION} 160 else 161 # starting with 1.2.0, multi-arch images will be default 162 : "${CA_TAG:="$CA_VERSION"}" 163 : "${FABRIC_TAG:="$VERSION"}" 164 : "${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}" 165 fi 166 167 BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.tar.gz 168 CA_BINARY_FILE=hyperledger-fabric-ca-${ARCH}-${CA_VERSION}.tar.gz 169 170 # then parse opts 171 while getopts "h?dsb" opt; do 172 case "$opt" in 173 h|\?) 174 printHelp 175 exit 0 176 ;; 177 d) DOCKER=false 178 ;; 179 s) SAMPLES=false 180 ;; 181 b) BINARIES=false 182 ;; 183 esac 184 done 185 186 if [ "$SAMPLES" == "true" ]; then 187 echo 188 echo "Clone hyperledger/fabric-samples repo" 189 echo 190 cloneSamplesRepo 191 fi 192 if [ "$BINARIES" == "true" ]; then 193 echo 194 echo "Pull Hyperledger Fabric binaries" 195 echo 196 pullBinaries 197 fi 198 if [ "$DOCKER" == "true" ]; then 199 echo 200 echo "Pull Hyperledger Fabric docker images" 201 echo 202 pullDockerImages 203 fi