Zack Williams | 32293ee | 2018-05-18 09:15:13 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Joey Armstrong | 56fdfec | 2024-03-01 13:43:36 -0500 | [diff] [blame] | 2 | # ----------------------------------------------------------------------- |
| 3 | # Copyright 2017-2024 Open Networking Foundation Contributors |
Zack Williams | 32293ee | 2018-05-18 09:15:13 -0700 | [diff] [blame] | 4 | # |
| 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 Armstrong | 56fdfec | 2024-03-01 13:43:36 -0500 | [diff] [blame] | 9 | # http:#www.apache.org/licenses/LICENSE-2.0 |
Zack Williams | 32293ee | 2018-05-18 09:15:13 -0700 | [diff] [blame] | 10 | # |
| 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 Armstrong | 56fdfec | 2024-03-01 13:43:36 -0500 | [diff] [blame] | 16 | # ----------------------------------------------------------------------- |
| 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 Williams | 32293ee | 2018-05-18 09:15:13 -0700 | [diff] [blame] | 24 | |
| 25 | set +e -u -o pipefail |
| 26 | fail_shellcheck=0 |
| 27 | |
| 28 | # verify that we have shellcheck-lint installed |
Joey Armstrong | 2987412 | 2023-09-21 12:34:34 -0400 | [diff] [blame] | 29 | command -v shellcheck >/dev/null 2>&1 \ |
| 30 | || { echo "shellcheck not found, please install it" >&2; exit 1; } |
Zack Williams | 32293ee | 2018-05-18 09:15:13 -0700 | [diff] [blame] | 31 | |
| 32 | # when not running under Jenkins, use current dir as workspace |
| 33 | WORKSPACE=${WORKSPACE:-.} |
| 34 | |
| 35 | echo "=> Linting shell script with $(shellcheck --version)" |
| 36 | |
| 37 | while IFS= read -r -d '' sf |
| 38 | do |
| 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 |
| 46 | done < <(find "${WORKSPACE}" \( -name "*.sh" -o -name "*.bash" \) -print0) |
| 47 | |
| 48 | exit ${fail_shellcheck} |
| 49 | |
Joey Armstrong | 2987412 | 2023-09-21 12:34:34 -0400 | [diff] [blame] | 50 | # [EOF] |