From 5c205225d46dffaae321d28836fdcd863a09daae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Tue, 2 Oct 2018 22:06:09 +0200 Subject: [PATCH] common-helpers.inc: Some ErrorOut / EvalEx rework MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ErrorOut outputs to stderr * Start message is magenta now * Add EvalExAuto which creates end messages from first word in start message Signed-off-by: Andreas Müller --- scripts/include/common-helpers.inc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/include/common-helpers.inc b/scripts/include/common-helpers.inc index 4821107..be131d3 100644 --- a/scripts/include/common-helpers.inc +++ b/scripts/include/common-helpers.inc @@ -37,9 +37,7 @@ base_tempdir=`dirname "$base_tempdir"` # ErrorOut outputs error text in first param and exits script ErrorOut() { - echo - echo -e "${style_red}${style_bold}${1}${style_normal}" - echo + echo -e "\n${style_red}${style_bold}${1}${style_normal}\n" >&2 exit -1 } @@ -51,7 +49,7 @@ ErrorOut() { # 4. Message on error end EvalEx() { if [ -n "${2}" ] ; then - echo -e "${style_blue}${2}${style_normal}" + echo -e "${style_magenta}${2}${style_normal}" fi if eval ${1} ; then if [ -n "${3}" ] ; then @@ -66,6 +64,19 @@ EvalEx() { fi } +# EvalExAuto is similar it EvalEx and expectes the following parameters: +# 1. Command +# 2. Message on start +# The end messages are created by extracting first word of start message +# and appening 'done' respectively 'failed' +EvalExAuto() { + # Catch 'Start...' case + StartAligned=`echo $2 | sed 's:\.: :'` + EndMessageOk="`echo $StartAligned | awk '{ print $1 }'` done." + EndMessageFail="`echo $StartAligned | awk '{ print $1 }'` failed!" + EvalEx "$1" "$2" "$EndMessageOk" "$EndMessageFail" +} + # CheckPrerequisite checks if required hosttool is found on host. In case not # it outputs a message and exits script. CheckPrerequisite() {