blob: 9b5f5d94307b2a4b2fbf06f358c27ab75d433907 [file] [log] [blame]
Jeremy Ronquillo6be909e2020-08-24 09:36:13 -07001#!/usr/bin/env bash
2
3# Copyright 2017-present Open Networking Foundation
4#
Andy Bavier2c427732022-02-03 15:16:46 -07005# SPDX-License-Identifier: Apache-2.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