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
This commit is contained in:
Sergii Golovatiuk 2021-03-05 01:16:36 +01:00
parent ec24e3ed7a
commit 0550d6900c
1 changed files with 13 additions and 4 deletions

View File

@ -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