reformatting

This commit is contained in:
Nathaniel Landau
2016-04-06 15:02:41 -04:00
parent 26e3c3aa25
commit 239bff84bf

View File

@@ -12,13 +12,12 @@ version="1.0.0" # Sets version variable
function mainScript() { function mainScript() {
# USE THIS SPACE FOR THE MAIN FUNCTIONALITY OF THE SCRIPT
# --------------------------------------------------------
echo -n echo -n
} }
## SET SCRIPTNAME VARIABLE ##
scriptName=$(basename "$0")
function trapCleanup() { function trapCleanup() {
# trapCleanup Function # trapCleanup Function
# ----------------------------------- # -----------------------------------
@@ -185,41 +184,38 @@ blue=$(tput setaf 38)
underline=$(tput sgr 0 1) underline=$(tput sgr 0 1)
function _alert() { function _alert() {
if [ "${1}" = "emergency" ]; then local color="${bold}${red}"; fi if [ "${1}" = "error" ]; then local color="${bold}${red}"; fi
if [ "${1}" = "error" ] || [ "${1}" = "warning" ]; then local color="${red}"; fi if [ "${1}" = "warning" ]; then local color="${red}"; fi
if [ "${1}" = "success" ]; then local color="${green}"; fi if [ "${1}" = "success" ]; then local color="${green}"; fi
if [ "${1}" = "debug" ]; then local color="${purple}"; fi if [ "${1}" = "debug" ]; then local color="${purple}"; fi
if [ "${1}" = "header" ]; then local color="${bold}""${tan}"; fi if [ "${1}" = "header" ]; then local color="${bold}""${tan}"; fi
if [ "${1}" = "input" ]; then local color="${bold}"; printLog="0"; fi if [ "${1}" = "input" ]; then local color="${bold}"; fi
if [ "${1}" = "info" ] || [ "${1}" = "notice" ]; then local color=""; fi if [ "${1}" = "info" ] || [ "${1}" = "notice" ]; then local color=""; fi
# Don't use colors on pipes or non-recognized terminals # Don't use colors on pipes or non-recognized terminals
if [[ "${TERM}" != "xterm"* ]] || [ -t 1 ]; then color=""; reset=""; fi if [[ "${TERM}" != "xterm"* ]] || [ -t 1 ]; then color=""; reset=""; fi
# Print to $logFile # Print to console when script is not 'quiet'
if ${printLog}; then if ${quiet}; then return; else
echo -e "$(date +"%m-%d-%Y %r") $(printf "[%9s]" "${1}") ${_message}" >> "${logFile}"; echo -e "$(date +"%r") ${color}$(printf "[%7s]" "${1}") ${_message}${reset}";
fi fi
# Print to console when script is not 'quiet' # Print to Logfile
if ${quiet}; then if ${printLog} && [ "${1}" != "input" ]; then
return color=""; reset="" # Don't use colors in logs
else echo -e "$(date +"%m-%d-%Y %r") $(printf "[%7s]" "${1}") ${_message}" >> "${logFile}";
echo -e "$(date +"%r") ${color}$(printf "[%9s]" "${1}") ${_message}${reset}";
fi fi
} }
function die () { local _message="${*} Exiting."; echo "$(_alert emergency)"; safeExit;} function die () { local _message="${*} Exiting."; echo -e "$(_alert error)"; safeExit;}
function error () { local _message="${*}"; echo "$(_alert error)"; } function error () { local _message="${*}"; echo -e "$(_alert error)"; }
function warning () { local _message="${*}"; echo "$(_alert warning)"; } function warning () { local _message="${*}"; echo -e "$(_alert warning)"; }
function notice () { local _message="${*}"; echo "$(_alert notice)"; } function notice () { local _message="${*}"; echo -e "$(_alert notice)"; }
function info () { local _message="${*}"; echo "$(_alert info)"; } function info () { local _message="${*}"; echo -e "$(_alert info)"; }
function debug () { local _message="${*}"; echo "$(_alert debug)"; } function debug () { local _message="${*}"; echo -e "$(_alert debug)"; }
function success () { local _message="${*}"; echo "$(_alert success)"; } function success () { local _message="${*}"; echo -e "$(_alert success)"; }
function input() { local _message="${*}"; echo -n "$(_alert input)"; } function input() { local _message="${*}"; echo -n "$(_alert input)"; }
function header() { local _message="========== ${*} ========== "; echo "$(_alert header)"; } function header() { local _message="== ${*} == "; echo -e "$(_alert header)"; }
function verbose() { if ${verbose}; then debug "$@"; fi }
# Log messages when verbose is set to "true"
verbose() { if ${verbose}; then debug "$@"; fi }
# Trap bad exits with your cleanup function # Trap bad exits with your cleanup function
trap trapCleanup EXIT INT TERM trap trapCleanup EXIT INT TERM