From b8353ec752fc94890a2ed584b35a1fb93bbe2b9a Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Thu, 3 Dec 2020 11:17:12 +0200 Subject: [PATCH] [#1574] add tools/shellcheck-all.sh --- tools/shellcheck-all.sh | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 tools/shellcheck-all.sh diff --git a/tools/shellcheck-all.sh b/tools/shellcheck-all.sh new file mode 100755 index 0000000000..b6d9601ff6 --- /dev/null +++ b/tools/shellcheck-all.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +# Copyright (C) 2020 Internet Systems Consortium, Inc. ("ISC") +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# Usage: +# +# ./tools/shellcheck-all.sh [-d|--debug] [-h|--help] +# +# Run to shellcheck all shell scripts inside this repository. + +# Exit with error if commands exit with non-zero and if undefined variables are +# used. +set -eu + +# Print usage. +print_usage() { + printf \ +'Usage: %s {{options}} +Options: + [-d|--debug] enable debug mode, showing every executed command + [-h|--help] print usage (this text) +' \ + "$(basename "${0}")" +} + +# Define some ANSI color codes. +if test -t 1; then + red='\033[91m' + reset='\033[0m' +else + red= + reset= +fi + +# Parse parameters. +while test ${#} -gt 0; do + case "${1}" in + # [-d|--debug] enable debug mode, showing every executed command + '-d'|'--debug') set -vx ;; + + # [-h|--help] print usage (this text). + '-h'|'--help') print_usage ;; + + # Unrecognized argument + *) + printf "${red}ERROR: Unrecognized argument '%s'${reset}\\n" "${1}" 1>&2; print_usage; exit 1 ;; + esac; shift +done + +# Change directory to Kea' top level build directory. +root_path=$(cd "$(dirname "${0}")/.." && pwd) +cd "${root_path}" + +# shellcheck disable=SC2046 +shellcheck $(grep -F 'SCRIPTS+=' ./.gitlab-ci.yml | cut -d '"' -f 2 | xargs | sort -uV)