#!/bin/bash
#========================================================
# [Cmd]
#========================================================
PATH=/bin:/usr/bin:/sbin:/usr/sbin
BIN="/usr/bin"
GREP="${BIN}/grep"
CAT="${BIN}/cat"
FIND="${BIN}/find"
XARGS="${BIN}/xargs"
TOUCH="${BIN}/touch"
RM="${BIN}/rm"
SED="${BIN}/sed"
WHOAMI="${BIN}/whoami"
CUT="${BIN}/cut"
SORT="${BIN}/sort"
EXPR="${BIN}/expr"
MKDIR="${BIN}/mkdir"
MV="${BIN}/mv"
UNIQ="${BIN}/uniq"
CP="${BIN}/cp"
LN="${BIN}/ln"
LS="${BIN}/ls"
#========================================================
# [Directory and file]
#========================================================
rw_base_dir="/opt/share/security-config"
ro_base_dir="/usr/share/security-config"
utils_dir="$ro_base_dir/test/utils"
aslr_script_dir="$ro_base_dir/test/aslr_test/scripts"
dep_script_dir="$ro_base_dir/test/dep_test/scripts"
suid_script_dir="$ro_base_dir/test/setuid_test"
log_dir="$rw_base_dir/log"
result_dir="$rw_base_dir/result"

#========================================================
# [Functions]
#========================================================
#========================================================
# [fn] Change console color
#========================================================
RESET=0;BRIGHT=1;DIM=2;ITALIC=3;UNDERLINE=4
BLINK_SLOW=5;BLINK_RAPID=6;REVERSE=7;HIDDEN=8

BLACK=0;RED=1;GREEN=2;YELLOW=3
BLUE=4;MAGENTA=5;CYAN=6;WHITE=7

FONT_OFFSET=30
BACK_OFFSET=40

# Ignore Background now
function fnChangeConsoleColor {

	argc=$#
	if [ $argc -eq 3 ]; then
		FontColor=`expr $2 + $FONT_OFFSET`
		cmd="\e[$1;$FontColor""m"
		echo -e $cmd
	else
		echo "[Usage] ChangeConsoleColor Brightness FontColor BackColor"
	fi

}

function fnRestoreOriginalColor {

	echo -e "\e[m";

}

#=========================================================
# [fn] Modified echo
#=========================================================
#echo Info
function echoI {

	fnChangeConsoleColor $BRIGHT $BLUE $BLACK
	echo "========================================================="
	echo $@
	echo "========================================================="
	fnRestoreOriginalColor

}

# echo Success
function echoS {

	fnChangeConsoleColor $BRIGHT $GREEN $BLACK
	echo $@
	fnRestoreOriginalColor

}

# echo Error
function echoE {

	fnChangeConsoleColor $BRIGHT $RED $BLACK
	echo $@
	fnRestoreOriginalColor

}

#=========================================================
# [fn] Print done
#=========================================================
function fnPrintSDone {

	echoS "Successfully Done!"

}

#=========================================================
# [fn] Finish the script
#=========================================================
function fnFinishThisScript {

	ret_val=$1

	if [ $ret_val -eq 0 ]
	then
		echoS "This script has completed successfully."
	else
		echoE "An error has occurred in this script."
	fi

	exit $ret_val

}
