2015-07-02 14:04:14 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2015-08-05 15:49:04 +02:00
|
|
|
HOOKS_DIR="${BASE_DIR}/hooks"
|
2015-10-29 17:40:26 +01:00
|
|
|
DEFAULT_OPTS_FILE="${BASE_DIR}/tmp/default_opts"
|
|
|
|
OPT_FILE="${BASE_DIR}/tmp/tamarin/opts"
|
2015-09-23 21:21:30 +02:00
|
|
|
OPT_PREFIX="tamarin_opt_"
|
2015-08-04 23:58:43 +02:00
|
|
|
|
2015-10-22 16:55:54 +02:00
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
2015-07-02 14:04:14 +02:00
|
|
|
function info {
|
2015-08-05 15:49:04 +02:00
|
|
|
if [ -z "$@" ]; then
|
|
|
|
while read str; do
|
|
|
|
log INFO "${str}"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
log INFO "$@"
|
|
|
|
fi
|
2015-07-02 14:04:14 +02:00
|
|
|
}
|
|
|
|
|
2015-10-22 16:55:54 +02:00
|
|
|
function warn {
|
2015-08-05 15:49:04 +02:00
|
|
|
if [ -z "$@" ]; then
|
|
|
|
while read str; do
|
2015-10-22 16:55:54 +02:00
|
|
|
log WARN "${str}"
|
2015-08-05 15:49:04 +02:00
|
|
|
done
|
|
|
|
else
|
2015-10-22 16:55:54 +02:00
|
|
|
log WARN "$@"
|
2015-08-05 15:49:04 +02:00
|
|
|
fi
|
2015-07-02 14:04:14 +02:00
|
|
|
}
|
|
|
|
|
2015-10-22 16:55:54 +02:00
|
|
|
function debug {
|
2015-08-05 15:49:04 +02:00
|
|
|
if [ -z "$@" ]; then
|
|
|
|
while read str; do
|
2015-10-22 16:55:54 +02:00
|
|
|
log DEBUG "${str}"
|
2015-08-05 15:49:04 +02:00
|
|
|
done
|
|
|
|
else
|
2015-10-22 16:55:54 +02:00
|
|
|
log DEBUG "$@"
|
2015-08-05 15:49:04 +02:00
|
|
|
fi
|
2015-07-02 14:04:14 +02:00
|
|
|
}
|
|
|
|
|
2015-07-04 18:45:36 +02:00
|
|
|
function fatal {
|
2015-08-05 15:49:04 +02:00
|
|
|
if [ -z "$@" ]; then
|
|
|
|
while read str; do
|
|
|
|
log FATAL "${str}" >&2
|
|
|
|
done
|
|
|
|
else
|
|
|
|
log FATAL "$@" >&2
|
|
|
|
fi
|
2015-07-02 14:04:14 +02:00
|
|
|
exit 1
|
|
|
|
}
|
2015-08-04 23:58:43 +02:00
|
|
|
|
2015-10-22 16:55:54 +02:00
|
|
|
function success {
|
|
|
|
if [ -z "$@" ]; then
|
|
|
|
while read str; do
|
|
|
|
log SUCCESS "${str}"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
log SUCCESS "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-08-05 15:49:04 +02:00
|
|
|
function log {
|
|
|
|
local args=( $@ )
|
2015-10-22 16:55:54 +02:00
|
|
|
local color=COLOR_${args[0]}
|
2015-10-29 17:40:26 +01:00
|
|
|
echo -e "${!color}[${args[0]}] $(remove_ansi ${args[@]:1})\e[0m"
|
2015-10-22 16:55:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function remove_ansi {
|
|
|
|
echo "$@" | sed 's,\x1B\[[0-9;]*[a-zA-Z],,g'
|
2015-08-05 15:49:04 +02:00
|
|
|
}
|
|
|
|
|
2015-10-29 17:40:26 +01:00
|
|
|
function load_default_opts {
|
|
|
|
if [[ -e "${DEFAULT_OPTS_FILE}" ]]; then
|
|
|
|
info "Loading default opts..."
|
|
|
|
else
|
|
|
|
info "No default opts found."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-08-04 23:58:43 +02:00
|
|
|
function get_opt {
|
2015-09-23 21:21:30 +02:00
|
|
|
local opt_name=${OPT_PREFIX}${1}
|
2015-08-05 15:49:04 +02:00
|
|
|
local default_value=${2}
|
|
|
|
touch "${OPT_FILE}"
|
|
|
|
source "${OPT_FILE}"
|
|
|
|
echo ${!opt_name:-${default_value}}
|
2015-08-04 23:58:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function set_opt {
|
2015-08-05 15:49:04 +02:00
|
|
|
local opt_name=${1}
|
|
|
|
local opt_value=${2}
|
2015-10-29 17:40:26 +01:00
|
|
|
mkdir -p "$(dirname ${OPT_FILE})"
|
2015-08-05 15:49:04 +02:00
|
|
|
touch "${OPT_FILE}"
|
2015-09-23 21:21:30 +02:00
|
|
|
sed -i "s/^${OPT_PREFIX}${opt_name}*$//" "${OPT_FILE}"
|
|
|
|
echo "${OPT_PREFIX}${opt_name}=\"${opt_value}\"" >> "${OPT_FILE}"
|
2015-08-05 15:49:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function exec_hooks {
|
|
|
|
|
|
|
|
local hook=${1}
|
|
|
|
local workspace=${2}
|
|
|
|
|
2015-10-20 17:17:02 +02:00
|
|
|
local hook_scripts=$( find "${HOOKS_DIR}" -type f -name "*${hook}" -executable | sort )
|
2015-08-05 15:49:04 +02:00
|
|
|
|
|
|
|
for hook_script in ${hook_scripts}; do
|
|
|
|
|
2015-10-29 17:40:26 +01:00
|
|
|
info "[>> ${hook}] ${hook_script}"
|
2015-08-05 15:49:04 +02:00
|
|
|
|
2015-10-22 16:55:54 +02:00
|
|
|
( cd "${workspace}" && "${hook_script}" ) 2> >(stderr) 1> >(stdout)
|
2015-08-05 15:49:04 +02:00
|
|
|
|
|
|
|
# If the script did not execute properly, we stop here
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
fatal "The '${hook_script}' hook script did not finished properly !"
|
|
|
|
fi
|
|
|
|
|
2015-10-29 17:40:26 +01:00
|
|
|
info "[<< ${hook}] ${hook_script}"
|
2015-08-05 15:49:04 +02:00
|
|
|
|
|
|
|
done
|
|
|
|
|
2015-08-04 23:58:43 +02:00
|
|
|
}
|