Skip to content

Commit c322e83

Browse files
[FAB-15316] Shellcheck fixes for some scripts
- Change scripts to use the recommended practices for bash scripting - The follow scripts were changed based on the suggestions of shellcheck: - scripts/bootrstrap.sh - scripts/chengelog.sh - scripts/check_trailingspaces.sh Change-Id: I4bf2b0562d3aa3f5deb48332ae721d7c1c5e2c8e Signed-off-by: Swetha Repakula <srepaku@us.ibm.com>
1 parent 0958a19 commit c322e83

File tree

3 files changed

+51
-50
lines changed

3 files changed

+51
-50
lines changed

scripts/bootstrap.sh

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
#
77

88
# if version not passed in, default to latest released version
9-
export VERSION=1.4.1
9+
VERSION=1.4.1
1010
# if ca version not passed in, default to latest released version
11-
export CA_VERSION=1.4.1
11+
CA_VERSION=1.4.1
1212
# current version of thirdparty images (couchdb, kafka and zookeeper) released
13-
export THIRDPARTY_IMAGE_VERSION=0.4.15
14-
export ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')")
15-
export MARCH=$(uname -m)
13+
THIRDPARTY_IMAGE_VERSION=0.4.15
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)
1616

1717
printHelp() {
1818
echo "Usage: bootstrap.sh [version [ca_version [thirdparty_version]]] [options]"
@@ -35,8 +35,8 @@ dockerFabricPull() {
3535
for IMAGES in peer orderer ccenv tools baseos nodeenv javaenv; do
3636
echo "==> FABRIC IMAGE: $IMAGES"
3737
echo
38-
docker pull hyperledger/fabric-$IMAGES:$FABRIC_TAG
39-
docker tag hyperledger/fabric-$IMAGES:$FABRIC_TAG hyperledger/fabric-$IMAGES
38+
docker pull "hyperledger/fabric-$IMAGES:$FABRIC_TAG"
39+
docker tag "hyperledger/fabric-$IMAGES:$FABRIC_TAG" "hyperledger/fabric-$IMAGES"
4040
done
4141
}
4242

@@ -45,17 +45,17 @@ dockerThirdPartyImagesPull() {
4545
for IMAGES in couchdb kafka zookeeper; do
4646
echo "==> THIRDPARTY DOCKER IMAGE: $IMAGES"
4747
echo
48-
docker pull hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG
49-
docker tag hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG hyperledger/fabric-$IMAGES
48+
docker pull "hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG"
49+
docker tag "hyperledger/fabric-$IMAGES:$THIRDPARTY_TAG" "hyperledger/fabric-$IMAGES"
5050
done
5151
}
5252

5353
dockerCaPull() {
5454
local CA_TAG=$1
5555
echo "==> FABRIC CA IMAGE"
5656
echo
57-
docker pull hyperledger/fabric-ca:$CA_TAG
58-
docker tag hyperledger/fabric-ca:$CA_TAG hyperledger/fabric-ca
57+
docker pull "hyperledger/fabric-ca:$CA_TAG"
58+
docker tag "hyperledger/fabric-ca:$CA_TAG" hyperledger/fabric-ca
5959
}
6060

6161
samplesInstall() {
@@ -82,7 +82,7 @@ samplesInstall() {
8282
binaryIncrementalDownload() {
8383
local BINARY_FILE=$1
8484
local URL=$2
85-
curl -f -s -C - ${URL} -o ${BINARY_FILE} || rc=$?
85+
curl -f -s -C - "${URL}" -o "${BINARY_FILE}" || rc=$?
8686
# Due to limitations in the current Nexus repo:
8787
# curl returns 33 when there's a resume attempt with no more bytes to download
8888
# curl returns 2 after finishing a resumed download
@@ -94,16 +94,16 @@ binaryIncrementalDownload() {
9494
if [ -z "$rc" ] || [ $rc -eq 33 ] || [ $rc -eq 2 ]; then
9595
# The checksum validates that RC 33 or 2 are not real failures
9696
echo "==> File downloaded. Verifying the md5sum..."
97-
localMd5sum=$(md5sum ${BINARY_FILE} | awk '{print $1}')
98-
remoteMd5sum=$(curl -s ${URL}.md5)
97+
localMd5sum=$(md5sum "${BINARY_FILE}" | awk '{print $1}')
98+
remoteMd5sum=$(curl -s "${URL}".md5)
9999
if [ "$localMd5sum" == "$remoteMd5sum" ]; then
100100
echo "==> Extracting ${BINARY_FILE}..."
101-
tar xzf ./${BINARY_FILE} --overwrite
101+
tar xzf ./"${BINARY_FILE}" --overwrite
102102
echo "==> Done."
103-
rm -f ${BINARY_FILE} ${BINARY_FILE}.md5
103+
rm -f "${BINARY_FILE}" "${BINARY_FILE}".md5
104104
else
105105
echo "Download failed: the local md5sum is different from the remote md5sum. Please try again."
106-
rm -f ${BINARY_FILE} ${BINARY_FILE}.md5
106+
rm -f "${BINARY_FILE}" "${BINARY_FILE}".md5
107107
exit 1
108108
fi
109109
else
@@ -118,17 +118,17 @@ binaryIncrementalDownload() {
118118
binaryDownload() {
119119
local BINARY_FILE=$1
120120
local URL=$2
121-
echo "===> Downloading: " ${URL}
121+
echo "===> Downloading: " "${URL}"
122122
# Check if a previous failure occurred and the file was partially downloaded
123-
if [ -e ${BINARY_FILE} ]; then
123+
if [ -e "${BINARY_FILE}" ]; then
124124
echo "==> Partial binary file found. Resuming download..."
125-
binaryIncrementalDownload ${BINARY_FILE} ${URL}
125+
binaryIncrementalDownload "${BINARY_FILE}" "${URL}"
126126
else
127-
curl ${URL} | tar xz || rc=$?
128-
if [ ! -z "$rc" ]; then
127+
curl "${URL}" | tar xz || rc=$?
128+
if [ -n "$rc" ]; then
129129
echo "==> There was an error downloading the binary file. Switching to incremental download."
130130
echo "==> Downloading file..."
131-
binaryIncrementalDownload ${BINARY_FILE} ${URL}
131+
binaryIncrementalDownload "${BINARY_FILE}" "${URL}"
132132
else
133133
echo "==> Done."
134134
fi
@@ -137,15 +137,15 @@ binaryDownload() {
137137

138138
binariesInstall() {
139139
echo "===> Downloading version ${FABRIC_TAG} platform specific fabric binaries"
140-
binaryDownload ${BINARY_FILE} https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/${ARCH}-${VERSION}/${BINARY_FILE}
140+
binaryDownload "${BINARY_FILE}" "https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/${ARCH}-${VERSION}/${BINARY_FILE}"
141141
if [ $? -eq 22 ]; then
142142
echo
143143
echo "------> ${FABRIC_TAG} platform specific fabric binary is not available to download <----"
144144
echo
145145
fi
146146

147147
echo "===> Downloading version ${CA_TAG} platform specific fabric-ca-client binary"
148-
binaryDownload ${CA_BINARY_FILE} https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/${ARCH}-${CA_VERSION}/${CA_BINARY_FILE}
148+
binaryDownload "${CA_BINARY_FILE}" "https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/${ARCH}-${CA_VERSION}/${CA_BINARY_FILE}"
149149
if [ $? -eq 22 ]; then
150150
echo
151151
echo "------> ${CA_TAG} fabric-ca-client binary is not available to download (Available from 1.1.0-rc1) <----"
@@ -154,18 +154,18 @@ binariesInstall() {
154154
}
155155

156156
dockerInstall() {
157-
which docker >& /dev/null
157+
command -v docker >& /dev/null
158158
NODOCKER=$?
159159
if [ "${NODOCKER}" == 0 ]; then
160160
echo "===> Pulling fabric Images"
161-
dockerFabricPull ${FABRIC_TAG}
161+
dockerFabricPull "${FABRIC_TAG}"
162162
echo "===> Pulling fabric ca Image"
163-
dockerCaPull ${CA_TAG}
163+
dockerCaPull "${CA_TAG}"
164164
echo "===> Pulling thirdparty docker images"
165-
dockerThirdPartyImagesPull ${THIRDPARTY_TAG}
165+
dockerThirdPartyImagesPull "${THIRDPARTY_TAG}"
166166
echo
167167
echo "===> List out hyperledger docker images"
168-
docker images | grep hyperledger*
168+
docker images | grep hyperledger
169169
else
170170
echo "========================================================="
171171
echo "Docker not installed, bypassing download of Fabric images"
@@ -179,11 +179,11 @@ BINARIES=true
179179

180180
# Parse commandline args pull out
181181
# version and/or ca-version strings first
182-
if [ ! -z "$1" -a "${1:0:1}" != "-" ]; then
182+
if [ -n "$1" ] -a [ "${1:0:1}" != "-" ]; then
183183
VERSION=$1;shift
184-
if [ ! -z "$1" -a "${1:0:1}" != "-" ]; then
184+
if [ -n "$1" ] -a [ "${1:0:1}" != "-" ]; then
185185
CA_VERSION=$1;shift
186-
if [ ! -z "$1" -a "${1:0:1}" != "-" ]; then
186+
if [ -n "$1" ] -a [ "${1:0:1}" != "-" ]; then
187187
THIRDPARTY_IMAGE_VERSION=$1;shift
188188
fi
189189
fi
@@ -196,9 +196,9 @@ if [[ $VERSION =~ ^1\.[0-1]\.* ]]; then
196196
export THIRDPARTY_TAG=${MARCH}-${THIRDPARTY_IMAGE_VERSION}
197197
else
198198
# starting with 1.2.0, multi-arch images will be default
199-
: ${CA_TAG:="$CA_VERSION"}
200-
: ${FABRIC_TAG:="$VERSION"}
201-
: ${THIRDPARTY_TAG:="$THIRDPARTY_IMAGE_VERSION"}
199+
: "${CA_TAG:=$CA_VERSION}"
200+
: "${FABRIC_TAG:=$VERSION}"
201+
: "${THIRDPARTY_TAG:=$THIRDPARTY_IMAGE_VERSION}"
202202
fi
203203

204204
BINARY_FILE=hyperledger-fabric-${ARCH}-${VERSION}.tar.gz

scripts/changelog.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
#
77

88

9-
echo "## $2\n$(date)" >> CHANGELOG.new
10-
echo "" >> CHANGELOG.new
11-
git log $1..HEAD --oneline | grep -v Merge | sed -e "s/\[\(FAB-[0-9]*\)\]/\[\1\](https:\/\/jira.hyperledger.org\/browse\/\1\)/" -e "s/ \(FAB-[0-9]*\)/ \[\1\](https:\/\/jira.hyperledger.org\/browse\/\1\)/" -e "s/\([0-9|a-z]*\)/* \[\1\](https:\/\/github.com\/hyperledger\/fabric\/commit\/\1)/" >> CHANGELOG.new
12-
echo "" >> CHANGELOG.new
13-
cat CHANGELOG.md >> CHANGELOG.new
9+
{
10+
echo "## $2";
11+
date;
12+
echo ""
13+
git log "$1..HEAD" --oneline | grep -v Merge | sed -e "s/\[\(FAB-[0-9]*\)\]/\[\1\](https:\/\/jira.hyperledger.org\/browse\/\1\)/" -e "s/ \(FAB-[0-9]*\)/ \[\1\](https:\/\/jira.hyperledger.org\/browse\/\1\)/" -e "s/\([0-9|a-z]*\)/* \[\1\](https:\/\/github.com\/hyperledger\/fabric\/commit\/\1)/"
14+
echo ""
15+
echo ""
16+
cat CHANGELOG.md
17+
} >> CHANGELOG.new
1418
mv -f CHANGELOG.new CHANGELOG.md

scripts/check_trailingspaces.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@
22
# Copyright Hitachi, Ltd. All Rights Reserved.
33
# SPDX-License-Identifier: Apache-2.0
44

5-
COMMIT_FILES=`git diff --name-only --diff-filter=ACMRTUXB HEAD | grep -Ev '(^|/)vendor/'`
5+
COMMIT_FILES=$(git diff --name-only --diff-filter=ACMRTUXB HEAD | grep -Ev '(^|/)vendor/')
66

77
echo "Checking trailing spaces ..."
8-
for filename in `echo $COMMIT_FILES`; do
9-
if [[ `file $filename` == *"ASCII text"* ]];
10-
then
11-
if [ ! -z "`egrep -l " +$" $filename`" ];
12-
then
8+
for filename in $COMMIT_FILES; do
9+
if [[ $(file "$filename") == *"ASCII text"* ]]; then
10+
if grep -El " +$" "$filename"; then
1311
FOUND_TRAILING='yes'
1412
echo "Error: Trailing spaces found in file:$filename, lines:"
15-
egrep -n " +$" $filename
13+
grep -En " +$" "$filename"
1614
fi
1715
fi
1816
done
1917

20-
if [ ! -z ${FOUND_TRAILING+x} ];
21-
then
18+
if [[ -n ${FOUND_TRAILING+x} ]]; then
2219
echo "Please omit trailing spaces and make again."
2320
exit 1
2421
fi

0 commit comments

Comments
 (0)