diff options
Diffstat (limited to 'debian/_buildscripts/local/scripts/_build_common.sh')
-rwxr-xr-x | debian/_buildscripts/local/scripts/_build_common.sh | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/debian/_buildscripts/local/scripts/_build_common.sh b/debian/_buildscripts/local/scripts/_build_common.sh new file mode 100755 index 000000000..41ca19cf9 --- /dev/null +++ b/debian/_buildscripts/local/scripts/_build_common.sh @@ -0,0 +1,109 @@ +#!/bin/bash + + +#---------------------------- +#---------------------------- +# Color table +# Black 0;30 Dark Gray 1;30 +# Blue 0;34 Light Blue 1;34 +# Green 0;32 Light Green 1;32 +# Cyan 0;36 Light Cyan 1;36 +# Red 0;31 Light Red 1;31 +# Purple 0;35 Light Purple 1;35 +# Brown 0;33 Yellow 1;33 +# Light Gray 0;37 White 1;37 +# No Color 0 +CBlack='\e[0;30m' +CDarkGray='\e[1;30m' +CBlue='\e[0;34m' +CLightBlue='\e[1;34m' +CGreen='\e[0;32m' +CLightGreen='\e[1;32m' +CCyan='\e[0;36m' +CLightCyan='\e[1;36m' +CRed='\e[0;31m' +CLightRed='\e[1;31m' +CPurple='\e[0;35m' +CLightPurple='\e[1;35m' +CBrown='\e[0;33m' +CYellow='\e[1;33m' +CGray='\e[0;37m' +CWhite='\e[1;37m' +CNone='\e[0m' + + +#---------------------------- +function init_common() +{ + # Check script folder + SCRIPT_DIR=$(dirname $(readlink -f "$0")) + cd $SCRIPT_DIR + BASE_DIR=${PWD##*/} + if [ "$BASE_DIR" != "scripts" ]; then + echo "This script can only be run from the script directory." + exit 1 + fi + + #---------------------------- + # TDE source folder + cd `git rev-parse --show-toplevel` + CURR_DIR=${PWD##*/} + if [ "$CURR_DIR" != "tde-packaging" ]; then + echo "Something wrong with folder structure.\nThis script should be located in the tde-packaging directory." + exit 1 + fi + cd ../.. + TDE_DIR=$PWD + cd $SCRIPT_DIR + + #---------------------------- + # Read config settings + CFG_FILE=$TDE_DIR/build_config.sh + if [ -f "$CFG_FILE" ]; then + . "$CFG_FILE" + else + echo -e "${CYellow} --- NOTE ---${CNone}" + echo "Creating TDE build configuration file from template as $CFG_FILE." + echo "Please check and modify as required, then rerun this script." + cp "$SCRIPT_DIR/_build_config_template.sh" "$CFG_FILE" + exit 0 + fi + SCRIPT_LOG_DIR=$TDE_DIR/$CFG_SCRIPT_LOG_DIR + LOG_RESULT_FILENAME="$SCRIPT_LOG_DIR/build_result.log" # Log result into the common build logfile + + cd "$SCRIPT_DIR" +} + + +#---------------------------- +# Save execution start time +# Parameters: +# $1 - timer number +function exec_time_start() +{ + _ET_start_var="_ET_start_$1" + eval "$_ET_start_var=`date +%s.%N`" +} + + +#---------------------------- +# Save execution stop time and set $2 to the execution time +# in the format: dd/hh:mm:ss.mmm +# Parameters: +# $1 - timer number +# $2 - result variable name +function exec_time_stop() +{ + _ET_start_var="_ET_start_$1" + _ET_stop_var="_ET_stop_$1" + eval "$_ET_stop_var=`date +%s.%N`" + _ET_diff=`echo "${!_ET_stop_var} - ${!_ET_start_var}" | bc` + _ET_days=`echo "$_ET_diff/86400" | bc` + _ET_diff_day=`echo "$_ET_diff-86400*$_ET_days" | bc` + _ET_hours=`echo "$_ET_diff_day/3600" | bc` + _ET_diff_hour=`echo "$_ET_diff_day-3600*$_ET_hours" | bc` + _ET_mins=`echo "$_ET_diff_hour/60" | bc` + _ET_secs=`echo "$_ET_diff_hour-60*$_ET_mins" | bc` + local _resultvar=$2 + eval "$_resultvar=`printf \"%02d/%02d:%02d:%06.3f\" $_ET_days $_ET_hours $_ET_mins $_ET_secs`" +} |