Skip to content

Commit 1088b90

Browse files
committed
Merge #16327: scripts and tools: Update ShellCheck linter
1ac454a Enable ShellCheck rules (Hennadii Stepanov) Pull request description: Enable some simple ShellCheck rules. Note for reviewers: `bash` and `shellcheck` on macOS are different from ones on Ubuntu. For local tests the latest `shellcheck` version 0.6.0 should be used (see #15166). ACKs for top commit: practicalswift: utACK 1ac454a dongcarl: utACK 1ac454a fanquake: ACK 1ac454a Tree-SHA512: 8d0a3a5c09fe1a0c22120178f5e6b80f81f746f8c3356b7701ff301c117acb2edea8fe08f08fb54ed73f94b1617515fb239fa28e7ab4121f74872e6494b6f20e
2 parents dfdcb3d + 1ac454a commit 1088b90

File tree

17 files changed

+42
-57
lines changed

17 files changed

+42
-57
lines changed

.travis/lint_06_script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test/lint/check-doc.py
1818
test/lint/check-rpc-mappings.py .
1919
test/lint/lint-all.sh
2020

21-
if [ "$TRAVIS_REPO_SLUG" = "bitcoin/bitcoin" -a "$TRAVIS_EVENT_TYPE" = "cron" ]; then
21+
if [ "$TRAVIS_REPO_SLUG" = "bitcoin/bitcoin" ] && [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then
2222
git log --merges --before="2 days ago" -1 --format='%H' > ./contrib/verify-commits/trusted-sha512-root-commit
2323
travis_retry gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys $(<contrib/verify-commits/trusted-keys) &&
2424
./contrib/verify-commits/verify-commits.py --clean-merge=2;

.travis/test_05_before_script.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ DOCKER_EXEC echo \> \$HOME/.bitcoin # Make sure default datadir does not exist
1010

1111
mkdir -p depends/SDKs depends/sdk-sources
1212

13-
if [ -n "$OSX_SDK" -a ! -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then
13+
if [ -n "$OSX_SDK" ] && [ ! -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then
1414
curl --location --fail $SDK_URL/MacOSX${OSX_SDK}.sdk.tar.gz -o depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz
1515
fi
16-
if [ -n "$OSX_SDK" -a -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then
16+
if [ -n "$OSX_SDK" ] && [ -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then
1717
tar -C depends/SDKs -xf depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz
1818
fi
1919
if [[ $HOST = *-mingw32 ]]; then
@@ -22,4 +22,3 @@ fi
2222
if [ -z "$NO_DEPENDS" ]; then
2323
DOCKER_EXEC CONFIG_SHELL= make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS
2424
fi
25-

autogen.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ export LC_ALL=C
77
set -e
88
srcdir="$(dirname $0)"
99
cd "$srcdir"
10-
if [ -z ${LIBTOOLIZE} ] && GLIBTOOLIZE="`which glibtoolize 2>/dev/null`"; then
10+
if [ -z ${LIBTOOLIZE} ] && GLIBTOOLIZE="$(command -v glibtoolize)"; then
1111
LIBTOOLIZE="${GLIBTOOLIZE}"
1212
export LIBTOOLIZE
1313
fi
14-
which autoreconf >/dev/null || \
14+
command -v autoreconf >/dev/null || \
1515
(echo "configuration failed, please install autoconf first" && exit 1)
1616
autoreconf --install --force --warnings=all

contrib/devtools/gen-manpages.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ BITCOINQT=${BITCOINQT:-$BINDIR/qt/bitcoin-qt}
1616
[ ! -x $BITCOIND ] && echo "$BITCOIND not found or not executable." && exit 1
1717

1818
# The autodetected version git tag can screw up manpage output a little bit
19-
BTCVER=($($BITCOINCLI --version | head -n1 | awk -F'[ -]' '{ print $6, $7 }'))
19+
read -r -a BTCVER <<< "$($BITCOINCLI --version | head -n1 | awk -F'[ -]' '{ print $6, $7 }')"
2020

2121
# Create a footer file with copyright content.
2222
# This gets autodetected fine for bitcoind if --version-string is not set,

contrib/install_db4.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if [ -z "${1}" ]; then
1414
fi
1515

1616
expand_path() {
17-
echo "$(cd "${1}" && pwd -P)"
17+
cd "${1}" && pwd -P
1818
}
1919

2020
BDB_PREFIX="$(expand_path ${1})/db4"; shift;
@@ -23,7 +23,7 @@ BDB_HASH='12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef'
2323
BDB_URL="https://download.oracle.com/berkeley-db/${BDB_VERSION}.tar.gz"
2424

2525
check_exists() {
26-
which "$1" >/dev/null 2>&1
26+
command -v "$1" >/dev/null
2727
}
2828

2929
sha256_check() {
@@ -95,7 +95,9 @@ make install
9595
echo
9696
echo "db4 build complete."
9797
echo
98+
# shellcheck disable=SC2016
9899
echo 'When compiling bitcoind, run `./configure` in the following way:'
99100
echo
100101
echo " export BDB_PREFIX='${BDB_PREFIX}'"
102+
# shellcheck disable=SC2016
101103
echo ' ./configure BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS="-I${BDB_PREFIX}/include" ...'

contrib/macdeploy/detached-sig-apply.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ if [ -z "${CODESIGN_ALLOCATE}" ]; then
3636
fi
3737

3838
find ${TEMPDIR} -name "*.sign" | while read i; do
39-
SIZE=`stat -c %s "${i}"`
40-
TARGET_FILE="`echo "${i}" | sed 's/\.sign$//'`"
39+
SIZE=$(stat -c %s "${i}")
40+
TARGET_FILE="$(echo "${i}" | sed 's/\.sign$//')"
4141

4242
echo "Allocating space for the signature of size ${SIZE} in ${TARGET_FILE}"
4343
${CODESIGN_ALLOCATE} -i "${TARGET_FILE}" -a ${ARCH} ${SIZE} -o "${i}.tmp"
4444

45-
OFFSET=`${PAGESTUFF} "${i}.tmp" -p | tail -2 | grep offset | sed 's/[^0-9]*//g'`
45+
OFFSET=$(${PAGESTUFF} "${i}.tmp" -p | tail -2 | grep offset | sed 's/[^0-9]*//g')
4646
if [ -z ${QUIET} ]; then
4747
echo "Attaching signature at offset ${OFFSET}"
4848
fi

contrib/macdeploy/detached-sig-create.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ TEMPLIST=${TEMPDIR}/signatures.txt
1414
OUT=signature-osx.tar.gz
1515
OUTROOT=osx
1616

17-
if [ ! -n "$1" ]; then
17+
if [ -z "$1" ]; then
1818
echo "usage: $0 <codesign args>"
1919
echo "example: $0 -s MyIdentity"
2020
exit 1
@@ -26,20 +26,20 @@ mkdir -p ${TEMPDIR}
2626
${CODESIGN} -f --file-list ${TEMPLIST} "$@" "${BUNDLE}"
2727

2828
grep -v CodeResources < "${TEMPLIST}" | while read i; do
29-
TARGETFILE="${BUNDLE}/`echo "${i}" | sed "s|.*${BUNDLE}/||"`"
30-
SIZE=`pagestuff "$i" -p | tail -2 | grep size | sed 's/[^0-9]*//g'`
31-
OFFSET=`pagestuff "$i" -p | tail -2 | grep offset | sed 's/[^0-9]*//g'`
29+
TARGETFILE="${BUNDLE}/$(echo "${i}" | sed "s|.*${BUNDLE}/||")"
30+
SIZE=$(pagestuff "$i" -p | tail -2 | grep size | sed 's/[^0-9]*//g')
31+
OFFSET=$(pagestuff "$i" -p | tail -2 | grep offset | sed 's/[^0-9]*//g')
3232
SIGNFILE="${TEMPDIR}/${OUTROOT}/${TARGETFILE}.sign"
33-
DIRNAME="`dirname "${SIGNFILE}"`"
33+
DIRNAME="$(dirname "${SIGNFILE}")"
3434
mkdir -p "${DIRNAME}"
3535
echo "Adding detached signature for: ${TARGETFILE}. Size: ${SIZE}. Offset: ${OFFSET}"
3636
dd if="$i" of="${SIGNFILE}" bs=1 skip=${OFFSET} count=${SIZE} 2>/dev/null
3737
done
3838

3939
grep CodeResources < "${TEMPLIST}" | while read i; do
40-
TARGETFILE="${BUNDLE}/`echo "${i}" | sed "s|.*${BUNDLE}/||"`"
40+
TARGETFILE="${BUNDLE}/$(echo "${i}" | sed "s|.*${BUNDLE}/||")"
4141
RESOURCE="${TEMPDIR}/${OUTROOT}/${TARGETFILE}"
42-
DIRNAME="`dirname "${RESOURCE}"`"
42+
DIRNAME="$(dirname "${RESOURCE}")"
4343
mkdir -p "${DIRNAME}"
4444
echo "Adding resource for: \"${TARGETFILE}\""
4545
cp "${i}" "${RESOURCE}"

contrib/qos/tc.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tc class add dev ${IF} parent 1:1 classid 1:11 htb rate ${LIMIT} ceil ${LIMIT} p
3333
tc filter add dev ${IF} parent 1: protocol ip prio 1 handle 1 fw classid 1:10
3434
tc filter add dev ${IF} parent 1: protocol ip prio 2 handle 2 fw classid 1:11
3535

36-
if [ ! -z "${LOCALNET_V6}" ] ; then
36+
if [ -n "${LOCALNET_V6}" ] ; then
3737
# v6 cannot have the same priority value as v4
3838
tc filter add dev ${IF} parent 1: protocol ipv6 prio 3 handle 1 fw classid 1:10
3939
tc filter add dev ${IF} parent 1: protocol ipv6 prio 4 handle 2 fw classid 1:11
@@ -56,7 +56,7 @@ fi
5656
iptables -t mangle -A OUTPUT -p tcp -m tcp --dport 8333 ! -d ${LOCALNET_V4} -j MARK --set-mark 0x2
5757
iptables -t mangle -A OUTPUT -p tcp -m tcp --sport 8333 ! -d ${LOCALNET_V4} -j MARK --set-mark 0x2
5858

59-
if [ ! -z "${LOCALNET_V6}" ] ; then
59+
if [ -n "${LOCALNET_V6}" ] ; then
6060
ip6tables -t mangle -A OUTPUT -p tcp -m tcp --dport 8333 ! -d ${LOCALNET_V6} -j MARK --set-mark 0x4
6161
ip6tables -t mangle -A OUTPUT -p tcp -m tcp --sport 8333 ! -d ${LOCALNET_V6} -j MARK --set-mark 0x4
6262
fi

contrib/verify-commits/gpg.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ else
2121
# they've created a collision for. Not the most likely attack, but preventing
2222
# it is pretty easy so we do so as a "belt-and-suspenders" measure.
2323
GPG_RES=""
24-
for LINE in "$(gpg --version)"; do
24+
for LINE in $(gpg --version); do
2525
case "$LINE" in
2626
"gpg (GnuPG) 1.4.1"*|"gpg (GnuPG) 2.0."*)
2727
echo "Please upgrade to at least gpg 2.1.10 to check for weak signatures" > /dev/stderr
@@ -35,7 +35,7 @@ else
3535
done
3636
[ "$GPG_RES" = "" ] && GPG_RES="$(printf '%s\n' "$INPUT" | gpg --trust-model always --weak-digest sha1 "$@" 2>/dev/null)"
3737
fi
38-
for LINE in $(echo "$GPG_RES"); do
38+
for LINE in $GPG_RES; do
3939
case "$LINE" in
4040
"[GNUPG:] VALIDSIG "*)
4141
while read KEY; do

contrib/verifybinaries/verify.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
export LC_ALL=C
1515
function clean_up {
16-
for file in $*
16+
for file in "$@"
1717
do
1818
rm "$file" 2> /dev/null
1919
done
@@ -82,22 +82,20 @@ else
8282
exit 2
8383
fi
8484

85-
#first we fetch the file containing the signature
86-
WGETOUT=$(wget -N "$HOST1$BASEDIR$SIGNATUREFILENAME" 2>&1)
87-
88-
#and then see if wget completed successfully
89-
if [ $? -ne 0 ]; then
85+
if ! WGETOUT=$(wget -N "$HOST1$BASEDIR$SIGNATUREFILENAME" 2>&1); then
9086
echo "Error: couldn't fetch signature file. Have you specified the version number in the following format?"
87+
# shellcheck disable=SC1087
9188
echo "[$VERSIONPREFIX]<version>-[$RCVERSIONSTRING[0-9]] (example: ${VERSIONPREFIX}0.10.4-${RCVERSIONSTRING}1)"
9289
echo "wget output:"
90+
# shellcheck disable=SC2001
9391
echo "$WGETOUT"|sed 's/^/\t/g'
9492
exit 2
9593
fi
9694

97-
WGETOUT=$(wget -N -O "$SIGNATUREFILENAME.2" "$HOST2$BASEDIR$SIGNATUREFILENAME" 2>&1)
98-
if [ $? -ne 0 ]; then
95+
if ! WGETOUT=$(wget -N -O "$SIGNATUREFILENAME.2" "$HOST2$BASEDIR$SIGNATUREFILENAME" 2>&1); then
9996
echo "bitcoin.org failed to provide signature file, but bitcoincore.org did?"
10097
echo "wget output:"
98+
# shellcheck disable=SC2001
10199
echo "$WGETOUT"|sed 's/^/\t/g'
102100
clean_up $SIGNATUREFILENAME
103101
exit 3
@@ -128,6 +126,7 @@ if [ $RET -ne 0 ]; then
128126
fi
129127

130128
echo "gpg output:"
129+
# shellcheck disable=SC2001
131130
echo "$GPGOUT"|sed 's/^/\t/g'
132131
clean_up $SIGNATUREFILENAME $SIGNATUREFILENAME.2 $TMPFILE
133132
exit "$RET"

0 commit comments

Comments
 (0)