From 0550d6900ca074e0ecb7bef4ceb499d427360c62 Mon Sep 17 00:00:00 2001 From: Sergii Golovatiuk Date: Fri, 5 Mar 2021 01:16:36 +0100 Subject: [PATCH] Fix unbound variable If operator runs script without any variables it will fail as scripts/run-local-test: line 26: $1: unbound variable This patch adds usage function and check if script is run without ROLE_NAME Change-Id: I9137821c8396568be125ec686bad2534f9d433b2 --- scripts/run-local-test | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/run-local-test b/scripts/run-local-test index debd1a0f9..9e724e6f8 100755 --- a/scripts/run-local-test +++ b/scripts/run-local-test @@ -15,17 +15,26 @@ # under the License. -## Shell Opts ---------------------------------------------------------------- - -set -o pipefail -set -xeuo +## Functions ----------------------------------------------------------------- +function usage { + echo "Usage: ROLE_NAME=ROLE_NAME ${0##*/} or ${0##*/} ROLE_NAME" +} ## Vars ---------------------------------------------------------------------- export PROJECT_DIR="$(dirname $(readlink -f ${BASH_SOURCE[0]}))/../" +if [ "${ROLE_NAME}x" = "x" -a "${1}x" = "x" ]; then + usage; + exit 2 +fi export ROLE_NAME="${ROLE_NAME:-$1}" export TRIPLEO_JOB_ANSIBLE_ARGS=${TRIPLEO_JOB_ANSIBLE_ARGS:-""} +## Shell Opts ---------------------------------------------------------------- + +set -o pipefail +set -xeuo + ## Main ---------------------------------------------------------------------- # Source distribution information