common-helpers.inc: Some ErrorOut / EvalEx rework

* 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 <schnitzeltony@gmail.com>
This commit is contained in:
Andreas Müller
2018-10-02 22:06:09 +02:00
parent 0fc0a4a9cd
commit 5c205225d4

View File

@@ -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() {