Ajout paramètre pour définir des opts par défaut + couleur dans la sortie

This commit is contained in:
2015-10-22 16:55:54 +02:00
parent 8afd107858
commit 30332dc5cb
6 changed files with 78 additions and 29 deletions

View File

@ -34,7 +34,7 @@ function build_project()
cd "${workspace}"
dpkg-buildpackage -b -a "${TARGET_ARCH}" 2> >(error) 1> >(info)
dpkg-buildpackage -b -a "${TARGET_ARCH}" 2> >(stderr) 1> >(stdout)
if [ $? != 0 ]; then
fatal "The build process has not completed successfuly !"

View File

@ -6,7 +6,7 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source "${DIR}/util.sh"
info "Updating packages definition..."
apt-get update 2> >(error) 1> >(info)
apt-get update 2> >(stderr) 1> >(stdout)
info "Installing package $1..."
gdebi --n "$1" 2> >(error) 1> >(info)
gdebi --n "$1" 2> >(stderr) 1> >(stdout)

View File

@ -1,9 +1,40 @@
#!/usr/bin/env bash
HOOKS_DIR="${BASE_DIR}/hooks"
DEFAULT_OPTS_FILE="${BASE_DIR}/default_opts"
OPT_FILE="${BASE_DIR}/tmp/.tamarin_opts"
OPT_PREFIX="tamarin_opt_"
# Colors
COLOR_INFO='\e[0;36m'
COLOR_FATAL='\e[0;31m'
COLOR_WARN='\e[0;33m'
COLOR_SUCCESS='\e[0;32m'
COLOR_ERR='\e[0;37m'
COLOR_OUT='\e[0;37m'
COLOR_DEBUG='\e[0;35m'
function stderr {
if [ -z "$@" ]; then
while read str; do
log ERR "${str}"
done
else
log stderr "$@"
fi
}
function stdout {
if [ -z "$@" ]; then
while read str; do
log OUT "${str}"
done
else
log OUT "$@"
fi
}
function info {
if [ -z "$@" ]; then
while read str; do
@ -14,6 +45,16 @@ function info {
fi
}
function warn {
if [ -z "$@" ]; then
while read str; do
log WARN "${str}"
done
else
log WARN "$@"
fi
}
function debug {
if [ -z "$@" ]; then
while read str; do
@ -24,16 +65,6 @@ function debug {
fi
}
function error {
if [ -z "$@" ]; then
while read str; do
log ERROR "${str}" >&2
done
else
log ERROR "$@" >&2
fi
}
function fatal {
if [ -z "$@" ]; then
while read str; do
@ -45,9 +76,24 @@ function fatal {
exit 1
}
function success {
if [ -z "$@" ]; then
while read str; do
log SUCCESS "${str}"
done
else
log SUCCESS "$@"
fi
}
function log {
local args=( $@ )
echo "[${HOSTNAME}] [${args[0]}] ${args[@]:1}"
local color=COLOR_${args[0]}
echo -e "${!color}[${HOSTNAME}] [${args[0]}] $(remove_ansi ${args[@]:1})\e[0m"
}
function remove_ansi {
echo "$@" | sed 's,\x1B\[[0-9;]*[a-zA-Z],,g'
}
function get_opt {
@ -75,16 +121,16 @@ function exec_hooks {
for hook_script in ${hook_scripts}; do
info "[${hook}] Executing ${hook_script}"
info "[${hook}] >> ${hook_script}"
( cd "${workspace}" && "${hook_script}" ) 2> >(error) 1> >(info)
( cd "${workspace}" && "${hook_script}" ) 2> >(stderr) 1> >(stdout)
# If the script did not execute properly, we stop here
if [ $? != 0 ]; then
fatal "The '${hook_script}' hook script did not finished properly !"
fi
info "[${hook}] ${hook_script} Done."
info "[${hook}] << ${hook_script}"
done