2018-06-20 05:54:54 -04:00
|
|
|
#!/usr/bin/env bash
|
2018-04-03 10:30:55 -03:00
|
|
|
#
|
2021-07-28 07:57:16 -04:00
|
|
|
# Copyright (c) 2018-2021 The Bitcoin Core developers
|
2018-04-03 10:30:55 -03:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#
|
|
|
|
# Check for shellcheck warnings in shell scripts.
|
|
|
|
|
2018-08-02 08:32:51 -04:00
|
|
|
export LC_ALL=C
|
|
|
|
|
2018-04-03 10:30:55 -03:00
|
|
|
# Disabled warnings:
|
2019-01-14 23:55:20 -03:00
|
|
|
disabled=(
|
|
|
|
SC2162 # read without -r will mangle backslashes.
|
|
|
|
)
|
2019-11-03 15:55:06 -03:00
|
|
|
|
|
|
|
EXIT_CODE=0
|
|
|
|
|
|
|
|
if ! command -v shellcheck > /dev/null; then
|
|
|
|
echo "Skipping shell linting since shellcheck is not installed."
|
|
|
|
exit $EXIT_CODE
|
|
|
|
fi
|
|
|
|
|
2021-11-13 15:35:59 -03:00
|
|
|
SHELLCHECK_CMD=(shellcheck --external-sources --check-sourced --source-path=SCRIPTDIR)
|
2019-11-03 15:55:06 -03:00
|
|
|
EXCLUDE="--exclude=$(IFS=','; echo "${disabled[*]}")"
|
2021-11-07 09:13:39 -03:00
|
|
|
# Check shellcheck directive used for sourced files
|
|
|
|
mapfile -t SOURCED_FILES < <(git ls-files | xargs gawk '/^# shellcheck shell=/ {print FILENAME} {nextfile}')
|
2021-11-13 15:35:59 -03:00
|
|
|
mapfile -t GUIX_FILES < <(git ls-files contrib/guix contrib/shell | xargs gawk '/^#!\/usr\/bin\/env bash/ {print FILENAME} {nextfile}')
|
2021-11-07 09:37:56 -03:00
|
|
|
mapfile -t FILES < <(git ls-files -- '*.sh' | grep -vE 'src/(leveldb|secp256k1|minisketch|univalue)/')
|
2021-11-13 15:35:59 -03:00
|
|
|
if ! "${SHELLCHECK_CMD[@]}" "$EXCLUDE" "${SOURCED_FILES[@]}" "${GUIX_FILES[@]}" "${FILES[@]}"; then
|
2019-11-03 15:55:06 -03:00
|
|
|
EXIT_CODE=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit $EXIT_CODE
|