Unexpanded all source files

pull/93/head
deajan 8 years ago
parent 7bc93df5e6
commit 23cac5cad6

@ -9,8 +9,8 @@ PROGRAM_BUILD=2016120401
## If an instance fails, run it again if time permits ## If an instance fails, run it again if time permits
if ! type "$BASH" > /dev/null; then if ! type "$BASH" > /dev/null; then
echo "Please run this script only with bash shell. Tested on bash >= 3.2" echo "Please run this script only with bash shell. Tested on bash >= 3.2"
exit 127 exit 127
fi fi
## If maximum execution time is not reached, failed instances will be rerun. Max exec time is in seconds. Example is set to 10 hours. ## If maximum execution time is not reached, failed instances will be rerun. Max exec time is in seconds. Example is set to 10 hours.

@ -4,7 +4,7 @@ PROGRAM=[prgname]
PROGRAM_VERSION=[version] PROGRAM_VERSION=[version]
PROGRAM_BINARY=$PROGRAM".sh" PROGRAM_BINARY=$PROGRAM".sh"
PROGRAM_BATCH=$PROGRAM"-batch.sh" PROGRAM_BATCH=$PROGRAM"-batch.sh"
SCRIPT_BUILD=2016112401 SCRIPT_BUILD=2016120801
## osync / obackup / pmocr / zsnap install script ## osync / obackup / pmocr / zsnap install script
## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8 & 10 ## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8 & 10
@ -35,23 +35,23 @@ PMOCR_SERVICE_FILE_SYSTEMD_SYSTEM="pmocr-srv@.service"
## Default log file ## Default log file
if [ -w $FAKEROOT/var/log ]; then if [ -w $FAKEROOT/var/log ]; then
LOG_FILE="$FAKEROOT/var/log/$PROGRAM-install.log" LOG_FILE="$FAKEROOT/var/log/$PROGRAM-install.log"
elif ([ "$HOME" != "" ] && [ -w "$HOME" ]); then elif ([ "$HOME" != "" ] && [ -w "$HOME" ]); then
LOG_FILE="$HOME/$PROGRAM-install.log" LOG_FILE="$HOME/$PROGRAM-install.log"
else else
LOG_FILE="./$PROGRAM-install.log" LOG_FILE="./$PROGRAM-install.log"
fi fi
# Generic quick logging function # Generic quick logging function
function _QuickLogger { function _QuickLogger {
local value="${1}" local value="${1}"
local destination="${2}" # Destination: stdout, log, both local destination="${2}" # Destination: stdout, log, both
if ([ "$destination" == "log" ] || [ "$destination" == "both" ]); then if ([ "$destination" == "log" ] || [ "$destination" == "both" ]); then
echo -e "$(date) - $value" >> "$LOG_FILE" echo -e "$(date) - $value" >> "$LOG_FILE"
elif ([ "$destination" == "stdout" ] || [ "$destination" == "both" ]); then elif ([ "$destination" == "stdout" ] || [ "$destination" == "both" ]); then
echo -e "$value" echo -e "$value"
fi fi
} }
function QuickLogger { function QuickLogger {
@ -64,17 +64,17 @@ function QuickLogger {
fi fi
} }
function urlencode() { function UrlEncode() {
# urlencode <string> # urlencode <string>
local LANG=C local LANG=C
local length="${#1}" local length="${#1}"
for (( i = 0; i < length; i++ )); do for (( i = 0; i < length; i++ )); do
local c="${1:i:1}" local c="${1:i:1}"
case $c in case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;; [a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c" ;; *) printf '%%%02X' "'$c" ;;
esac esac
done done
} }
@ -83,23 +83,23 @@ function SetOSSettings {
USER=root USER=root
# There's no good way to tell if currently running in BusyBox shell. Using sluggish way. # There's no good way to tell if currently running in BusyBox shell. Using sluggish way.
if ls --help 2>&1 | grep -i "BusyBox" > /dev/null; then if ls --help 2>&1 | grep -i "BusyBox" > /dev/null; then
localOsVar="BusyBox" localOsVar="BusyBox"
else else
# Detecting the special ubuntu userland in Windows 10 bash # Detecting the special ubuntu userland in Windows 10 bash
if grep -i Microsoft /proc/sys/kernel/osrelease > /dev/null 2>&1; then if grep -i Microsoft /proc/sys/kernel/osrelease > /dev/null 2>&1; then
localOsVar="Microsoft" localOsVar="Microsoft"
else else
localOsVar="$(uname -spio 2>&1)" localOsVar="$(uname -spio 2>&1)"
if [ $? != 0 ]; then if [ $? != 0 ]; then
localOsVar="$(uname -v 2>&1)" localOsVar="$(uname -v 2>&1)"
if [ $? != 0 ]; then if [ $? != 0 ]; then
localOsVar="$(uname)" localOsVar="$(uname)"
fi fi
fi fi
fi fi
fi fi
case $localOsVar in case $localOsVar in
*"BSD"*) *"BSD"*)
@ -118,11 +118,11 @@ function SetOSSettings {
esac esac
if ([ "$USER" != "" ] && [ "$(whoami)" != "$USER" ] && [ "$FAKEROOT" == "" ]); then if ([ "$USER" != "" ] && [ "$(whoami)" != "$USER" ] && [ "$FAKEROOT" == "" ]); then
QuickLogger "Must be run as $USER." QuickLogger "Must be run as $USER."
exit 1 exit 1
fi fi
OS=$(urlencode "$localOsVar") OS=$(UrlEncode "$localOsVar")
} }
function GetInit { function GetInit {
@ -262,22 +262,22 @@ function CopyServiceFiles {
} }
function Statistics { function Statistics {
if type wget > /dev/null; then if type wget > /dev/null; then
wget -qO- "$STATS_LINK" > /dev/null 2>&1 wget -qO- "$STATS_LINK" > /dev/null 2>&1
if [ $? == 0 ]; then if [ $? == 0 ]; then
return 0 return 0
fi fi
fi fi
if type curl > /dev/null; then if type curl > /dev/null; then
curl "$STATS_LINK" -o /dev/null > /dev/null 2>&1 curl "$STATS_LINK" -o /dev/null > /dev/null 2>&1
if [ $? == 0 ]; then if [ $? == 0 ]; then
return 0 return 0
fi fi
fi fi
QuickLogger "Neiter wget nor curl could be used for. Cannot run statistics. Use the provided link please." QuickLogger "Neiter wget nor curl could be used for. Cannot run statistics. Use the provided link please."
return 1 return 1
} }
function Usage { function Usage {

@ -68,12 +68,12 @@ function __PREPROCESSOR_MergeSubset {
local subsetFile="${3}" local subsetFile="${3}"
local mergedFile="${4}" local mergedFile="${4}"
sed -n "/$subsetBegin/,/$subsetEnd/p" "$subsetFile" > "$subsetFile.$subsetBegin" sed -n "/$subsetBegin/,/$subsetEnd/p" "$subsetFile" > "$subsetFile.$subsetBegin"
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot sed subset [$subsetBegin -- $subsetEnd] in [$subsetFile]." "stderr" QuickLogger "Cannot sed subset [$subsetBegin -- $subsetEnd] in [$subsetFile]." "stderr"
exit 1 exit 1
fi fi
sed "/include $subsetBegin/r $subsetFile.$subsetBegin" "$mergedFile" | grep -v -E "$subsetBegin\$|$subsetEnd\$" > "$mergedFile.tmp" sed "/include $subsetBegin/r $subsetFile.$subsetBegin" "$mergedFile" | grep -v -E "$subsetBegin\$|$subsetEnd\$" > "$mergedFile.tmp"
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot add subset [$subsetBegin] to [$mergedFile]." "stderr" QuickLogger "Cannot add subset [$subsetBegin] to [$mergedFile]." "stderr"
exit 1 exit 1
@ -84,13 +84,13 @@ function __PREPROCESSOR_MergeSubset {
exit 1 exit 1
fi fi
rm -f "$mergedFile" rm -f "$mergedFile"
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot remove merged original file [$mergedFile]." "stderr" QuickLogger "Cannot remove merged original file [$mergedFile]." "stderr"
exit 1 exit 1
fi fi
mv "$mergedFile.tmp" "$mergedFile" mv "$mergedFile.tmp" "$mergedFile"
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot move merged tmp file to original [$mergedFile]." "stderr" QuickLogger "Cannot move merged tmp file to original [$mergedFile]." "stderr"
exit 1 exit 1

@ -124,60 +124,60 @@ function TrapQuit {
} }
function CheckEnvironment { function CheckEnvironment {
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG __CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
if [ "$REMOTE_OPERATION" == "yes" ]; then if [ "$REMOTE_OPERATION" == "yes" ]; then
if ! type ssh > /dev/null 2>&1 ; then if ! type ssh > /dev/null 2>&1 ; then
Logger "ssh not present. Cannot start sync." "CRITICAL" Logger "ssh not present. Cannot start sync." "CRITICAL"
exit 1 exit 1
fi fi
if [ "$SSH_PASSWORD_FILE" != "" ] && ! type sshpass > /dev/null 2>&1 ; then if [ "$SSH_PASSWORD_FILE" != "" ] && ! type sshpass > /dev/null 2>&1 ; then
Logger "sshpass not present. Cannot use password authentication." "CRITICAL" Logger "sshpass not present. Cannot use password authentication." "CRITICAL"
exit 1 exit 1
fi fi
fi fi
if ! type rsync > /dev/null 2>&1 ; then if ! type rsync > /dev/null 2>&1 ; then
Logger "rsync not present. Sync cannot start." "CRITICAL" Logger "rsync not present. Sync cannot start." "CRITICAL"
exit 1 exit 1
fi fi
if ! type pgrep > /dev/null 2>&1 ; then if ! type pgrep > /dev/null 2>&1 ; then
Logger "pgrep not present. Sync cannot start." "CRITICAL" Logger "pgrep not present. Sync cannot start." "CRITICAL"
exit 1 exit 1
fi fi
} }
# Only gets checked in config file mode where all values should be present # Only gets checked in config file mode where all values should be present
function CheckCurrentConfig { function CheckCurrentConfig {
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG __CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
# Check all variables that should contain "yes" or "no" # Check all variables that should contain "yes" or "no"
declare -a yes_no_vars=(CREATE_DIRS SUDO_EXEC SSH_COMPRESSION SSH_IGNORE_KNOWN_HOSTS REMOTE_HOST_PING PRESERVE_PERMISSIONS PRESERVE_OWNER PRESERVE_GROUP PRESERVE_EXECUTABILITY PRESERVE_ACL PRESERVE_XATTR COPY_SYMLINKS KEEP_DIRLINKS PRESERVE_HARDLINKS CHECKSUM RSYNC_COMPRESS CONFLICT_BACKUP CONFLICT_BACKUP_MULTIPLE SOFT_DELETE RESUME_SYNC FORCE_STRANGER_LOCK_RESUME PARTIAL DELTA_COPIES STOP_ON_CMD_ERROR RUN_AFTER_CMD_ON_ERROR) declare -a yes_no_vars=(CREATE_DIRS SUDO_EXEC SSH_COMPRESSION SSH_IGNORE_KNOWN_HOSTS REMOTE_HOST_PING PRESERVE_PERMISSIONS PRESERVE_OWNER PRESERVE_GROUP PRESERVE_EXECUTABILITY PRESERVE_ACL PRESERVE_XATTR COPY_SYMLINKS KEEP_DIRLINKS PRESERVE_HARDLINKS CHECKSUM RSYNC_COMPRESS CONFLICT_BACKUP CONFLICT_BACKUP_MULTIPLE SOFT_DELETE RESUME_SYNC FORCE_STRANGER_LOCK_RESUME PARTIAL DELTA_COPIES STOP_ON_CMD_ERROR RUN_AFTER_CMD_ON_ERROR)
for i in "${yes_no_vars[@]}"; do for i in "${yes_no_vars[@]}"; do
test="if [ \"\$$i\" != \"yes\" ] && [ \"\$$i\" != \"no\" ]; then Logger \"Bogus $i value [\$$i] defined in config file. Correct your config file or update it using the update script if using and old version.\" \"CRITICAL\"; exit 1; fi" test="if [ \"\$$i\" != \"yes\" ] && [ \"\$$i\" != \"no\" ]; then Logger \"Bogus $i value [\$$i] defined in config file. Correct your config file or update it using the update script if using and old version.\" \"CRITICAL\"; exit 1; fi"
eval "$test" eval "$test"
done done
# Check all variables that should contain a numerical value >= 0 # Check all variables that should contain a numerical value >= 0
declare -a num_vars=(MINIMUM_SPACE BANDWIDTH SOFT_MAX_EXEC_TIME HARD_MAX_EXEC_TIME KEEP_LOGGING MIN_WAIT MAX_WAIT CONFLICT_BACKUP_DAYS SOFT_DELETE_DAYS RESUME_TRY MAX_EXEC_TIME_PER_CMD_BEFORE MAX_EXEC_TIME_PER_CMD_AFTER) declare -a num_vars=(MINIMUM_SPACE BANDWIDTH SOFT_MAX_EXEC_TIME HARD_MAX_EXEC_TIME KEEP_LOGGING MIN_WAIT MAX_WAIT CONFLICT_BACKUP_DAYS SOFT_DELETE_DAYS RESUME_TRY MAX_EXEC_TIME_PER_CMD_BEFORE MAX_EXEC_TIME_PER_CMD_AFTER)
for i in "${num_vars[@]}"; do for i in "${num_vars[@]}"; do
test="if [ $(IsNumericExpand \"\$$i\") -eq 0 ]; then Logger \"Bogus $i value [\$$i] defined in config file. Correct your config file or update it using the update script if using and old version.\" \"CRITICAL\"; exit 1; fi" test="if [ $(IsNumericExpand \"\$$i\") -eq 0 ]; then Logger \"Bogus $i value [\$$i] defined in config file. Correct your config file or update it using the update script if using and old version.\" \"CRITICAL\"; exit 1; fi"
eval "$test" eval "$test"
done done
} }
# Gets checked in quicksync and config file mode # Gets checked in quicksync and config file mode
function CheckCurrentConfigAll { function CheckCurrentConfigAll {
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG __CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
local tmp local tmp
if [ "$INSTANCE_ID" == "" ]; then if [ "$INSTANCE_ID" == "" ]; then
Logger "No INSTANCE_ID defined in config file." "CRITICAL" Logger "No INSTANCE_ID defined in config file." "CRITICAL"
exit 1 exit 1
fi fi
if [ "$INITIATOR_SYNC_DIR" == "" ]; then if [ "$INITIATOR_SYNC_DIR" == "" ]; then
Logger "No INITIATOR_SYNC_DIR set in config file." "CRITICAL" Logger "No INITIATOR_SYNC_DIR set in config file." "CRITICAL"
@ -564,22 +564,22 @@ function HandleLocks {
_HandleLocksRemote "${TARGET[$__replicaDir]}${TARGET[$__stateDir]}" "${TARGET[$__lockFile]}" "${TARGET[$__type]}" $overwrite & _HandleLocksRemote "${TARGET[$__replicaDir]}${TARGET[$__stateDir]}" "${TARGET[$__lockFile]}" "${TARGET[$__type]}" $overwrite &
pids="$pids;$!" pids="$pids;$!"
fi fi
INITIATOR_LOCK_FILE_EXISTS=true INITIATOR_LOCK_FILE_EXISTS=true
TARGET_LOCK_FILE_EXISTS=true TARGET_LOCK_FILE_EXISTS=true
WaitForTaskCompletion $pids 720 1800 $SLEEP_TIME $KEEP_LOGGING true true false WaitForTaskCompletion $pids 720 1800 $SLEEP_TIME $KEEP_LOGGING true true false
retval=$? retval=$?
if [ $retval -ne 0 ]; then if [ $retval -ne 0 ]; then
IFS=';' read -r -a pidArray <<< "$(eval echo \"\$WAIT_FOR_TASK_COMPLETION_${FUNCNAME[0]}\")" IFS=';' read -r -a pidArray <<< "$(eval echo \"\$WAIT_FOR_TASK_COMPLETION_${FUNCNAME[0]}\")"
for pid in "${pidArray[@]}"; do for pid in "${pidArray[@]}"; do
pid=${pid%:*} pid=${pid%:*}
if [ "$pid" == "$initiatorPid" ]; then if [ "$pid" == "$initiatorPid" ]; then
INITIATOR_LOCK_FILE_EXISTS=false INITIATOR_LOCK_FILE_EXISTS=false
elif [ "$pid" == "$targetPid" ]; then elif [ "$pid" == "$targetPid" ]; then
TARGET_LOCK_FILE_EXISTS=false TARGET_LOCK_FILE_EXISTS=false
fi fi
done done
Logger "Cancelling task." "CRITICAL" $retval Logger "Cancelling task." "CRITICAL" $retval
exit 1 exit 1
fi fi
fi fi
@ -817,9 +817,9 @@ function _getFileCtimeMtimeRemote {
$SSH_CMD env PROGRAM="'$PROGRAM'" env SCRIPT_PID="'$SCRIPT_PID'" env replicaPath="'$replicaPath'" env replicaType="'$replicaType'" env REMOTE_STAT_CTIME_MTIME_CMD="'$REMOTE_STAT_CTIME_MTIME_CMD'" 'bash -s' << 'ENDSSH' > "$RUN_DIR/$PROGRAM.ctime_mtime.$replicaType.$SCRIPT_PID" $SSH_CMD env PROGRAM="'$PROGRAM'" env SCRIPT_PID="'$SCRIPT_PID'" env replicaPath="'$replicaPath'" env replicaType="'$replicaType'" env REMOTE_STAT_CTIME_MTIME_CMD="'$REMOTE_STAT_CTIME_MTIME_CMD'" 'bash -s' << 'ENDSSH' > "$RUN_DIR/$PROGRAM.ctime_mtime.$replicaType.$SCRIPT_PID"
while read -r file; do $REMOTE_STAT_CTIME_MTIME_CMD "$replicaPath$file" | sort; done < ".$PROGRAM.ctime_mtime.$replicaType.$SCRIPT_PID" while read -r file; do $REMOTE_STAT_CTIME_MTIME_CMD "$replicaPath$file" | sort; done < ".$PROGRAM.ctime_mtime.$replicaType.$SCRIPT_PID"
if [ -f ".$PROGRAM.ctime_mtime.$replicaType.$SCRIPT_PID" ]; then if [ -f ".$PROGRAM.ctime_mtime.$replicaType.$SCRIPT_PID" ]; then
rm -f ".$PROGRAM.ctime_mtime.$replicaType.$SCRIPT_PID" rm -f ".$PROGRAM.ctime_mtime.$replicaType.$SCRIPT_PID"
fi fi
ENDSSH ENDSSH
retval=$? retval=$?
if [ $retval -ne 0 ]; then if [ $retval -ne 0 ]; then
@ -955,7 +955,7 @@ function syncAttrs {
WaitForTaskCompletion $! $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME $SLEEP_TIME $KEEP_LOGGING false true false WaitForTaskCompletion $! $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME $SLEEP_TIME $KEEP_LOGGING false true false
retval=$? retval=$?
if [ $retval !-ne 0 ] && [ $retval -ne 24 ]; then if [ $retval -ne 0 ] && [ $retval -ne 24 ]; then
Logger "Updating file attributes on $destReplica [$retval]. Stopping execution." "CRITICAL" $retval Logger "Updating file attributes on $destReplica [$retval]. Stopping execution." "CRITICAL" $retval
if [ -f "$RUN_DIR/$PROGRAM.attr-update.$destReplica.$SCRIPT_PID" ]; then if [ -f "$RUN_DIR/$PROGRAM.attr-update.$destReplica.$SCRIPT_PID" ]; then
Logger "Rsync output:\n$(cat $RUN_DIR/$PROGRAM.attr-update.$destReplica.$SCRIPT_PID)" "NOTICE" Logger "Rsync output:\n$(cat $RUN_DIR/$PROGRAM.attr-update.$destReplica.$SCRIPT_PID)" "NOTICE"
@ -1414,7 +1414,7 @@ function Sync {
echo "${SYNC_ACTION[1]}" > "${INITIATOR[$__targetLastActionFile]}" echo "${SYNC_ACTION[1]}" > "${INITIATOR[$__targetLastActionFile]}"
fi fi
exit 1 exit 1
else else
echo "${SYNC_ACTION[1]}" > "${INITIATOR[$__initiatorLastActionFile]}" echo "${SYNC_ACTION[1]}" > "${INITIATOR[$__initiatorLastActionFile]}"
echo "${SYNC_ACTION[1]}" > "${INITIATOR[$__targetLastActionFile]}" echo "${SYNC_ACTION[1]}" > "${INITIATOR[$__targetLastActionFile]}"
@ -1459,7 +1459,7 @@ function Sync {
echo "${SYNC_ACTION[2]}" > "${INITIATOR[$__targetLastActionFile]}" echo "${SYNC_ACTION[2]}" > "${INITIATOR[$__targetLastActionFile]}"
fi fi
exit 1 exit 1
else else
echo "${SYNC_ACTION[2]}" > "${INITIATOR[$__initiatorLastActionFile]}" echo "${SYNC_ACTION[2]}" > "${INITIATOR[$__initiatorLastActionFile]}"
echo "${SYNC_ACTION[2]}" > "${INITIATOR[$__targetLastActionFile]}" echo "${SYNC_ACTION[2]}" > "${INITIATOR[$__targetLastActionFile]}"
@ -1583,7 +1583,7 @@ function Sync {
echo "${SYNC_ACTION[5]}" > "${INITIATOR[$__targetLastActionFile]}" echo "${SYNC_ACTION[5]}" > "${INITIATOR[$__targetLastActionFile]}"
fi fi
exit 1 exit 1
else else
echo "${SYNC_ACTION[5]}" > "${INITIATOR[$__initiatorLastActionFile]}" echo "${SYNC_ACTION[5]}" > "${INITIATOR[$__initiatorLastActionFile]}"
echo "${SYNC_ACTION[5]}" > "${INITIATOR[$__targetLastActionFile]}" echo "${SYNC_ACTION[5]}" > "${INITIATOR[$__targetLastActionFile]}"
@ -1629,7 +1629,7 @@ function Sync {
echo "${SYNC_ACTION[6]}" > "${INITIATOR[$__targetLastActionFile]}" echo "${SYNC_ACTION[6]}" > "${INITIATOR[$__targetLastActionFile]}"
fi fi
exit 1 exit 1
else else
echo "${SYNC_ACTION[6]}" > "${INITIATOR[$__initiatorLastActionFile]}" echo "${SYNC_ACTION[6]}" > "${INITIATOR[$__initiatorLastActionFile]}"
echo "${SYNC_ACTION[6]}" > "${INITIATOR[$__targetLastActionFile]}" echo "${SYNC_ACTION[6]}" > "${INITIATOR[$__targetLastActionFile]}"
@ -1885,10 +1885,10 @@ function Init {
INITIATOR_SYNC_DIR="${INITIATOR_SYNC_DIR%/}/" INITIATOR_SYNC_DIR="${INITIATOR_SYNC_DIR%/}/"
TARGET_SYNC_DIR="${TARGET_SYNC_DIR%/}/" TARGET_SYNC_DIR="${TARGET_SYNC_DIR%/}/"
# Expand ~ if exists # Expand ~ if exists
INITIATOR_SYNC_DIR="${INITIATOR_SYNC_DIR/#\~/$HOME}" INITIATOR_SYNC_DIR="${INITIATOR_SYNC_DIR/#\~/$HOME}"
TARGET_SYNC_DIR="${TARGET_SYNC_DIR/#\~/$HOME}" TARGET_SYNC_DIR="${TARGET_SYNC_DIR/#\~/$HOME}"
SSH_RSA_PRIVATE_KEY="${SSH_RSA_PRIVATE_KEY/#\~/$HOME}" SSH_RSA_PRIVATE_KEY="${SSH_RSA_PRIVATE_KEY/#\~/$HOME}"
SSH_PASSWORD_FILE="${SSH_PASSWORD_FILE/#\~/$HOME}" SSH_PASSWORD_FILE="${SSH_PASSWORD_FILE/#\~/$HOME}"
## Replica format ## Replica format
@ -1900,9 +1900,9 @@ function Init {
local deleteDir="deleted" local deleteDir="deleted"
local partialDir="_partial" local partialDir="_partial"
local lastAction="last-action" local lastAction="last-action"
local resumeCount="resume-count" local resumeCount="resume-count"
if [ "$_DRYRUN" == true ]; then if [ "$_DRYRUN" == true ]; then
local drySuffix="-dry" local drySuffix="-dry"
else else
local drySuffix= local drySuffix=
fi fi
@ -2012,8 +2012,8 @@ function Usage {
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG __CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
if [ "$IS_STABLE" != "yes" ]; then if [ "$IS_STABLE" != "yes" ]; then
echo -e "\e[93mThis is an unstable dev build. Please use with caution.\e[0m" echo -e "\e[93mThis is an unstable dev build. Please use with caution.\e[0m"
fi fi
echo "$PROGRAM $PROGRAM_VERSION $PROGRAM_BUILD" echo "$PROGRAM $PROGRAM_VERSION $PROGRAM_BUILD"
echo "$AUTHOR" echo "$AUTHOR"

@ -39,7 +39,7 @@ _LOGGER_VERBOSE=false
_LOGGER_ERR_ONLY=false _LOGGER_ERR_ONLY=false
_LOGGER_PREFIX="date" _LOGGER_PREFIX="date"
if [ "$KEEP_LOGGING" == "" ]; then if [ "$KEEP_LOGGING" == "" ]; then
KEEP_LOGGING=1801 KEEP_LOGGING=1801
fi fi
# Initial error status, logging 'WARN', 'ERROR' or 'CRITICAL' will enable alerts flags # Initial error status, logging 'WARN', 'ERROR' or 'CRITICAL' will enable alerts flags

@ -156,7 +156,7 @@ function CreateOldFile () {
assertEquals "touch [$filePath]" "0" $? assertEquals "touch [$filePath]" "0" $?
# Get current drive # Get current drive
drive=$(df "$OSYNC_DIR" | tail -1 | awk '{print $1}') drive=$(df "$OSYNC_DIR" | tail -1 | awk '{print $1}')
# modify ctime on ext4 so osync thinks it has to delete the old files # modify ctime on ext4 so osync thinks it has to delete the old files
debugfs -w -R 'set_inode_field "'$filePath'" ctime 201001010101' $drive debugfs -w -R 'set_inode_field "'$filePath'" ctime 201001010101' $drive
@ -175,7 +175,7 @@ function PrepareLocalDirs () {
mkdir -p "$INITIATOR_DIR" mkdir -p "$INITIATOR_DIR"
if [ -d "$TARGET_DIR" ]; then if [ -d "$TARGET_DIR" ]; then
rm -rf "$TARGET_DIR" rm -rf "$TARGET_DIR"
fi fi
mkdir -p "$TARGET_DIR" mkdir -p "$TARGET_DIR"
} }
@ -283,8 +283,8 @@ function oneTimeTearDown () {
} }
function setUp () { function setUp () {
rm -rf "$INITIATOR_DIR" rm -rf "$INITIATOR_DIR"
rm -rf "$TARGET_DIR" rm -rf "$TARGET_DIR"
} }
# This test has to be done everytime in order for osync executable to be fresh # This test has to be done everytime in order for osync executable to be fresh
@ -1235,15 +1235,15 @@ function test_timedExecution () {
SLEEP_TIME=1 SOFT_MAX_EXEC_TIME=${softTimes[$x]} HARD_MAX_EXEC_TIME=${hardTimes[$x]} ./$OSYNC_EXECUTABLE $i SLEEP_TIME=1 SOFT_MAX_EXEC_TIME=${softTimes[$x]} HARD_MAX_EXEC_TIME=${hardTimes[$x]} ./$OSYNC_EXECUTABLE $i
retval=$? retval=$?
if [ "$OSYNC_MIN_VERSION" -gt 1 ]; then if [ "$OSYNC_MIN_VERSION" -gt 1 ]; then
assertEquals "Timed Execution test with timed SOFT_MAX_EXEC_TIME=${softTimes[$x]} and HARD_MAX_EXEC_TIME=${hardTimes[$x]}." $x $retval assertEquals "Timed Execution test with timed SOFT_MAX_EXEC_TIME=${softTimes[$x]} and HARD_MAX_EXEC_TIME=${hardTimes[$x]}." $x $retval
else else
# osync v1.1 had different exit codes, 240 was warning, anything else than 0 was error # osync v1.1 had different exit codes, 240 was warning, anything else than 0 was error
if [ $x -eq 2 ]; then if [ $x -eq 2 ]; then
assertEquals "Timed Execution test with timed SOFT_MAX_EXEC_TIME=${softTimes[$x]} and HARD_MAX_EXEC_TIME=${hardTimes[$x]}." 240 $retval assertEquals "Timed Execution test with timed SOFT_MAX_EXEC_TIME=${softTimes[$x]} and HARD_MAX_EXEC_TIME=${hardTimes[$x]}." 240 $retval
elif [ $x -eq 1 ]; then elif [ $x -eq 1 ]; then
assertNotEquals "Timed Execution test with timed SOFT_MAX_EXEC_TIME=${softTimes[$x]} and HARD_MAX_EXEC_TIME=${hardTimes[$x]}." 0 $retval assertNotEquals "Timed Execution test with timed SOFT_MAX_EXEC_TIME=${softTimes[$x]} and HARD_MAX_EXEC_TIME=${hardTimes[$x]}." 0 $retval
else else
assertEquals "Timed Execution test with timed SOFT_MAX_EXEC_TIME=${softTimes[$x]} and HARD_MAX_EXEC_TIME=${hardTimes[$x]}." 0 $retval assertEquals "Timed Execution test with timed SOFT_MAX_EXEC_TIME=${softTimes[$x]} and HARD_MAX_EXEC_TIME=${hardTimes[$x]}." 0 $retval
fi fi
fi fi
done done
@ -1256,20 +1256,20 @@ function test_UpgradeConfRun () {
return 0 return 0
fi fi
# Basic return code tests. Need to go deep into file presence testing # Basic return code tests. Need to go deep into file presence testing
cd "$OSYNC_DIR" cd "$OSYNC_DIR"
PrepareLocalDirs PrepareLocalDirs
# Make a security copy of the old config file # Make a security copy of the old config file
cp "$CONF_DIR/$OLD_CONF" "$CONF_DIR/$TMP_OLD_CONF" cp "$CONF_DIR/$OLD_CONF" "$CONF_DIR/$TMP_OLD_CONF"
./$OSYNC_UPGRADE "$CONF_DIR/$TMP_OLD_CONF" ./$OSYNC_UPGRADE "$CONF_DIR/$TMP_OLD_CONF"
assertEquals "Conf file upgrade" "0" $? assertEquals "Conf file upgrade" "0" $?
./$OSYNC_EXECUTABLE "$CONF_DIR/$TMP_OLD_CONF" ./$OSYNC_EXECUTABLE "$CONF_DIR/$TMP_OLD_CONF"
assertEquals "Upgraded conf file execution test" "0" $? assertEquals "Upgraded conf file execution test" "0" $?
rm -f "$CONF_DIR/$TMP_OLD_CONF" rm -f "$CONF_DIR/$TMP_OLD_CONF"
rm -f "$CONF_DIR/$TMP_OLD_CONF.save" rm -f "$CONF_DIR/$TMP_OLD_CONF.save"
} }
function test_DaemonMode () { function test_DaemonMode () {
@ -1330,7 +1330,7 @@ function test_DaemonMode () {
function test_NoRemoteAccessTest () { function test_NoRemoteAccessTest () {
RemoveSSH RemoveSSH
cd "$OSYNC_DIR" cd "$OSYNC_DIR"
PrepareLocalDirs PrepareLocalDirs
REMOTE_HOST_PING=no ./$OSYNC_EXECUTABLE ${osyncParameters[$__confLocal]} REMOTE_HOST_PING=no ./$OSYNC_EXECUTABLE ${osyncParameters[$__confLocal]}

@ -11,8 +11,8 @@ PROGRAM_BUILD=2016112101
## 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
if ! type "$BASH" > /dev/null; then if ! type "$BASH" > /dev/null; then
echo "Please run this script only with bash shell. Tested on bash >= 3.2" echo "Please run this script only with bash shell. Tested on bash >= 3.2"
exit 127 exit 127
fi fi
# Defines all keywords / value sets in osync configuration files # Defines all keywords / value sets in osync configuration files
@ -458,12 +458,12 @@ function RewriteOldConfigFiles {
exit 1 exit 1
fi fi
echo "Backing up [$config_file] as [$config_file.save]" echo "Backing up [$config_file] as [$config_file.save]"
cp -p "$config_file" "$config_file.save" cp -p "$config_file" "$config_file.save"
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "Cannot backup config file." echo "Cannot backup config file."
exit 1 exit 1
fi fi
echo "Rewriting config file $config_file" echo "Rewriting config file $config_file"
@ -480,34 +480,34 @@ function RewriteOldConfigFiles {
} }
function AddMissingConfigOptions { function AddMissingConfigOptions {
local config_file="${1}" local config_file="${1}"
local counter=0 local counter=0
while [ $counter -lt ${#KEYWORDS[@]} ]; do while [ $counter -lt ${#KEYWORDS[@]} ]; do
if ! grep "^${KEYWORDS[$counter]}=" > /dev/null "$config_file"; then if ! grep "^${KEYWORDS[$counter]}=" > /dev/null "$config_file"; then
echo "${KEYWORDS[$counter]} not found" echo "${KEYWORDS[$counter]} not found"
if [ $counter -gt 0 ]; then if [ $counter -gt 0 ]; then
sed -i'.tmp' '/^'${KEYWORDS[$((counter-1))]}'=*/a\'$'\n'${KEYWORDS[$counter]}'="'"${VALUES[$counter]}"'"\'$'\n''' "$config_file" sed -i'.tmp' '/^'${KEYWORDS[$((counter-1))]}'=*/a\'$'\n'${KEYWORDS[$counter]}'="'"${VALUES[$counter]}"'"\'$'\n''' "$config_file"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Cannot add missing ${[KEYWORDS[$counter]}." echo "Cannot add missing ${[KEYWORDS[$counter]}."
exit 1 exit 1
fi fi
else else
sed -i'.tmp' '/onfig file rev*/a\'$'\n'${KEYWORDS[$counter]}'="'"${VALUES[$counter]}"'"\'$'\n''' "$config_file" sed -i'.tmp' '/onfig file rev*/a\'$'\n'${KEYWORDS[$counter]}'="'"${VALUES[$counter]}"'"\'$'\n''' "$config_file"
fi fi
echo "Added missing ${KEYWORDS[$counter]} config option with default option [${VALUES[$counter]}]" echo "Added missing ${KEYWORDS[$counter]} config option with default option [${VALUES[$counter]}]"
fi fi
counter=$((counter+1)) counter=$((counter+1))
done done
} }
function UpdateConfigHeader { function UpdateConfigHeader {
local config_file="${1}" local config_file="${1}"
# "onfig file rev" to deal with earlier variants of the file where c was lower or uppercase # "onfig file rev" to deal with earlier variants of the file where c was lower or uppercase
#sed -i'.tmp' '/onfig file rev/c\###### '$SUBPROGRAM' config file rev '$CONFIG_FILE_VERSION' '$NEW_PROGRAM_VERSION "$config_file" #sed -i'.tmp' '/onfig file rev/c\###### '$SUBPROGRAM' config file rev '$CONFIG_FILE_VERSION' '$NEW_PROGRAM_VERSION "$config_file"
sed -i'.tmp' 's/.*onfig file rev.*/##### '$SUBPROGRAM' config file rev '$CONFIG_FILE_VERSION' '$NEW_PROGRAM_VERSION'/' "$config_file" sed -i'.tmp' 's/.*onfig file rev.*/##### '$SUBPROGRAM' config file rev '$CONFIG_FILE_VERSION' '$NEW_PROGRAM_VERSION'/' "$config_file"
rm -f "$config_file.tmp" rm -f "$config_file.tmp"
} }
_QUICKSYNC=0 _QUICKSYNC=0
@ -544,9 +544,9 @@ elif [ "$1" != "" ] && [ -f "$1" ] && [ -w "$1" ]; then
CONF_FILE="${CONF_FILE%/}" CONF_FILE="${CONF_FILE%/}"
LoadConfigFile "$CONF_FILE" LoadConfigFile "$CONF_FILE"
Init Init
RewriteOldConfigFiles "$CONF_FILE" RewriteOldConfigFiles "$CONF_FILE"
AddMissingConfigOptions "$CONF_FILE" AddMissingConfigOptions "$CONF_FILE"
UpdateConfigHeader "$CONF_FILE" UpdateConfigHeader "$CONF_FILE"
RenameStateFiles RenameStateFiles
else else
Usage Usage

Loading…
Cancel
Save