Added option to ignore unknown OS

This commit is contained in:
deajan 2016-03-19 10:48:46 +01:00
parent d11bd61473
commit 8428662d61
3 changed files with 137 additions and 98 deletions

View File

@ -11,7 +11,7 @@ PROGRAM_VERSION=1.1-dev
PROGRAM_BUILD=2016031002 PROGRAM_BUILD=2016031002
IS_STABLE=no IS_STABLE=no
## FUNC_BUILD=2016031101 ## FUNC_BUILD=2016031901
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## 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 ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
@ -20,6 +20,21 @@ if ! type "$BASH" > /dev/null; then
exit 127 exit 127
fi 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 # Environment variables
_DRYRUN=0 _DRYRUN=0
_SILENT=0 _SILENT=0
@ -44,8 +59,6 @@ else
_VERBOSE=1 _VERBOSE=1
fi fi
#### MINIMAL-FUNCTION-SET BEGIN ####
SCRIPT_PID=$$ SCRIPT_PID=$$
LOCAL_USER=$(whoami) LOCAL_USER=$(whoami)
@ -67,14 +80,6 @@ else
RUN_DIR=. RUN_DIR=.
fi 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 # Default alert attachment filename
ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.last.log" ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.last.log"
@ -277,8 +282,6 @@ function SendAlert {
fi fi
} }
#### MINIMAL-FUNCTION-SET END ####
function TrapError { function TrapError {
local job="$0" local job="$0"
local line="$1" local line="$1"
@ -288,6 +291,28 @@ function TrapError {
fi 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 { function Spinner {
if [ $_SILENT -eq 1 ]; then if [ $_SILENT -eq 1 ]; then
return 0 return 0
@ -368,26 +393,6 @@ function CleanUp {
fi 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 { function GetLocalOS {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG __CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
@ -415,6 +420,10 @@ function GetLocalOS {
LOCAL_OS="MacOSX" LOCAL_OS="MacOSX"
;; ;;
*) *)
if [ "$IGNORE_OS_TYPE" == "yes" ]; then #DOC: Undocumented option
Logger "Running on unknown local OS." "WARN"
return
fi
Logger "Running on >> $local_os_var << not supported. Please report to the author." "ERROR" Logger "Running on >> $local_os_var << not supported. Please report to the author." "ERROR"
exit 1 exit 1
;; ;;
@ -475,6 +484,10 @@ function GetRemoteOS {
exit 1 exit 1
;; ;;
*) *)
if [ "$IGNORE_OS_VER" == "yes" ]; then #DOC: Undocumented option
Logger "Running on unknown remote OS." "WARN"
return
fi
Logger "Running on remote OS failed. Please report to the author if the OS is not supported." "CRITICAL" 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" Logger "Remote OS said:\n$remote_os_var" "CRITICAL"
exit 1 exit 1

View File

@ -1,4 +1,4 @@
## FUNC_BUILD=2016031101 ## FUNC_BUILD=2016031901
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## 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 ## 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 exit 127
fi 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 # Environment variables
_DRYRUN=0 _DRYRUN=0
_SILENT=0 _SILENT=0
@ -31,8 +46,6 @@ else
_VERBOSE=1 _VERBOSE=1
fi fi
#### MINIMAL-FUNCTION-SET BEGIN ####
SCRIPT_PID=$$ SCRIPT_PID=$$
LOCAL_USER=$(whoami) LOCAL_USER=$(whoami)
@ -54,14 +67,6 @@ else
RUN_DIR=. RUN_DIR=.
fi 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 # Default alert attachment filename
ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.last.log" ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.last.log"
@ -264,8 +269,6 @@ function SendAlert {
fi fi
} }
#### MINIMAL-FUNCTION-SET END ####
function TrapError { function TrapError {
local job="$0" local job="$0"
local line="$1" local line="$1"
@ -275,6 +278,28 @@ function TrapError {
fi 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 { function Spinner {
if [ $_SILENT -eq 1 ]; then if [ $_SILENT -eq 1 ]; then
return 0 return 0
@ -355,26 +380,6 @@ function CleanUp {
fi 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 { function GetLocalOS {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG __CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
@ -402,6 +407,10 @@ function GetLocalOS {
LOCAL_OS="MacOSX" LOCAL_OS="MacOSX"
;; ;;
*) *)
if [ "$IGNORE_OS_TYPE" == "yes" ]; then #DOC: Undocumented option
Logger "Running on unknown local OS." "WARN"
return
fi
Logger "Running on >> $local_os_var << not supported. Please report to the author." "ERROR" Logger "Running on >> $local_os_var << not supported. Please report to the author." "ERROR"
exit 1 exit 1
;; ;;
@ -462,6 +471,10 @@ function GetRemoteOS {
exit 1 exit 1
;; ;;
*) *)
if [ "$IGNORE_OS_VER" == "yes" ]; then #DOC: Undocumented option
Logger "Running on unknown remote OS." "WARN"
return
fi
Logger "Running on remote OS failed. Please report to the author if the OS is not supported." "CRITICAL" 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" Logger "Remote OS said:\n$remote_os_var" "CRITICAL"
exit 1 exit 1

View File

@ -11,7 +11,7 @@ PROGRAM_VERSION=1.1-dev
PROGRAM_BUILD=2016031002 PROGRAM_BUILD=2016031002
IS_STABLE=no IS_STABLE=no
## FUNC_BUILD=2016031101 ## FUNC_BUILD=2016031901
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## 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 ## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
@ -20,6 +20,21 @@ if ! type "$BASH" > /dev/null; then
exit 127 exit 127
fi 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 # Environment variables
_DRYRUN=0 _DRYRUN=0
_SILENT=0 _SILENT=0
@ -40,8 +55,6 @@ else
_VERBOSE=1 _VERBOSE=1
fi fi
#### MINIMAL-FUNCTION-SET BEGIN ####
SCRIPT_PID=$$ SCRIPT_PID=$$
LOCAL_USER=$(whoami) LOCAL_USER=$(whoami)
@ -63,14 +76,6 @@ else
RUN_DIR=. RUN_DIR=.
fi 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 # Default alert attachment filename
ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.last.log" ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.last.log"
@ -266,8 +271,6 @@ function SendAlert {
fi fi
} }
#### MINIMAL-FUNCTION-SET END ####
function TrapError { function TrapError {
local job="$0" local job="$0"
local line="$1" local line="$1"
@ -277,6 +280,27 @@ function TrapError {
fi fi
} }
function LoadConfigFile {
local config_file="${1}"
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 { function Spinner {
if [ $_SILENT -eq 1 ]; then if [ $_SILENT -eq 1 ]; then
return 0 return 0
@ -356,25 +380,6 @@ function CleanUp {
fi fi
} }
function LoadConfigFile {
local config_file="${1}"
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 { function GetLocalOS {
local local_os_var= local local_os_var=
@ -401,6 +406,10 @@ function GetLocalOS {
LOCAL_OS="MacOSX" LOCAL_OS="MacOSX"
;; ;;
*) *)
if [ "$IGNORE_OS_TYPE" == "yes" ]; then #DOC: Undocumented option
Logger "Running on unknown local OS." "WARN"
return
fi
Logger "Running on >> $local_os_var << not supported. Please report to the author." "ERROR" Logger "Running on >> $local_os_var << not supported. Please report to the author." "ERROR"
exit 1 exit 1
;; ;;
@ -460,6 +469,10 @@ function GetRemoteOS {
exit 1 exit 1
;; ;;
*) *)
if [ "$IGNORE_OS_VER" == "yes" ]; then #DOC: Undocumented option
Logger "Running on unknown remote OS." "WARN"
return
fi
Logger "Running on remote OS failed. Please report to the author if the OS is not supported." "CRITICAL" 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" Logger "Remote OS said:\n$remote_os_var" "CRITICAL"
exit 1 exit 1