partial merge #16327: scripts and tools: Update ShellCheck linter

1ac454a3844b9b8389de0f660fa9455c0efa7140 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 1ac454a3844b9b8389de0f660fa9455c0efa7140
  dongcarl:
    utACK 1ac454a
  fanquake:
    ACK 1ac454a3844b9b8389de0f660fa9455c0efa7140

Tree-SHA512: 8d0a3a5c09fe1a0c22120178f5e6b80f81f746f8c3356b7701ff301c117acb2edea8fe08f08fb54ed73f94b1617515fb239fa28e7ab4121f74872e6494b6f20e
This commit is contained in:
fanquake 2019-07-05 09:00:44 +08:00 committed by UdjinM6
parent 824d6c08f9
commit ffe950bbc7
No known key found for this signature in database
GPG Key ID: 83592BD1400D58D9
15 changed files with 32 additions and 49 deletions

View File

@ -18,7 +18,7 @@ test/lint/check-doc.py
test/lint/check-rpc-mappings.py . test/lint/check-rpc-mappings.py .
test/lint/lint-all.sh test/lint/lint-all.sh
if [ "$TRAVIS_REPO_SLUG" = "bitcoin/bitcoin" -a "$TRAVIS_EVENT_TYPE" = "cron" ]; then if [ "$TRAVIS_REPO_SLUG" = "bitcoin/bitcoin" ] && [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then
git log --merges --before="2 days ago" -1 --format='%H' > ./contrib/verify-commits/trusted-sha512-root-commit git log --merges --before="2 days ago" -1 --format='%H' > ./contrib/verify-commits/trusted-sha512-root-commit
while read -r LINE; do travis_retry gpg --keyserver hkp://subset.pool.sks-keyservers.net --recv-keys $LINE; done < contrib/verify-commits/trusted-keys && while read -r LINE; do travis_retry gpg --keyserver hkp://subset.pool.sks-keyservers.net --recv-keys $LINE; done < contrib/verify-commits/trusted-keys &&
./contrib/verify-commits/verify-commits.py --clean-merge=2; ./contrib/verify-commits/verify-commits.py --clean-merge=2;

View File

@ -24,4 +24,3 @@ fi
if [ -z "$NO_DEPENDS" ]; then if [ -z "$NO_DEPENDS" ]; then
DOCKER_EXEC CONFIG_SHELL= make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS DOCKER_EXEC CONFIG_SHELL= make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS
fi fi

View File

@ -7,10 +7,10 @@ export LC_ALL=C
set -e set -e
srcdir="$(dirname $0)" srcdir="$(dirname $0)"
cd "$srcdir" cd "$srcdir"
if [ -z ${LIBTOOLIZE} ] && GLIBTOOLIZE="`which glibtoolize 2>/dev/null`"; then if [ -z ${LIBTOOLIZE} ] && GLIBTOOLIZE="$(command -v glibtoolize)"; then
LIBTOOLIZE="${GLIBTOOLIZE}" LIBTOOLIZE="${GLIBTOOLIZE}"
export LIBTOOLIZE export LIBTOOLIZE
fi fi
which autoreconf >/dev/null || \ command -v autoreconf >/dev/null || \
(echo "configuration failed, please install autoconf first" && exit 1) (echo "configuration failed, please install autoconf first" && exit 1)
autoreconf --install --force --warnings=all autoreconf --install --force --warnings=all

View File

@ -15,7 +15,7 @@ BITCOINQT=${BITCOINQT:-$BINDIR/qt/dash-qt}
[ ! -x $BITCOIND ] && echo "$BITCOIND not found or not executable." && exit 1 [ ! -x $BITCOIND ] && echo "$BITCOIND not found or not executable." && exit 1
# The autodetected version git tag can screw up manpage output a little bit # The autodetected version git tag can screw up manpage output a little bit
BTCVER=($($BITCOINCLI --version | head -n1 | awk -F'[ -]' '{ print $6, $7 }')) read -r -a BTCVER <<< "$($BITCOINCLI --version | head -n1 | awk -F'[ -]' '{ print $6, $7 }')"
# Create a footer file with copyright content. # Create a footer file with copyright content.
# This gets autodetected fine for dashd if --version-string is not set, # This gets autodetected fine for dashd if --version-string is not set,

View File

@ -36,13 +36,13 @@ if [ -z "${CODESIGN_ALLOCATE}" ]; then
fi fi
find ${TEMPDIR} -name "*.sign" | while read i; do find ${TEMPDIR} -name "*.sign" | while read i; do
SIZE=`stat -c %s "${i}"` SIZE=$(stat -c %s "${i}")
TARGET_FILE="`echo "${i}" | sed 's/\.sign$//'`" TARGET_FILE="$(echo "${i}" | sed 's/\.sign$//')"
echo "Allocating space for the signature of size ${SIZE} in ${TARGET_FILE}" echo "Allocating space for the signature of size ${SIZE} in ${TARGET_FILE}"
${CODESIGN_ALLOCATE} -i "${TARGET_FILE}" -a ${ARCH} ${SIZE} -o "${i}.tmp" ${CODESIGN_ALLOCATE} -i "${TARGET_FILE}" -a ${ARCH} ${SIZE} -o "${i}.tmp"
OFFSET=`${PAGESTUFF} "${i}.tmp" -p | tail -2 | grep offset | sed 's/[^0-9]*//g'` OFFSET=$(${PAGESTUFF} "${i}.tmp" -p | tail -2 | grep offset | sed 's/[^0-9]*//g')
if [ -z ${QUIET} ]; then if [ -z ${QUIET} ]; then
echo "Attaching signature at offset ${OFFSET}" echo "Attaching signature at offset ${OFFSET}"
fi fi

View File

@ -26,20 +26,20 @@ mkdir -p ${TEMPDIR}
${CODESIGN} -f --file-list ${TEMPLIST} -o runtime "$@" "${BUNDLE}" ${CODESIGN} -f --file-list ${TEMPLIST} -o runtime "$@" "${BUNDLE}"
grep -v CodeResources < "${TEMPLIST}" | while read i; do grep -v CodeResources < "${TEMPLIST}" | while read i; do
TARGETFILE="${BUNDLE}/`echo "${i}" | sed "s|.*${BUNDLE}/||"`" TARGETFILE="${BUNDLE}/$(echo "${i}" | sed "s|.*${BUNDLE}/||")"
SIZE=`pagestuff "$i" -p | tail -2 | grep size | sed 's/[^0-9]*//g'` SIZE=$(pagestuff "$i" -p | tail -2 | grep size | sed 's/[^0-9]*//g')
OFFSET=`pagestuff "$i" -p | tail -2 | grep offset | sed 's/[^0-9]*//g'` OFFSET=$(pagestuff "$i" -p | tail -2 | grep offset | sed 's/[^0-9]*//g')
SIGNFILE="${TEMPDIR}/${OUTROOT}/${TARGETFILE}.sign" SIGNFILE="${TEMPDIR}/${OUTROOT}/${TARGETFILE}.sign"
DIRNAME="`dirname "${SIGNFILE}"`" DIRNAME="$(dirname "${SIGNFILE}")"
mkdir -p "${DIRNAME}" mkdir -p "${DIRNAME}"
echo "Adding detached signature for: ${TARGETFILE}. Size: ${SIZE}. Offset: ${OFFSET}" echo "Adding detached signature for: ${TARGETFILE}. Size: ${SIZE}. Offset: ${OFFSET}"
dd if="$i" of="${SIGNFILE}" bs=1 skip=${OFFSET} count=${SIZE} 2>/dev/null dd if="$i" of="${SIGNFILE}" bs=1 skip=${OFFSET} count=${SIZE} 2>/dev/null
done done
grep CodeResources < "${TEMPLIST}" | while read i; do grep CodeResources < "${TEMPLIST}" | while read i; do
TARGETFILE="${BUNDLE}/`echo "${i}" | sed "s|.*${BUNDLE}/||"`" TARGETFILE="${BUNDLE}/$(echo "${i}" | sed "s|.*${BUNDLE}/||")"
RESOURCE="${TEMPDIR}/${OUTROOT}/${TARGETFILE}" RESOURCE="${TEMPDIR}/${OUTROOT}/${TARGETFILE}"
DIRNAME="`dirname "${RESOURCE}"`" DIRNAME="$(dirname "${RESOURCE}")"
mkdir -p "${DIRNAME}" mkdir -p "${DIRNAME}"
echo "Adding resource for: \"${TARGETFILE}\"" echo "Adding resource for: \"${TARGETFILE}\""
cp "${i}" "${RESOURCE}" cp "${i}" "${RESOURCE}"

View File

@ -21,7 +21,7 @@ else
# they've created a collision for. Not the most likely attack, but preventing # they've created a collision for. Not the most likely attack, but preventing
# it is pretty easy so we do so as a "belt-and-suspenders" measure. # it is pretty easy so we do so as a "belt-and-suspenders" measure.
GPG_RES="" GPG_RES=""
for LINE in "$(gpg --version)"; do for LINE in $(gpg --version); do
case "$LINE" in case "$LINE" in
"gpg (GnuPG) 1.4.1"*|"gpg (GnuPG) 2.0."*) "gpg (GnuPG) 1.4.1"*|"gpg (GnuPG) 2.0."*)
echo "Please upgrade to at least gpg 2.1.10 to check for weak signatures" > /dev/stderr echo "Please upgrade to at least gpg 2.1.10 to check for weak signatures" > /dev/stderr
@ -35,7 +35,7 @@ else
done done
[ "$GPG_RES" = "" ] && GPG_RES="$(printf '%s\n' "$INPUT" | gpg --trust-model always --weak-digest sha1 "$@" 2>/dev/null)" [ "$GPG_RES" = "" ] && GPG_RES="$(printf '%s\n' "$INPUT" | gpg --trust-model always --weak-digest sha1 "$@" 2>/dev/null)"
fi fi
for LINE in $(echo "$GPG_RES"); do for LINE in $GPG_RES; do
case "$LINE" in case "$LINE" in
"[GNUPG:] VALIDSIG "*) "[GNUPG:] VALIDSIG "*)
while read KEY; do while read KEY; do

