#!/bin/bash
|
#!/bin/bash
|
# Xanthopoulos Constantinos
|
# Xanthopoulos Constantinos
|
# Some useful function for my scripts
|
# Some useful function for my scripts
|
|
|
function cecho
|
function cecho
|
{
|
{
|
echo -e "\033[1m\033[33m$1\033[0m"
|
echo -e "\033[1m\033[33m$1\033[0m"
|
echo -e "\033[1m\033[33m$1\033[0m" >> ${DIR_TO_INSTALL}/progress.log
|
echo -e "\033[1m\033[33m$1\033[0m" >> ${SCRIPT_DIR}/progress.log
|
}
|
}
|
|
|
function cnecho
|
function cnecho
|
{
|
{
|
echo -e -n "\033[0m\033[33m$1\033[0m"
|
echo -e -n "\033[0m\033[33m$1\033[0m"
|
echo -e -n "\033[0m\033[33m$1\033[0m" >> ${DIR_TO_INSTALL}/progress.log
|
echo -e -n "\033[0m\033[33m$1\033[0m" >> ${SCRIPT_DIR}/progress.log
|
}
|
}
|
|
|
function errormsg
|
function errormsg
|
{
|
{
|
echo -e "\033[1m\033[31mError: $1\033[0m\n";
|
echo -e "\033[1m\033[31mError: $1\033[0m\n";
|
echo -e "\033[1m\033[31mError: $1\033[0m\n" >> ${DIR_TO_INSTALL}/error.log
|
echo -e "\033[1m\033[31mError: $1\033[0m\n" >> ${SCRIPT_DIR}/error.log
|
exit 1;
|
exit 1;
|
}
|
}
|
|
|
function _execcmd
|
function _execcmd
|
{
|
{
|
# Print Message
|
# Print Message
|
echo -e "\033[35m$1...\033[0m\n" >> ${DIR_TO_INSTALL}/progress.log
|
echo -e "\033[35m$1...\033[0m\n" >> ${SCRIPT_DIR}/progress.log
|
if [ -n "$1" ]
|
if [ -n "$1" ]
|
then
|
then
|
echo -e -n "\033[35m$1...\033[0m"
|
echo -e -n "\033[35m$1...\033[0m"
|
fi
|
fi
|
# Execute command
|
# Execute command
|
if [ $DEBUG -ne 1 ];
|
if [ $DEBUG -ne 1 ];
|
then
|
then
|
eval $2 1>>${DIR_TO_INSTALL}/progress.log 2>>${DIR_TO_INSTALL}/error.log;
|
eval $2 1>>${SCRIPT_DIR}/progress.log 2>>${SCRIPT_DIR}/error.log;
|
fi;
|
fi;
|
# Check Execution
|
# Check Execution
|
if [ $? -eq 0 ]
|
if [ $? -eq 0 ]
|
then
|
then
|
if [ -n "$1" ]
|
if [ -n "$1" ]
|
then
|
then
|
echo -e "\033[32mcomplete\033[0m";
|
echo -e "\033[32mcomplete\033[0m";
|
echo -e "\033[32mcomplete\033[0m" >> ${DIR_TO_INSTALL}/progress.log
|
echo -e "\033[32mcomplete\033[0m" >> ${SCRIPT_DIR}/progress.log
|
fi
|
fi
|
else
|
else
|
errormsg "Command: $2 Description: $1";
|
errormsg "Command: $2 Description: $1";
|
exit 1;
|
exit 1;
|
fi
|
fi
|
}
|
}
|
|
|
function execcmd
|
function execcmd
|
{
|
{
|
if [ -z "$2" ]
|
if [ -z "$2" ]
|
then
|
then
|
_execcmd "" "$1"
|
_execcmd "" "$1"
|
else
|
else
|
_execcmd "$1" "$2"
|
_execcmd "$1" "$2"
|
fi
|
fi
|
}
|
}
|
|
|
if [ $DEBUG -eq 1 ]
|
if [ $DEBUG -eq 1 ]
|
then
|
then
|
cecho "Debug mode on! Nothing will actually run";
|
cecho "Debug mode on! Nothing will actually run";
|
fi
|
fi
|
|
|