From 30d5ba634a5c249697509d7c4f29f4aca0597457 Mon Sep 17 00:00:00 2001 From: Alexandru Avadanii Date: Fri, 26 Jan 2018 03:50:10 +0100 Subject: deploy.sh: Move notify() to globals.sh Extend `notify` to 4 variants: - notify_i = inline (no newline) colored output; - notify = `notify_i` + trailing '\n'; - notify_n = `notify` + extra '\n' before and after; - notify_e = `notify` + stderr output + exit; This allows us to remove '\n' and cleanup the code a bit. While at it, fix some 'NOTE' messages going to stderr instead of stdout. Change-Id: I682e3344ae9e307c4a68ab31c7766bc91b12ee58 Signed-off-by: Alexandru Avadanii --- mcp/scripts/globals.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'mcp') diff --git a/mcp/scripts/globals.sh b/mcp/scripts/globals.sh index fe8d7a3f9..ace1de3a1 100644 --- a/mcp/scripts/globals.sh +++ b/mcp/scripts/globals.sh @@ -17,3 +17,31 @@ export MAAS_IP=${MAAS_IP:-${SALT_MASTER%.*}.3} # Derivated from above global vars export SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${SSH_KEY}" export SSH_SALT="${SALT_MASTER_USER}@${SALT_MASTER}" + +############################################################################## +# BEGIN of colored notification wrappers +# +function notify() { + local msg=${1}; shift + notify_i "${msg}\n" "$@" +} + +function notify_i() { + tput setaf "${2:-1}" || true + echo -en "${1:-"[WARN] Unsupported opt arg: $3\\n"}" + tput sgr0 +} + +function notify_n() { + local msg=${1}; shift + notify_i "\n${msg}\n\n" "$@" +} + +function notify_e() { + local msg=${1}; shift + notify_i "\n${msg}\n\n" "$@" 1>&2 + exit 1 +} +# +# END of colored notification wrapper +############################################################################## -- cgit 1.2.3-korg