#!/bin/bash
## Copyright IBM Corp. All Rights Reserved.## SPDX-License-Identifier: Apache-2.0## if version not passed in, default to latest released versionVERSION=1.4.4
# if ca version not passed in, default to latest released versionCA_VERSION=1.4.4
# current version of thirdparty images (couchdb, kafka and zookeeper) releasedTHIRDPARTY_IMAGE_VERSION=0.4.18
ARCH=$(echo"$(uname -s|tr '[:upper:]''[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')")MARCH=$(uname -m)# dockerPull() pulls docker images from fabric and chaincode repositories# note, if a docker image doesn't exist for a requested release, it will simply# be skipped, since this script doesn't terminate upon errors.dockerPull(){image_tag=$1shiftwhile[[$# -gt 0]]doimage_name="$1"echo"====> hyperledger/fabric-$image_name:$image_tag" docker pull "hyperledger/fabric-$image_name:$image_tag" docker tag "hyperledger/fabric-$image_name:$image_tag""hyperledger/fabric-$image_name"shiftdone}pullDockerImages(){command -v docker >& /dev/null
NODOCKER=$?if["${NODOCKER}"==0];thenFABRIC_IMAGES=(peer orderer ccenv tools)case"$VERSION" in
1.*)FABRIC_IMAGES+=(javaenv)shift;; 2.*)FABRIC_IMAGES+=(nodeenv baseos javaenv)shift;;esacecho"FABRIC_IMAGES:""${FABRIC_IMAGES[@]}"echo"===> Pulling fabric Images" dockerPull "${FABRIC_TAG}""${FABRIC_IMAGES[@]}"echo"===> Pulling fabric ca Image"CA_IMAGE=(ca) dockerPull "${CA_TAG}""${CA_IMAGE[@]}"echo"===> Pulling thirdparty docker images"THIRDPARTY_IMAGES=(zookeeper kafka couchdb) dockerPull "${THIRDPARTY_TAG}""${THIRDPARTY_IMAGES[@]}"echoecho"===> List out hyperledger docker images" docker images | grep hyperledger
elseecho"========================================================="echo"Docker not installed, bypassing download of Fabric images"echo"========================================================="fi}DOCKER=trueSAMPLES=trueBINARIES=true# Parse commandline args pull out# version and/or ca-version strings firstif[ -n "$1"]&&["${1:0:1}" !="-"];thenVERSION=$1;shiftif[ -n "$1"]&&["${1:0:1}" !="-"];thenCA_VERSION=$1;shiftif[ -n "$1"]&&["${1:0:1}" !="-"];thenTHIRDPARTY_IMAGE_VERSION=$1;shiftfififi# prior to 1.2.0 architecture was determined by uname -mif[[$VERSION=~ ^1\.[0-1]\.* ]];thenexportFABRIC_TAG=${MARCH}-${VERSION}exportCA_TAG=${MARCH}-${CA_VERSION}exportTHIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION}else# starting with 1.2.0, multi-arch images will be default : "${CA_TAG:="$CA_VERSION"}" : "${FABRIC_TAG:="$VERSION"}" : "${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}"fi# then parse optswhilegetopts"h?dsb" opt;docase"$opt" in
h|\?) printHelp
exit0;; d)DOCKER=false;; s)SAMPLES=false;; b)BINARIES=false;;esacdoneif["$DOCKER"=="true"];thenechoecho"Pull Hyperledger Fabric docker images"echo pullDockerImages
fi