blob: d1fbc4a2006883e712557b276a5c3d0ae6eb0005 [file] [log] [blame]
Zack Williams32293ee2018-05-18 09:15:13 -07001#!/usr/bin/env bash
Joey Armstrong56fdfec2024-03-01 13:43:36 -05002# -----------------------------------------------------------------------
3# Copyright 2017-2024 Open Networking Foundation Contributors
Zack Williams32293ee2018-05-18 09:15:13 -07004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
Joey Armstrong56fdfec2024-03-01 13:43:36 -05009# http:#www.apache.org/licenses/LICENSE-2.0
Zack Williams32293ee2018-05-18 09:15:13 -070010#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Joey Armstrong56fdfec2024-03-01 13:43:36 -050016# -----------------------------------------------------------------------
17# SPDX-FileCopyrightText: 2017-2024 Open Networking Foundation Contributors
18# SPDX-License-Identifier: Apache-2.0
19# -----------------------------------------------------------------------
20# Entropy: 0fcb5ffa-d1a4-11ee-be5e-9f44b7181764
21# -----------------------------------------------------------------------
22# Intent: Syntax check shell scripts with shellcheck
23# -----------------------------------------------------------------------
Zack Williams32293ee2018-05-18 09:15:13 -070024
25set +e -u -o pipefail
26fail_shellcheck=0
27
28# verify that we have shellcheck-lint installed
Joey Armstrong29874122023-09-21 12:34:34 -040029command -v shellcheck >/dev/null 2>&1 \
30 || { echo "shellcheck not found, please install it" >&2; exit 1; }
Zack Williams32293ee2018-05-18 09:15:13 -070031
32# when not running under Jenkins, use current dir as workspace
33WORKSPACE=${WORKSPACE:-.}
34
35echo "=> Linting shell script with $(shellcheck --version)"
36
37while IFS= read -r -d '' sf
38do
39 echo "==> CHECKING: ${sf}"
40 shellcheck "${sf}"
41 rc=$?
42 if [[ $rc != 0 ]]; then
43 echo "==> LINTING FAIL: ${sf}"
44 fail_shellcheck=1
45 fi
46done < <(find "${WORKSPACE}" \( -name "*.sh" -o -name "*.bash" \) -print0)
47
48exit ${fail_shellcheck}
49
Joey Armstrong29874122023-09-21 12:34:34 -040050# [EOF]