View File

@ -13,7 +13,7 @@
export LC_ALL=C export LC_ALL=C
function clean_up { function clean_up {
for file in $* for file in "$@"
do do
rm "$file" 2> /dev/null rm "$file" 2> /dev/null
done done
@ -82,22 +82,20 @@ else
exit 2 exit 2
fi fi
#first we fetch the file containing the signature if ! WGETOUT=$(wget -N "$HOST1$BASEDIR$SIGNATUREFILENAME" 2>&1); then
WGETOUT=$(wget -N "$HOST1$BASEDIR$SIGNATUREFILENAME" 2>&1)
#and then see if wget completed successfully
if [ $? -ne 0 ]; then
echo "Error: couldn't fetch signature file. Have you specified the version number in the following format?" echo "Error: couldn't fetch signature file. Have you specified the version number in the following format?"
# shellcheck disable=SC1087
echo "[$VERSIONPREFIX]<version>-[$RCVERSIONSTRING[0-9]] (example: ${VERSIONPREFIX}0.10.4-${RCVERSIONSTRING}1)" echo "[$VERSIONPREFIX]<version>-[$RCVERSIONSTRING[0-9]] (example: ${VERSIONPREFIX}0.10.4-${RCVERSIONSTRING}1)"
echo "wget output:" echo "wget output:"
# shellcheck disable=SC2001
echo "$WGETOUT"|sed 's/^/\t/g' echo "$WGETOUT"|sed 's/^/\t/g'
exit 2 exit 2
fi fi
WGETOUT=$(wget -N -O "$SIGNATUREFILENAME.2" "$HOST2$BASEDIR$SIGNATUREFILENAME" 2>&1) if ! WGETOUT=$(wget -N -O "$SIGNATUREFILENAME.2" "$HOST2$BASEDIR$SIGNATUREFILENAME" 2>&1); then
if [ $? -ne 0 ]; then
echo "pasta.keybase.pub failed to provide signature file, but github.com did?" echo "pasta.keybase.pub failed to provide signature file, but github.com did?"
echo "wget output:" echo "wget output:"
# shellcheck disable=SC2001
echo "$WGETOUT"|sed 's/^/\t/g' echo "$WGETOUT"|sed 's/^/\t/g'
clean_up $SIGNATUREFILENAME clean_up $SIGNATUREFILENAME
exit 3 exit 3
@ -128,6 +126,7 @@ if [ $RET -ne 0 ]; then
fi fi
echo "gpg output:" echo "gpg output:"
# shellcheck disable=SC2001
echo "$GPGOUT"|sed 's/^/\t/g' echo "$GPGOUT"|sed 's/^/\t/g'
clean_up $SIGNATUREFILENAME $SIGNATUREFILENAME.2 $TMPFILE clean_up $SIGNATUREFILENAME $SIGNATUREFILENAME.2 $TMPFILE
exit "$RET" exit "$RET"

View File

@ -23,7 +23,7 @@ TIMESERVER=http://timestamp.comodoca.com
CERTFILE="win-codesign.cert" CERTFILE="win-codesign.cert"
mkdir -p "${OUTSUBDIR}" mkdir -p "${OUTSUBDIR}"
basename -a `ls -1 "${SRCDIR}"/*-unsigned.exe` | while read UNSIGNED; do basename -a $(ls -1 "${SRCDIR}"/*-unsigned.exe) | while read UNSIGNED; do
echo Signing "${UNSIGNED}" echo Signing "${UNSIGNED}"
"${OSSLSIGNCODE}" sign -certs "${CERTFILE}" -t "${TIMESERVER}" -in "${SRCDIR}/${UNSIGNED}" -out "${WORKDIR}/${UNSIGNED}" "$@" "${OSSLSIGNCODE}" sign -certs "${CERTFILE}" -t "${TIMESERVER}" -in "${SRCDIR}/${UNSIGNED}" -out "${WORKDIR}/${UNSIGNED}" "$@"
"${OSSLSIGNCODE}" extract-signature -pem -in "${WORKDIR}/${UNSIGNED}" -out "${OUTSUBDIR}/${UNSIGNED}.pem" && rm "${WORKDIR}/${UNSIGNED}" "${OSSLSIGNCODE}" extract-signature -pem -in "${WORKDIR}/${UNSIGNED}" -out "${OUTSUBDIR}/${UNSIGNED}.pem" && rm "${WORKDIR}/${UNSIGNED}"

View File

@ -24,7 +24,7 @@ git_check_in_repo() {
DESC="" DESC=""
SUFFIX="" SUFFIX=""
if [ "${BITCOIN_GENBUILD_NO_GIT}" != "1" -a -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] && git_check_in_repo share/genbuild.sh; then if [ "${BITCOIN_GENBUILD_NO_GIT}" != "1" ] && [ -e "$(command -v git)" ] && [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ] && git_check_in_repo share/genbuild.sh; then
# clean 'dirty' status of touched files that haven't been modified # clean 'dirty' status of touched files that haven't been modified
git diff >/dev/null 2>/dev/null git diff >/dev/null 2>/dev/null

View File

@ -9,6 +9,6 @@ FRAMEDIR=$(dirname $0)
for i in {0..89} for i in {0..89}
do do
frame=$(printf "%03d" $i) frame=$(printf "%03d" $i)
angle=$(($i * 4)) angle=$((i * 4))
convert $FRAMEDIR/../src/spinner.png -background "rgba(0,0,0,0.0)" -distort SRT $angle $FRAMEDIR/spinner-$frame.png convert $FRAMEDIR/../src/spinner.png -background "rgba(0,0,0,0.0)" -distort SRT $angle $FRAMEDIR/spinner-$frame.png
done done

View File

@ -18,12 +18,12 @@ if test -z "$1"; then
fi fi
RET=0 RET=0
PREV_BRANCH=`git name-rev --name-only HEAD` PREV_BRANCH=$(git name-rev --name-only HEAD)
PREV_HEAD=`git rev-parse HEAD` PREV_HEAD=$(git rev-parse HEAD)
for commit in `git rev-list --reverse $1`; do for commit in $(git rev-list --reverse $1); do
if git rev-list -n 1 --pretty="%s" $commit | grep -q "^scripted-diff:"; then if git rev-list -n 1 --pretty="%s" $commit | grep -q "^scripted-diff:"; then
git checkout --quiet $commit^ || exit git checkout --quiet $commit^ || exit
SCRIPT="`git rev-list --format=%b -n1 $commit | sed '/^-BEGIN VERIFY SCRIPT-$/,/^-END VERIFY SCRIPT-$/{//!b};d'`" SCRIPT="$(git rev-list --format=%b -n1 $commit | sed '/^-BEGIN VERIFY SCRIPT-$/,/^-END VERIFY SCRIPT-$/{//!b};d')"
if test -z "$SCRIPT"; then if test -z "$SCRIPT"; then
echo "Error: missing script for: $commit" echo "Error: missing script for: $commit"
echo "Failed" echo "Failed"

View File

@ -113,7 +113,7 @@ CIRCULAR_DEPENDENCIES=()
IFS=$'\n' IFS=$'\n'
for CIRC in $(cd src && ../contrib/devtools/circular-dependencies.py {*,*/*,*/*/*}.{h,cpp} | sed -e 's/^Circular dependency: //'); do for CIRC in $(cd src && ../contrib/devtools/circular-dependencies.py {*,*/*,*/*/*}.{h,cpp} | sed -e 's/^Circular dependency: //'); do
CIRCULAR_DEPENDENCIES+=($CIRC) CIRCULAR_DEPENDENCIES+=( "$CIRC" )
IS_EXPECTED_CIRC=0 IS_EXPECTED_CIRC=0
for EXPECTED_CIRC in "${EXPECTED_CIRCULAR_DEPENDENCIES[@]}"; do for EXPECTED_CIRC in "${EXPECTED_CIRCULAR_DEPENDENCIES[@]}"; do
if [[ "${CIRC}" == "${EXPECTED_CIRC}" ]]; then if [[ "${CIRC}" == "${EXPECTED_CIRC}" ]]; then

View File

@ -20,6 +20,7 @@ UNTERMINATED_LOGS=$(git grep --extended-regexp "LogPrintf?\(" -- "*.cpp" | \
grep -v "LogPrint()" | \ grep -v "LogPrint()" | \
grep -v "LogPrintf()") grep -v "LogPrintf()")
if [[ ${UNTERMINATED_LOGS} != "" ]]; then if [[ ${UNTERMINATED_LOGS} != "" ]]; then
# shellcheck disable=SC2028
echo "All calls to LogPrintf() and LogPrint() should be terminated with \\n" echo "All calls to LogPrintf() and LogPrint() should be terminated with \\n"
echo echo
echo "${UNTERMINATED_LOGS}" echo "${UNTERMINATED_LOGS}"

View File

@ -18,25 +18,9 @@ fi
# Disabled warnings: # Disabled warnings:
disabled=( disabled=(
SC1087 # Use braces when expanding arrays, e.g. ${array[idx]} (or ${var}[.. to quiet).
SC2001 # See if you can use ${variable//search/replace} instead.
SC2004 # $/${} is unnecessary on arithmetic variables.
SC2005 # Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.
SC2006 # Use $(..) instead of legacy `..`.
SC2016 # Expressions don't expand in single quotes, use double quotes for that.
SC2028 # echo won't expand escape sequences. Consider printf.
SC2046 # Quote this to prevent word splitting. SC2046 # Quote this to prevent word splitting.
SC2048 # Use "$@" (with quotes) to prevent whitespace problems.
SC2066 # Since you double quoted this, it will not word split, and the loop will only run once.
SC2086 # Double quote to prevent globbing and word splitting. SC2086 # Double quote to prevent globbing and word splitting.
SC2116 # Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
SC2162 # read without -r will mangle backslashes. SC2162 # read without -r will mangle backslashes.
SC2166 # Prefer [ p ] {&&,||} [ q ] as [ p -{a,o} q ] is not well defined.
SC2181 # Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.
SC2206 # Quote to prevent word splitting, or split robustly with mapfile or read -a.
SC2207 # Prefer mapfile or read -a to split command output (or quote to avoid splitting).
SC2230 # which is non-standard. Use builtin 'command -v' instead.
SC2236 # Don't force -n instead of ! -z.
) )
disabled_gitian=( disabled_gitian=(
SC2094 # Make sure not to read and write the same file in the same pipeline. SC2094 # Make sure not to read and write the same file in the same pipeline.