blob: 9c659eb6f23a826d59c5afd5524a24dfa070f70f [file] [log] [blame]
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -07001#!/usr/bin/env bash
2
3# Copyright 2017-present Open Networking Foundation
4#
Jeremy Ronquillo5263c732020-10-13 09:42:19 -07005# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -07006
7# shcheck.sh - check shell scripts with shellcheck
8
9set +e -u -o pipefail
10fail_shellcheck=0
11
12# verify that we have shellcheck-lint installed
13command -v shellcheck >/dev/null 2>&1 || { echo "shellcheck not found, please install it" >&2; exit 1; }
14
15# when not running under Jenkins, use current dir as workspace
16WORKSPACE=${WORKSPACE:-.}
17
18echo "=> Linting shell script with $(shellcheck --version)"
19
20while IFS= read -r -d '' sf
21do
22 echo "==> CHECKING: ${sf}"
23 shellcheck "${sf}"
24 rc=$?
25 if [[ $rc != 0 ]]; then
26 echo "==> LINTING FAIL: ${sf}"
27 fail_shellcheck=1
28 fi
29done < <(find "${WORKSPACE}" \( -name "*.sh" -o -name "*.bash" \) -print0)
30
31exit ${fail_shellcheck}
32