2
0
mirror of https://github.com/deajan/osync synced 2024-11-03 15:40:14 +00:00

Merge branch 'forced_bash'

This commit is contained in:
deajan 2016-12-09 19:27:12 +01:00
commit 785c12b364
5 changed files with 657 additions and 601 deletions

27
dev/bootstrap.sh Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env bash
## dev pre-processor bootstrap rev 2016120701
## Yeah !!! A really tech sounding name... In fact it's just include emulation in bash
outputFileName="$0"
source "merge.sh"
__PREPROCESSOR_PROGRAM=osync
__PREPROCESSOR_Constants
cp "n_$__PREPROCESSOR_PROGRAM.sh" "$outputFileName.tmp.sh"
if [ $? != 0 ]; then
QuickLogger "Cannot copy original file [n_$__PREPROCESSOR_PROGRAM.sh] to [$outputFileName.tmp.sh]." "stderr"
exit 1
fi
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "$outputFileName.tmp.sh"
done
chmod +x "$0.tmp.sh"
if [ $? != 0 ]; then
QuickLogger "Cannot make [$outputFileName] executable.." "stderr"
exit 1
fi
"$outputFileName.tmp.sh" "$@"

View File

@ -1,142 +1,156 @@
#!/usr/bin/env bash
## MERGE 2016112001
## MERGE 2016120802
## Merges ofunctions.sh and n_program.sh into program.sh
## Adds installer
PROGRAM=osync
VERSION=$(grep "PROGRAM_VERSION=" n_$PROGRAM.sh)
VERSION=${VERSION#*=}
function __PREPROCESSOR_Merge {
PROGRAM=osync
VERSION=$(grep "PROGRAM_VERSION=" n_$PROGRAM.sh)
VERSION=${VERSION#*=}
PARANOIA_DEBUG_LINE="__WITH_PARANOIA_DEBUG"
PARANOIA_DEBUG_BEGIN="#__BEGIN_WITH_PARANOIA_DEBUG"
PARANOIA_DEBUG_END="#__END_WITH_PARANOIA_DEBUG"
MINIMUM_FUNCTION_BEGIN="#### MINIMAL-FUNCTION-SET BEGIN ####"
MINIMUM_FUNCTION_END="#### MINIMAL-FUNCTION-SET END ####"
__PREPROCESSOR_Constants
source "ofunctions.sh"
if [ $? != 0 ]; then
echo "Please run $0 in dev directory with ofunctions.sh"
exit 1
fi
function Unexpand {
unexpand n_$PROGRAM.sh > tmp_$PROGRAM.sh
}
function MergeAll {
sed "/source \"\.\/ofunctions.sh\"/r ofunctions.sh" tmp_$PROGRAM.sh | grep -v 'source "./ofunctions.sh"' > debug_$PROGRAM.sh
source "ofunctions.sh"
if [ $? != 0 ]; then
QuickLogger "Cannot sed ofunctions" "stdout"
echo "Please run $0 in dev directory with ofunctions.sh"
exit 1
fi
chmod +x debug_$PROGRAM.sh
__PREPROCESSOR_Unexpand "n_$PROGRAM.sh" "debug_$PROGRAM.sh"
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "debug_$PROGRAM.sh"
done
__PREPROCESSOR_CleanDebug
__PREPROCESSOR_CopyCommons
rm -f tmp_$PROGRAM.sh
if [ $? != 0 ]; then
QuickLogger "Cannot chmod $PROGRAM.sh" "stdout"
QuickLogger "Cannot remove tmp_$PROGRAM.sh" "stderr"
exit 1
fi
}
function MergeMinimum {
sed -n "/$MINIMUM_FUNCTION_BEGIN/,/$MINIMUM_FUNCTION_END/p" ofunctions.sh > tmp_minimal.sh
if [ $? != 0 ]; then
QuickLogger "Cannot sed minimum functions." "stdout"
exit 1
fi
sed "/source \"\.\/ofunctions.sh\"/r tmp_minimal.sh" tmp_$PROGRAM.sh | grep -v 'source "./ofunctions.sh"' | grep -v "$PARANOIA_DEBUG_LINE" > debug_$PROGRAM.sh
if [ $? != 0 ]; then
QuickLogger "Cannot remove PARANOIA_DEBUG code from tmp_minimum.." "stdout"
exit 1
fi
rm -f tmp_minimal.sh
if [ $? != 0 ]; then
QuickLogger "Cannot remove tmp_minimal.sh" "stdout"
exit 1
fi
chmod +x debug_$PROGRAM.sh
if [ $? != 0 ]; then
QuickLogger "Cannot chmod debug_$PROGRAM.sh" "stdout"
exit 1
fi
function __PREPROCESSOR_Constants {
PARANOIA_DEBUG_LINE="#__WITH_PARANOIA_DEBUG"
PARANOIA_DEBUG_BEGIN="#__BEGIN_WITH_PARANOIA_DEBUG"
PARANOIA_DEBUG_END="#__END_WITH_PARANOIA_DEBUG"
__PREPROCESSOR_SUBSETS=(
'#### OFUNCTIONS FULL SUBSET ####'
'#### OFUNCTIONS MINIMAL SUBSET ####'
'#### DEBUG SUBSET ####'
'#### TrapError SUBSET ####'
'#### RemoteLogger SUBSET ####'
'#### IsInteger SUBSET ####'
'#### HumanToNumeric SUBSET ####'
'#### ArrayContains SUBSET ####'
)
}
function __PREPROCESSOR_Unexpand {
local source="${1}"
local destination="${2}"
function CleanDebug {
unexpand "$source" > "$destination"
if [ $? != 0 ]; then
QuickLogger "Cannot unexpand [$source] to [$destination]." "stderr"
exit 1
fi
}
# sed explanation
#/pattern1/{ # if pattern1 is found
# p # print it
# :a # loop
# N # and accumulate lines
# /pattern2/!ba # until pattern2 is found
# s/.*\n// # delete the part before pattern2
#}
#p
# sed -n '/'$PARANOIA_DEBUG_BEGIN'/{p; :a; N; /'$PARANOIA_DEBUG_END'/!ba; s/.*\n//}; p' debug_$PROGRAM.sh | grep -v "$PARANOIA_DEBUG_LINE" > ../$PROGRAM.sh
function __PREPROCESSOR_MergeSubset {
local subsetBegin="${1}"
local subsetEnd="${2}"
local subsetFile="${3}"
local mergedFile="${4}"
# Way simpler version of the above, compatible with BSD
sed -n "/$subsetBegin/,/$subsetEnd/p" "$subsetFile" > "$subsetFile.$subsetBegin"
if [ $? != 0 ]; then
QuickLogger "Cannot sed subset [$subsetBegin -- $subsetEnd] in [$subsetFile]." "stderr"
exit 1
fi
sed "/include $subsetBegin/r $subsetFile.$subsetBegin" "$mergedFile" | grep -v -E "$subsetBegin\$|$subsetEnd\$" > "$mergedFile.tmp"
if [ $? != 0 ]; then
QuickLogger "Cannot add subset [$subsetBegin] to [$mergedFile]." "stderr"
exit 1
fi
rm -f "$subsetFile.$subsetBegin"
if [ $? != 0 ]; then
QuickLogger "Cannot remove temporary subset [$subsetFile.$subsetBeign]." "stderr"
exit 1
fi
rm -f "$mergedFile"
if [ $? != 0 ]; then
QuickLogger "Cannot remove merged original file [$mergedFile]." "stderr"
exit 1
fi
mv "$mergedFile.tmp" "$mergedFile"
if [ $? != 0 ]; then
QuickLogger "Cannot move merged tmp file to original [$mergedFile]." "stderr"
exit 1
fi
}
function __PREPROCESSOR_CleanDebug {
sed '/'$PARANOIA_DEBUG_BEGIN'/,/'$PARANOIA_DEBUG_END'/d' debug_$PROGRAM.sh | grep -v "$PARANOIA_DEBUG_LINE" > ../$PROGRAM.sh
if [ $? != 0 ]; then
QuickLogger "Cannot remove PARANOIA_DEBUG code from standard build." "stdout"
QuickLogger "Cannot remove PARANOIA_DEBUG code from standard build." "stderr"
exit 1
fi
chmod +x ../$PROGRAM.sh
chmod +x "debug_$PROGRAM.sh"
if [ $? != 0 ]; then
QuickLogger "Cannot chmod $PROGRAM.sh" "stdout"
QuickLogger "Cannot chmod debug_$PROGRAM.sh" "stderr"
exit 1
fi
chmod +x "../$PROGRAM.sh"
if [ $? != 0 ]; then
QuickLogger "Cannot chmod $PROGRAM.sh" "stderr"
exit 1
fi
}
function CopyCommons {
function __PREPROCESSOR_CopyCommons {
sed "s/\[prgname\]/$PROGRAM/g" common_install.sh > ../tmp_install.sh
if [ $? != 0 ]; then
QuickLogger "Cannot assemble install." "stdout"
QuickLogger "Cannot assemble install." "stderr"
exit 1
fi
sed "s/\[version\]/$VERSION/g" ../tmp_install.sh > ../install.sh
if [ $? != 0 ]; then
QuickLogger "Cannot change install version." "stdout"
QuickLogger "Cannot change install version." "stderr"
exit 1
fi
if [ -f "common_batch.sh" ]; then
sed "s/\[prgname\]/$PROGRAM/g" common_batch.sh > ../$PROGRAM-batch.sh
if [ $? != 0 ]; then
QuickLogger "Cannot assemble batch runner." "stdout"
QuickLogger "Cannot assemble batch runner." "stderr"
exit 1
fi
chmod +x ../$PROGRAM-batch.sh
if [ $? != 0 ]; then
QuickLogger "Cannot chmod $PROGRAM-batch.sh" "stdout"
QuickLogger "Cannot chmod $PROGRAM-batch.sh" "stderr"
exit 1
fi
fi
chmod +x ../install.sh
if [ $? != 0 ]; then
QuickLogger "Cannot chmod install.sh" "stdout"
QuickLogger "Cannot chmod install.sh" "stderr"
exit 1
fi
rm -f ../tmp_install.sh
if [ $? != 0 ]; then
QuickLogger "Cannot chmod $PROGRAM.sh" "stdout"
QuickLogger "Cannot chmod $PROGRAM.sh" "stderr"
exit 1
fi
}
Unexpand
if [ "$PROGRAM" == "osync" ] || [ "$PROGRAM" == "obackup" ]; then
MergeAll
else
MergeMinimum
fi
CleanDebug
CopyCommons
rm -f tmp_$PROGRAM.sh
if [ $? != 0 ]; then
QuickLogger "Cannot remove tmp_$PROGRAM.sh" "stdout"
exit 1
# If sourced don't do anything
if [ "$(basename $0)" == "merge.sh" ]; then
__PREPROCESSOR_Merge
fi

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,9 @@
#### MINIMAL-FUNCTION-SET BEGIN ####
#### OFUNCTIONS FULL SUBSET ####
#### OFUNCTIONS MINI SUBSET ####
_OFUNCTIONS_VERSION=2.0
_OFUNCTIONS_BUILD=2016120401
_OFUNCTIONS_VERSION=2.1
_OFUNCTIONS_BUILD=2016120901
_OFUNCTIONS_BOOTSTRAP=true
## BEGIN Generic bash functions written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
## To use in a program, define the following variables:
@ -41,6 +43,7 @@ fi
ERROR_ALERT=false
WARN_ALERT=false
#### DEBUG SUBSET ####
## allow function call checks #__WITH_PARANOIA_DEBUG
if [ "$_PARANOIA_DEBUG" == "yes" ];then #__WITH_PARANOIA_DEBUG
_DEBUG=yes #__WITH_PARANOIA_DEBUG
@ -58,6 +61,7 @@ fi
if [ "$SLEEP_TIME" == "" ]; then # Leave the possibity to set SLEEP_TIME as environment variable when runinng with bash -x in order to avoid spamming console
SLEEP_TIME=.05
fi
#### DEBUG SUBSET END ####
SCRIPT_PID=$$
@ -73,8 +77,10 @@ if [ -w /var/log ]; then
LOG_FILE="/var/log/$PROGRAM.log"
elif ([ "$HOME" != "" ] && [ -w "$HOME" ]); then
LOG_FILE="$HOME/$PROGRAM.log"
else
elif [ -w . ]; then
LOG_FILE="./$PROGRAM.log"
else
LOG_FILE="/tmp/$PROGRAM.log"
fi
## Default directory where to store temporary run files
@ -96,20 +102,24 @@ ALERT_LOG_FILE="$RUN_DIR/$PROGRAM.$SCRIPT_PID.last.log"
function Dummy {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
sleep $SLEEP_TIME
}
#### Logger SUBSET ####
#### RemoteLogger SUBSET ####
# Sub function of Logger
function _Logger {
local logValue="${1}" # Log to file
local stdValue="${2}" # Log to screeen
local toStderr="${3:-false}" # Log to stderr instead of stdout
echo -e "$logValue" >> "$LOG_FILE"
# Current log file
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID"
if [ "$logValue" != "" ]; then
echo -e "$logValue" >> "$LOG_FILE"
# Current log file
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID"
fi
if [ "$stdValue" != "" ] && [ "$_LOGGER_SILENT" != true ]; then
if [ $toStderr == true ]; then
@ -122,6 +132,58 @@ function _Logger {
fi
}
# Remote logger similar to below Logger, without log to file and alert flags
function RemoteLogger {
local value="${1}" # Sentence to log (in double quotes)
local level="${2}" # Log level
if [ "$_LOGGER_PREFIX" == "time" ]; then
prefix="TIME: $SECONDS - "
elif [ "$_LOGGER_PREFIX" == "date" ]; then
prefix="$(date) - "
else
prefix=""
fi
if [ "$level" == "CRITICAL" ]; then
_Logger "" "$prefix\e[41m$value\e[0m" true
return
elif [ "$level" == "ERROR" ]; then
_Logger "" "$prefix\e[91m$value\e[0m" true
return
elif [ "$level" == "WARN" ]; then
_Logger "" "$prefix\e[33m$value\e[0m" true
return
elif [ "$level" == "NOTICE" ]; then
if [ $_LOGGER_ERR_ONLY != true ]; then
_Logger "" "$prefix$value"
fi
return
elif [ "$level" == "VERBOSE" ]; then
if [ $_LOGGER_VERBOSE == true ]; then
_Logger "" "$prefix$value"
fi
return
elif [ "$level" == "ALWAYS" ]; then
_Logger "" "$prefix$value"
return
elif [ "$level" == "DEBUG" ]; then
if [ "$_DEBUG" == "yes" ]; then
_Logger "" "$prefix$value"
return
fi
elif [ "$level" == "PARANOIA_DEBUG" ]; then #__WITH_PARANOIA_DEBUG
if [ "$_PARANOIA_DEBUG" == "yes" ]; then #__WITH_PARANOIA_DEBUG
_Logger "" "$prefix\e[35m$value\e[0m" #__WITH_PARANOIA_DEBUG
return #__WITH_PARANOIA_DEBUG
fi #__WITH_PARANOIA_DEBUG
else
_Logger "\e[41mLogger function called without proper loglevel [$level].\e[0m"
_Logger "Value was: $prefix$value"
fi
}
#### RemoteLogger SUBSET END ####
# General log function with log levels:
# Environment variables
@ -193,13 +255,14 @@ function Logger {
_Logger "Value was: $prefix$value"
fi
}
#### Logger SUBSET END ####
# QuickLogger subfunction, can be called directly
function _QuickLogger {
local value="${1}"
local destination="${2}" # Destination: stdout, log, both
__CheckArguments 2 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 2 $# "$@" #__WITH_PARANOIA_DEBUG
if ([ "$destination" == "log" ] || [ "$destination" == "both" ]); then
echo -e "$(date) - $value" >> "$LOG_FILE"
@ -212,7 +275,7 @@ function _QuickLogger {
function QuickLogger {
local value="${1}"
__CheckArguments 1 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 1 $# "$@" #__WITH_PARANOIA_DEBUG
if [ $_LOGGER_SILENT == true ]; then
_QuickLogger "$value" "log"
@ -226,7 +289,7 @@ function KillChilds {
local pid="${1}" # Parent pid to kill childs
local self="${2:-false}" # Should parent be killed too ?
# Warning: pgrep does not exist in cygwin, have this checked in CheckEnvironment
if children="$(pgrep -P "$pid")"; then
for child in $children; do
Logger "Launching KillChilds \"$child\" true" "DEBUG" #__WITH_PARANOIA_DEBUG
@ -261,7 +324,7 @@ function KillAllChilds {
local pids="${1}" # List of parent pids to kill separated by semi-colon
local self="${2:-false}" # Should parent be killed too ?
__CheckArguments 1 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 1 $# "$@" #__WITH_PARANOIA_DEBUG
local errorcount=0
@ -279,7 +342,7 @@ function KillAllChilds {
function SendAlert {
local runAlert="${1:-false}" # Specifies if current message is sent while running or at the end of a run
__CheckArguments 0-1 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0-1 $# "$@" #__WITH_PARANOIA_DEBUG
local attachment
local attachmentFile
@ -362,7 +425,7 @@ function SendEmail {
local smtpUser="${9}"
local smtpPassword="${10}"
__CheckArguments 3-10 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 3-10 $# "$@" #__WITH_PARANOIA_DEBUG
local mail_no_attachment=
local attachment_command=
@ -499,6 +562,7 @@ function SendEmail {
Logger "Cannot send mail (neither mutt, mail, sendmail, sendemail, mailsend (windows) or pfSense mail.php could be used)." "ERROR" # Is not marked critical because execution must continue
}
#### TrapError SUBSET ####
function TrapError {
local job="$0"
local line="$1"
@ -508,11 +572,12 @@ function TrapError {
echo -e "\e[45m/!\ ERROR in ${job}: Near line ${line}, exit code ${code}\e[0m"
fi
}
#### TrapError SUBSET END ####
function LoadConfigFile {
local configFile="${1}"
__CheckArguments 1 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 1 $# "$@" #__WITH_PARANOIA_DEBUG
if [ ! -f "$configFile" ]; then
@ -573,7 +638,7 @@ function joinString {
# Fills a global variable called WAIT_FOR_TASK_COMPLETION_$callerName that contains list of failed pids in format pid1:result1;pid2:result2
# Also sets a global variable called HARD_MAX_EXEC_TIME_REACHED_$callerName to true if hardMaxTime is reached
# Standard wait $! emulation would be WaitForTaskCompletion $! 0 0 1 0 true false true false "${FUNCNAME[0]}"
# Standard wait $! emulation would be WaitForTaskCompletion $! 0 0 1 0 true false true false
function WaitForTaskCompletion {
local pids="${1}" # pids to wait for, separated by semi-colon
@ -584,10 +649,10 @@ function WaitForTaskCompletion {
local counting="${6:-true}" # Count time since function has been launched (true), or since script has been launched (false)
local spinner="${7:-true}" # Show spinner (true), don't show anything (false)
local noErrorLog="${8:-false}" # Log errors when reaching soft / hard max time (false), don't log errors on those triggers (true)
local callerName="${9}" # Name of the function who called this function for debugging purposes, generally ${FUNCNAME[0]}
local callerName="${FUNCNAME[1]}"
Logger "${FUNCNAME[0]} called by [$callerName]." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG
__CheckArguments 9 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 8 $# "$@" #__WITH_PARANOIA_DEBUG
local log_ttime=0 # local time instance for comparaison
@ -730,9 +795,9 @@ function ParallelExec {
local counting="${8:-true}" # Count time since function has been launched (true), or since script has been launched (false)
local spinner="${9:-false}" # Show spinner (true), don't show spinner (false)
local noErrorLog="${10:-false}" # Log errors when reaching soft / hard max time (false), don't log errors on those triggers (true)
local callerName="${11:-false}" # Name of the function who called this function for debugging purposes, generally ${FUNCNAME[0]}
__CheckArguments 2-11 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
local callerName="${FUNCNAME[1]}"
__CheckArguments 2-10 $# "$@" #__WITH_PARANOIA_DEBUG
local log_ttime=0 # local time instance for comparaison
@ -871,7 +936,7 @@ function ParallelExec {
}
function CleanUp {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
if [ "$_DEBUG" != "yes" ]; then
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID"
@ -939,6 +1004,7 @@ function IsNumeric {
fi
}
#### IsInteger SUBSET ####
function IsInteger {
local value="${1}"
@ -948,7 +1014,9 @@ function IsInteger {
echo 0
fi
}
#### IsInteger SUBSET END ####
#### HumanToNumeric SUBSET ####
# Converts human readable sizes into integer kilobyte sizes
# Usage numericSize="$(HumanToNumeric $humanSize)"
function HumanToNumeric {
@ -979,9 +1047,10 @@ function HumanToNumeric {
echo $value
}
#### HumanToNumeric SUBSET END ####
## from https://gist.github.com/cdown/1163649
function urlEncode {
function UrlEncode {
local length="${#1}"
local LANG=C
@ -998,29 +1067,35 @@ function urlEncode {
done
}
function urlDecode {
function UrlDecode {
local urlEncoded="${1//+/ }"
printf '%b' "${urlEncoded//%/\\x}"
}
#### ArrayContains SUBSET ####
## Modified version of http://stackoverflow.com/a/8574392
## Usage: arrayContains "needle" "${haystack[@]}"
arrayContains () {
## Usage: [ $(ArrayContains "needle" "${haystack[@]}") -eq 1 ]
function ArrayContains () {
local needle="${1}"
local haystack="${2}"
local e
if [ "$2" == "" ]; then
echo 0 && return 0
if [ "$needle" != "" ] && [ "$haystack" != "" ]; then
for e in "${@:2}"; do
if [ "$e" == "$needle" ]; then
echo 1
return
fi
done
fi
for e in "${@:2}"; do
[[ "$e" == "$1" ]] && echo 1 && return 1
done
echo 0 && return 0
echo 0
return
}
#### ArrayContains SUBSET END ####
function GetLocalOS {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
local localOsVar
@ -1053,9 +1128,12 @@ function GetLocalOS {
*"BSD"*)
LOCAL_OS="BSD"
;;
*"MINGW32"*|*"CYGWIN"*)
*"MINGW32"*|*"MSYS"*)
LOCAL_OS="msys"
;;
*"CYGWIN"*)
LOCAL_OS="Cygwin"
;;
*"Microsoft"*)
LOCAL_OS="WinNT10"
;;
@ -1077,10 +1155,10 @@ function GetLocalOS {
Logger "Local OS: [$localOsVar]." "DEBUG"
}
#### MINIMAL-FUNCTION-SET END ####
#### OFUNCTIONS MINI SUBSET END ####
function GetRemoteOS {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
if [ "$REMOTE_OPERATION" != "yes" ]; then
return 0
@ -1129,9 +1207,12 @@ ENDSSH
*"BSD"*)
REMOTE_OS="BSD"
;;
*"MINGW32"*|*"CYGWIN"*)
*"MINGW32"*|*"MSYS"*)
REMOTE_OS="msys"
;;
*"CYGWIN"*)
REMOTE_OS="Cygwin"
;;
*"Microsoft"*)
REMOTE_OS="WinNT10"
;;
@ -1163,7 +1244,7 @@ ENDSSH
function RunLocalCommand {
local command="${1}" # Command to run
local hardMaxTime="${2}" # Max time to wait for command to compleet
__CheckArguments 2 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 2 $# "$@" #__WITH_PARANOIA_DEBUG
if [ $_DRYRUN == true ]; then
Logger "Dryrun: Local command [$command] not run." "NOTICE"
@ -1195,7 +1276,7 @@ function RunLocalCommand {
function RunRemoteCommand {
local command="${1}" # Command to run
local hardMaxTime="${2}" # Max time to wait for command to compleet
__CheckArguments 2 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 2 $# "$@" #__WITH_PARANOIA_DEBUG
CheckConnectivity3rdPartyHosts
CheckConnectivityRemoteHost
@ -1228,7 +1309,7 @@ function RunRemoteCommand {
}
function RunBeforeHook {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
local pids
@ -1247,7 +1328,7 @@ function RunBeforeHook {
}
function RunAfterHook {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
local pids
@ -1266,7 +1347,7 @@ function RunAfterHook {
}
function CheckConnectivityRemoteHost {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
local retval
@ -1285,7 +1366,7 @@ function CheckConnectivityRemoteHost {
}
function CheckConnectivity3rdPartyHosts {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
local remote3rdPartySuccess
local retval
@ -1323,16 +1404,17 @@ function __CheckArguments {
if [ "$_DEBUG" == "yes" ]; then
local numberOfArguments="${1}" # Number of arguments the tested function should have, can be a number of a range, eg 0-2 for zero to two arguments
local numberOfGivenArguments="${2}" # Number of arguments that have been passed
local functionName="${3}" # Function name that called __CheckArguments
local minArgs
local maxArgs
# All arguments of the function to check are passed as array in ${4} (the function call waits for $@)
# All arguments of the function to check are passed as array in ${3} (the function call waits for $@)
# If any of the arguments contains spaces, bash things there are two aguments
# In order to avoid this, we need to iterate over ${4} and count
# In order to avoid this, we need to iterate over ${3} and count
local iterate=4
callerName="${FUNCNAME[1]}"
local iterate=3
local fetchArguments=true
local argList=""
local countedArguments
@ -1342,12 +1424,12 @@ function __CheckArguments {
if [ "$argument" = "" ]; then
fetchArguments=false
else
argList="$argList[Argument $(($iterate-3)): $argument] "
argList="$argList[Argument $(($iterate-2)): $argument] "
iterate=$(($iterate+1))
fi
done
countedArguments=$((iterate-4))
countedArguments=$((iterate-3))
if [ $(IsInteger "$numberOfArguments") -eq 1 ]; then
minArgs=$numberOfArguments
@ -1356,13 +1438,15 @@ function __CheckArguments {
IFS='-' read minArgs maxArgs <<< "$numberOfArguments"
fi
Logger "Entering function [$functionName]." "PARANOIA_DEBUG"
Logger "Entering function [$callerName]." "PARANOIA_DEBUG"
if ! ([ $countedArguments -ge $minArgs ] && [ $countedArguments -le $maxArgs ]); then
Logger "Function $functionName may have inconsistent number of arguments. Expected min: $minArgs, max: $maxArgs, count: $countedArguments, bash seen: $numberOfGivenArguments. see log file." "ERROR"
Logger "Arguments passed: $argList" "ERROR"
Logger "$callerName arguments: $argList" "ERROR"
else
Logger "Arguments passed: $argList" "PARANOIA_DEBUG"
if [ ! -z "$argList" ]; then
Logger "$callerName arguments: $argList" "PARANOIA_DEBUG"
fi
fi
fi
}
@ -1372,7 +1456,7 @@ function __CheckArguments {
function RsyncPatternsAdd {
local patternType="${1}" # exclude or include
local pattern="${2}"
__CheckArguments 2 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 2 $# "$@" #__WITH_PARANOIA_DEBUG
local rest
@ -1402,7 +1486,7 @@ function RsyncPatternsAdd {
function RsyncPatternsFromAdd {
local patternType="${1}"
local patternFrom="${2}"
__CheckArguments 2 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 2 $# "$@" #__WITH_PARANOIA_DEBUG
## Check if the exclude list has a full path, and if not, add the config file path if there is one
if [ "$(basename $patternFrom)" == "$patternFrom" ]; then
@ -1415,7 +1499,7 @@ function RsyncPatternsFromAdd {
}
function RsyncPatterns {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
if [ "$RSYNC_PATTERN_FIRST" == "exclude" ]; then
if [ "$RSYNC_EXCLUDE_PATTERN" != "" ]; then
@ -1450,7 +1534,7 @@ function RsyncPatterns {
}
function PreInit {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
local compressionString
@ -1495,7 +1579,7 @@ function PreInit {
}
function PostInit {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
# Define remote commands
if [ -f "$SSH_RSA_PRIVATE_KEY" ]; then
@ -1515,13 +1599,13 @@ function PostInit {
}
function InitLocalOSDependingSettings {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
## If running under Msys, some commands do not run the same way
## Using mingw version of find instead of windows one
## Getting running processes is quite different
## Ping command is not the same
if [ "$LOCAL_OS" == "msys" ]; then
if [ "$LOCAL_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
FIND_CMD=$(dirname $BASH)/find
PING_CMD='$SYSTEMROOT\system32\ping -n 2'
else
@ -1529,7 +1613,7 @@ function InitLocalOSDependingSettings {
PING_CMD="ping -c 2 -i .2"
fi
if [ "$LOCAL_OS" == "BusyBox" ] || [ "$LOCAL_OS" == "Android" ] || [ "$LOCAL_OS" == "msys" ]; then
if [ "$LOCAL_OS" == "BusyBox" ] || [ "$LOCAL_OS" == "Android" ] || [ "$LOCAL_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
PROCESS_STATE_CMD="echo none"
DF_CMD="df"
else
@ -1551,9 +1635,9 @@ function InitLocalOSDependingSettings {
}
function InitRemoteOSDependingSettings {
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
if [ "$REMOTE_OS" == "msys" ]; then
if [ "$REMOTE_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
REMOTE_FIND_CMD=$(dirname $BASH)/find
else
REMOTE_FIND_CMD=find
@ -1590,7 +1674,7 @@ function InitRemoteOSDependingSettings {
if [ "$PRESERVE_EXECUTABILITY" != "no" ]; then
RSYNC_ATTR_ARGS=$RSYNC_ATTR_ARGS" --executability"
fi
if [ "$LOCAL_OS" != "MacOSX" ] && [ "$REMOTE_OS" != "MacOSX" ] && [ "$LOCAL_OS" != "msys" ] && [ "$REMOTE_OS" != "MacOSX" ]; then
if [ "$LOCAL_OS" != "MacOSX" ] && [ "$REMOTE_OS" != "MacOSX" ] && [ "$LOCAL_OS" != "msys" ] && [ "$LOCAL_OS" != "Cygwin" ] && [ "$REMOTE_OS" != "MacOSX" ]; then
if [ "$PRESERVE_ACL" == "yes" ]; then
RSYNC_ATTR_ARGS=$RSYNC_ATTR_ARGS" -A"
fi
@ -1691,4 +1775,4 @@ function ParentPid {
fi
}
## END Generic functions
#### OFUNCTIONS FULL SUBSET END ####

View File

@ -7,7 +7,7 @@
## On CYGWIN / MSYS, ACL and extended attributes aren't supported
# osync test suite 2016120802
# osync test suite 2016120901
# 4 tests:
# quicklocal
@ -221,7 +221,7 @@ function oneTimeSetUp () {
osyncDaemonParameters[$__local]="$CONF_DIR/$LOCAL_CONF --on-changes"
if [ "$LOCAL_OS" != "msys" ]; then
if [ "$LOCAL_OS" != "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
osyncParameters[$__quickRemote]="--initiator=$INITIATOR_DIR --target=ssh://localhost:$SSH_PORT/$TARGET_DIR --rsakey=${HOME}/.ssh/id_rsa_local --instance-id=quickremote"
osyncParameters[$__confRemote]="$CONF_DIR/$REMOTE_CONF"
@ -536,6 +536,11 @@ function test_handle_symlinks () {
return 0
fi
if [ "$LOCAL_OS" == "msys" ]; then
echo "Skipping symlink tests because msys handles them strangely or not at all."
return 0
fi
# Check with and without copySymlinks
copySymlinks="no"
@ -735,7 +740,7 @@ function test_softdeletion_cleanup () {
touch "$file.new"
if [ "$TRAVIS_RUN" == true ] || [ "$LOCAL_OS" == "BSD" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ]; then
if [ "$TRAVIS_RUN" == true ] || [ "$LOCAL_OS" == "BSD" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
echo "Skipping changing ctime on file because travis / bsd / macos / Win10 / msys / cygwin does not support debugfs"
else
CreateOldFile "$file.old"
@ -750,7 +755,7 @@ function test_softdeletion_cleanup () {
[ -f "$file.new" ]
assertEquals "New softdeleted / backed up file [$file.new] exists." "0" $?
if [ "$TRAVIS_RUN" == true ] || [ "$LOCAL_OS" == "BSD" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ]; then
if [ "$TRAVIS_RUN" == true ] || [ "$LOCAL_OS" == "BSD" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
[ ! -f "$file.old" ]
assertEquals "Old softdeleted / backed up file [$file.old] is deleted permanently." "0" $?
else
@ -1268,8 +1273,8 @@ function test_UpgradeConfRun () {
}
function test_DaemonMode () {
if [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ]; then
echo "Skipping daemon mode test as Win10 does not have inotifywait support."
if [ "$LOCAL_OS" == "WinNT10" ] || [ "$LOCAL_OS" == "msys" ] || [ "$LOCAL_OS" == "Cygwin" ]; then
echo "Skipping daemon mode test as [$LOCAL_OS] does not have inotifywait support."
return 0
fi