Minor enhancement in os detection log

This commit is contained in:
deajan 2016-03-20 16:52:49 +01:00
parent c2675e125d
commit f931227cd2
3 changed files with 58 additions and 41 deletions

View File

@ -8,7 +8,7 @@ PROGRAM_VERSION=2.0-pre
PROGRAM_BUILD=2016031801
IS_STABLE=no
## FUNC_BUILD=2016032001
## FUNC_BUILD=2016032002
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
@ -418,7 +418,7 @@ function GetLocalOS {
;;
*)
if [ "$IGNORE_OS_TYPE" == "yes" ]; then #DOC: Undocumented option
Logger "Running on unknown local OS." "WARN"
Logger "Running on unknown local OS [$local_os_var]." "WARN"
return
fi
Logger "Running on >> $local_os_var << not supported. Please report to the author." "ERROR"
@ -482,7 +482,7 @@ function GetRemoteOS {
;;
*)
if [ "$IGNORE_OS_VER" == "yes" ]; then #DOC: Undocumented option
Logger "Running on unknown remote OS." "WARN"
Logger "Running on unknown remote OS [$remote_os_var]." "WARN"
return
fi
Logger "Running on remote OS failed. Please report to the author if the OS is not supported." "CRITICAL"

View File

@ -1,4 +1,4 @@
## FUNC_BUILD=2016031001
## FUNC_BUILD=2016032002
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
@ -7,6 +7,21 @@ if ! type "$BASH" > /dev/null; then
exit 127
fi
#### obackup & osync specific code BEGIN ####
## Log a state message every $KEEP_LOGGING seconds. Should not be equal to soft or hard execution time so your log will not be unnecessary big.
KEEP_LOGGING=1801
## Correct output of sort command (language agnostic sorting)
export LC_ALL=C
# Standard alert mail body
MAIL_ALERT_MSG="Execution of $PROGRAM instance $INSTANCE_ID on $(date) has warnings/errors."
#### obackup & osync specific code END ####
#### MINIMAL-FUNCTION-SET BEGIN ####
# Environment variables
_DRYRUN=0
_SILENT=0
@ -31,8 +46,6 @@ else
_VERBOSE=1
fi
#### MINIMAL-FUNCTION-SET BEGIN ####
SCRIPT_PID=$$
LOCAL_USER=$(whoami)
@ -54,14 +67,6 @@ else
RUN_DIR=.
fi
## Log a state message every $KEEP_LOGGING seconds. Should not be equal to soft or hard execution time so your log will not be unnecessary big.
KEEP_LOGGING=1801
## Correct output of sort command (language agnostic sorting)
export LC_ALL=C
# Standard alert mail body
MAIL_ALERT_MSG="Execution of $PROGRAM instance $INSTANCE_ID on $(date) has warnings/errors."
# Default alert attachment filename
ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.last.log"
@ -190,6 +195,7 @@ function SendAlert {
fi
if type mutt > /dev/null 2>&1 ; then
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mutt) -x -s \"$subject\" $DESTINATION_MAILS $attachment_command"
Logger "Mail cmd: $cmd" "DEBUG"
eval $cmd
if [ $? != 0 ]; then
Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN"
@ -208,10 +214,12 @@ function SendAlert {
attachment_command=""
fi
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) $attachment_command -s \"$subject\" $DESTINATION_MAILS"
Logger "Mail cmd: $cmd" "DEBUG"
eval $cmd
if [ $? != 0 ]; then
Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) -s \"$subject\" $DESTINATION_MAILS"
Logger "Mail cmd: $cmd" "DEBUG"
eval $cmd
if [ $? != 0 ]; then
Logger "Cannot send alert email via $(type -p mail) without attachments !!!" "WARN"
@ -227,6 +235,7 @@ function SendAlert {
if type sendmail > /dev/null 2>&1 ; then
cmd="echo -e \"Subject:$subject\r\n$MAIL_ALERT_MSG\" | $(type -p sendmail) $DESTINATION_MAILS"
Logger "Mail cmd: $cmd" "DEBUG"
eval $cmd
if [ $? != 0 ]; then
Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN"
@ -260,8 +269,6 @@ function SendAlert {
fi
}
#### MINIMAL-FUNCTION-SET END ####
function TrapError {
local job="$0"
local line="$1"
@ -271,6 +278,28 @@ function TrapError {
fi
}
function LoadConfigFile {
local config_file="${1}"
__CheckArguments 1 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
if [ ! -f "$config_file" ]; then
Logger "Cannot load configuration file [$config_file]. Cannot start." "CRITICAL"
exit 1
elif [[ "$1" != *".conf" ]]; then
Logger "Wrong configuration file supplied [$config_file]. Cannot start." "CRITICAL"
exit 1
else
grep '^[^ ]*=[^;&]*' "$config_file" > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" # WITHOUT COMMENTS
# Shellcheck source=./sync.conf
source "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID"
fi
CONFIG_FILE="$config_file"
}
#### MINIMAL-FUNCTION-SET END ####
function Spinner {
if [ $_SILENT -eq 1 ]; then
return 0
@ -351,26 +380,6 @@ function CleanUp {
fi
}
function LoadConfigFile {
local config_file="${1}"
__CheckArguments 1 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
if [ ! -f "$config_file" ]; then
Logger "Cannot load configuration file [$config_file]. Cannot start." "CRITICAL"
exit 1
elif [[ "$1" != *".conf" ]]; then
Logger "Wrong configuration file supplied [$config_file]. Cannot start." "CRITICAL"
exit 1
else
grep '^[^ ]*=[^;&]*' "$config_file" > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" # WITHOUT COMMENTS
# Shellcheck source=./sync.conf
source "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID"
fi
CONFIG_FILE="$config_file"
}
function GetLocalOS {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
@ -391,13 +400,17 @@ function GetLocalOS {
*"BSD"*)
LOCAL_OS="BSD"
;;
*"MINGW32"*)
*"MINGW32"*|*"CYGWIN"*)
LOCAL_OS="msys"
;;
*"Darwin"*)
LOCAL_OS="MacOSX"
;;
*)
if [ "$IGNORE_OS_TYPE" == "yes" ]; then #DOC: Undocumented option
Logger "Running on unknown local OS [$local_os_var]." "WARN"
return
fi
Logger "Running on >> $local_os_var << not supported. Please report to the author." "ERROR"
exit 1
;;
@ -447,7 +460,7 @@ function GetRemoteOS {
*"BSD"*)
REMOTE_OS="BSD"
;;
*"MINGW32"*)
*"MINGW32"*|*"CYGWIN"*)
REMOTE_OS="msys"
;;
*"Darwin"*)
@ -458,6 +471,10 @@ function GetRemoteOS {
exit 1
;;
*)
if [ "$IGNORE_OS_VER" == "yes" ]; then #DOC: Undocumented option
Logger "Running on unknown remote OS [$remote_os_var]." "WARN"
return
fi
Logger "Running on remote OS failed. Please report to the author if the OS is not supported." "CRITICAL"
Logger "Remote OS said:\n$remote_os_var" "CRITICAL"
exit 1

View File

@ -8,7 +8,7 @@ PROGRAM_VERSION=2.0-pre
PROGRAM_BUILD=2016031801
IS_STABLE=no
## FUNC_BUILD=2016032001
## FUNC_BUILD=2016032002
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
@ -404,7 +404,7 @@ function GetLocalOS {
;;
*)
if [ "$IGNORE_OS_TYPE" == "yes" ]; then #DOC: Undocumented option
Logger "Running on unknown local OS." "WARN"
Logger "Running on unknown local OS [$local_os_var]." "WARN"
return
fi
Logger "Running on >> $local_os_var << not supported. Please report to the author." "ERROR"
@ -467,7 +467,7 @@ function GetRemoteOS {
;;
*)
if [ "$IGNORE_OS_VER" == "yes" ]; then #DOC: Undocumented option
Logger "Running on unknown remote OS." "WARN"
Logger "Running on unknown remote OS [$remote_os_var]." "WARN"
return
fi
Logger "Running on remote OS failed. Please report to the author if the OS is not supported." "CRITICAL"