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