|
@@ -10,8 +10,8 @@ init () {
|
|
|
# Value: yes or no (y / n)
|
|
|
#
|
|
|
DEBUG=no
|
|
|
-
|
|
|
- #
|
|
|
+
|
|
|
+ #
|
|
|
# Syslog style log messages
|
|
|
#
|
|
|
if ! defined LOGDATEFORMAT
|
|
@@ -22,7 +22,7 @@ init () {
|
|
|
then
|
|
|
LOG_FILE=$0.log
|
|
|
fi
|
|
|
-
|
|
|
+
|
|
|
#
|
|
|
# Enable / disable logging to a file
|
|
|
# Value: yes or no (y / n)
|
|
@@ -39,7 +39,7 @@ init () {
|
|
|
then
|
|
|
SYSLOG_TAG=$0
|
|
|
fi
|
|
|
-
|
|
|
+
|
|
|
#
|
|
|
# Use colours in output.
|
|
|
#
|
|
@@ -52,15 +52,15 @@ init () {
|
|
|
LIGHT_BLUE="$CYAN"
|
|
|
BOLD="tput bold"
|
|
|
DEFAULT="tput sgr0"
|
|
|
-
|
|
|
+
|
|
|
RED_BG="tput setab 1"
|
|
|
GREEN_BG="tput setab 2"
|
|
|
YELLOW_BG="tput setab 3"
|
|
|
BLUE_BG="tput setab 4"
|
|
|
MAGENTA_BG="tput setab 5"
|
|
|
CYAN_BG="tput setab 6"
|
|
|
-
|
|
|
- #
|
|
|
+
|
|
|
+ #
|
|
|
# Bug fix for Bash, parsing exclamation mark.
|
|
|
#
|
|
|
set +o histexpand
|
|
@@ -141,6 +141,13 @@ function file_exists {
|
|
|
return 1
|
|
|
}
|
|
|
|
|
|
+function command_exists {
|
|
|
+ if command -v "$1" > /dev/null 2>&1; then
|
|
|
+ return 0;
|
|
|
+ fi
|
|
|
+ return 1
|
|
|
+}
|
|
|
+
|
|
|
#
|
|
|
# returns lowercase string
|
|
|
#
|
|
@@ -167,8 +174,8 @@ function trim {
|
|
|
# Override this function if required.
|
|
|
#
|
|
|
show_usage () {
|
|
|
-
|
|
|
- MESSAGE="$1"
|
|
|
+
|
|
|
+ MESSAGE="$1"
|
|
|
echo "$MESSAGE"
|
|
|
exit 1
|
|
|
}
|
|
@@ -190,7 +197,7 @@ option_enabled () {
|
|
|
}
|
|
|
|
|
|
#
|
|
|
-# The log funcion just puts a string into a file, prepended with a date & time in
|
|
|
+# The log funcion just puts a string into a file, prepended with a date & time in
|
|
|
# syslog format.
|
|
|
#
|
|
|
|
|
@@ -206,13 +213,13 @@ log2syslog () {
|
|
|
#
|
|
|
# This function writes messages to a log file and/or syslog
|
|
|
# The only argument is a message that has to be logged.
|
|
|
-#
|
|
|
+#
|
|
|
|
|
|
log () {
|
|
|
-
|
|
|
- if option_enabled LOG_ENABLED || option_enabled SYSLOG_ENABLED
|
|
|
+
|
|
|
+ if option_enabled LOG_ENABLED || option_enabled SYSLOG_ENABLED
|
|
|
then
|
|
|
- LOG_MESSAGE="$1"
|
|
|
+ LOG_MESSAGE="$1"
|
|
|
DATE=`date +"$LOGDATEFORMAT"`
|
|
|
|
|
|
if has_value LOG_MESSAGE
|
|
@@ -230,8 +237,8 @@ log () {
|
|
|
if option_enabled SYSLOG_ENABLED
|
|
|
then
|
|
|
#
|
|
|
- # Syslog already prepends a date/time stamp so only the message
|
|
|
- # is logged.
|
|
|
+ # Syslog already prepends a date/time stamp so only the message
|
|
|
+ # is logged.
|
|
|
#
|
|
|
log2syslog "$LOG_MESSAGE"
|
|
|
fi
|
|
@@ -241,7 +248,7 @@ log () {
|
|
|
|
|
|
#
|
|
|
# This function basically replaces the 'echo' function in bash scripts.
|
|
|
-# The added functionality over echo is logging and using colors.
|
|
|
+# The added functionality over echo is logging and using colors.
|
|
|
#
|
|
|
# The first argument is the string / message that must be displayed.
|
|
|
# The second argument is the text color.
|
|
@@ -259,7 +266,7 @@ msg () {
|
|
|
if has_value "MESSAGE"
|
|
|
then
|
|
|
$COLOR
|
|
|
- echo "$MESSAGE"
|
|
|
+ echo "$MESSAGE"
|
|
|
$DEFAULT
|
|
|
log "$MESSAGE"
|
|
|
else
|
|
@@ -269,7 +276,7 @@ msg () {
|
|
|
}
|
|
|
|
|
|
#
|
|
|
-# This function echos a message
|
|
|
+# This function echos a message
|
|
|
# and displays the status at the end of the line.
|
|
|
#
|
|
|
# It can be used to create status messages other
|
|
@@ -291,8 +298,8 @@ msg_status () {
|
|
|
#
|
|
|
|
|
|
#
|
|
|
-# The following functions are shorthand for
|
|
|
-# msg_status "a message" OK
|
|
|
+# The following functions are shorthand for
|
|
|
+# msg_status "a message" OK
|
|
|
# msg_status "another message" FAIL
|
|
|
|
|
|
|
|
@@ -439,7 +446,7 @@ display_status () {
|
|
|
|
|
|
STATUS="$1"
|
|
|
|
|
|
- case $STATUS in
|
|
|
+ case $STATUS in
|
|
|
|
|
|
EMERGENCY )
|
|
|
STATUS="EMERGENCY"
|
|
@@ -454,30 +461,30 @@ display_status () {
|
|
|
COLOR="$RED"
|
|
|
;;
|
|
|
ERROR )
|
|
|
- STATUS=" ERROR "
|
|
|
+ STATUS=" ERROR "
|
|
|
COLOR="$RED"
|
|
|
;;
|
|
|
|
|
|
WARNING )
|
|
|
- STATUS=" WARNING "
|
|
|
+ STATUS=" WARNING "
|
|
|
COLOR="$YELLOW"
|
|
|
;;
|
|
|
|
|
|
NOTICE )
|
|
|
- STATUS=" NOTICE "
|
|
|
+ STATUS=" NOTICE "
|
|
|
COLOR="$BLUE"
|
|
|
;;
|
|
|
INFO )
|
|
|
- STATUS=" INFO "
|
|
|
+ STATUS=" INFO "
|
|
|
COLOR="$LIGHT_BLUE"
|
|
|
;;
|
|
|
DEBUG )
|
|
|
STATUS=" DEBUG "
|
|
|
COLOR="$DEFAULT"
|
|
|
- ;;
|
|
|
+ ;;
|
|
|
|
|
|
- OK )
|
|
|
- STATUS=" OK "
|
|
|
+ OK )
|
|
|
+ STATUS=" OK "
|
|
|
COLOR="$GREEN"
|
|
|
;;
|
|
|
NOT_OK)
|
|
@@ -485,18 +492,18 @@ display_status () {
|
|
|
COLOR="$RED"
|
|
|
;;
|
|
|
|
|
|
- PASSED )
|
|
|
- STATUS=" PASSED "
|
|
|
+ PASSED )
|
|
|
+ STATUS=" PASSED "
|
|
|
COLOR="$GREEN"
|
|
|
;;
|
|
|
|
|
|
- SUCCESS )
|
|
|
- STATUS=" SUCCESS "
|
|
|
+ SUCCESS )
|
|
|
+ STATUS=" SUCCESS "
|
|
|
COLOR="$GREEN"
|
|
|
;;
|
|
|
-
|
|
|
+
|
|
|
FAILURE | FAILED )
|
|
|
- STATUS=" FAILED "
|
|
|
+ STATUS=" FAILED "
|
|
|
COLOR="$RED"
|
|
|
;;
|
|
|
|
|
@@ -510,7 +517,7 @@ display_status () {
|
|
|
|
|
|
|
|
|
#
|
|
|
-# Exit with error status
|
|
|
+# Exit with error status
|
|
|
#
|
|
|
bail () {
|
|
|
|
|
@@ -536,7 +543,7 @@ cmd () {
|
|
|
ERROR="$?"
|
|
|
|
|
|
MSG="Command: ${COMMAND:0:29}..."
|
|
|
-
|
|
|
+
|
|
|
tput cuu1
|
|
|
|
|
|
if [ "$ERROR" == "0" ]
|
|
@@ -564,7 +571,7 @@ now () {
|
|
|
}
|
|
|
|
|
|
elapsed () {
|
|
|
-
|
|
|
+
|
|
|
START="$1"
|
|
|
STOP="$2"
|
|
|
|
|
@@ -642,7 +649,7 @@ function str_replace_in_file () {
|
|
|
local DEST="$2"
|
|
|
local FILE="$3"
|
|
|
|
|
|
- has_value FILE
|
|
|
+ has_value FILE
|
|
|
die_if_false $? "Empty argument 'file'"
|
|
|
file_exists "$FILE"
|
|
|
die_if_false $? "File does not exist"
|