diff --git a/dev/common_batch.sh b/dev/common_batch.sh index 0a8bde0..bf5e97e 100755 --- a/dev/common_batch.sh +++ b/dev/common_batch.sh @@ -9,8 +9,8 @@ PROGRAM_BUILD=2016120401 ## If an instance fails, run it again if time permits if ! type "$BASH" > /dev/null; then - echo "Please run this script only with bash shell. Tested on bash >= 3.2" - exit 127 + echo "Please run this script only with bash shell. Tested on bash >= 3.2" + exit 127 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. diff --git a/dev/common_install.sh b/dev/common_install.sh index 9f97460..c176643 100755 --- a/dev/common_install.sh +++ b/dev/common_install.sh @@ -4,7 +4,7 @@ PROGRAM=[prgname] PROGRAM_VERSION=[version] PROGRAM_BINARY=$PROGRAM".sh" PROGRAM_BATCH=$PROGRAM"-batch.sh" -SCRIPT_BUILD=2016112401 +SCRIPT_BUILD=2016120801 ## osync / obackup / pmocr / zsnap install script ## 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 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 - LOG_FILE="$HOME/$PROGRAM-install.log" + LOG_FILE="$HOME/$PROGRAM-install.log" else - LOG_FILE="./$PROGRAM-install.log" + LOG_FILE="./$PROGRAM-install.log" fi # Generic quick logging function function _QuickLogger { - local value="${1}" - local destination="${2}" # Destination: stdout, log, both - - if ([ "$destination" == "log" ] || [ "$destination" == "both" ]); then - echo -e "$(date) - $value" >> "$LOG_FILE" - elif ([ "$destination" == "stdout" ] || [ "$destination" == "both" ]); then - echo -e "$value" - fi + local value="${1}" + local destination="${2}" # Destination: stdout, log, both + + if ([ "$destination" == "log" ] || [ "$destination" == "both" ]); then + echo -e "$(date) - $value" >> "$LOG_FILE" + elif ([ "$destination" == "stdout" ] || [ "$destination" == "both" ]); then + echo -e "$value" + fi } function QuickLogger { @@ -64,17 +64,17 @@ function QuickLogger { fi } -function urlencode() { +function UrlEncode() { # urlencode local LANG=C local length="${#1}" for (( i = 0; i < length; i++ )); do - local c="${1:i:1}" - case $c in - [a-zA-Z0-9.~_-]) printf "$c" ;; - *) printf '%%%02X' "'$c" ;; - esac + local c="${1:i:1}" + case $c in + [a-zA-Z0-9.~_-]) printf "$c" ;; + *) printf '%%%02X' "'$c" ;; + esac done } @@ -83,23 +83,23 @@ function SetOSSettings { USER=root - # 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 - localOsVar="BusyBox" - else - # Detecting the special ubuntu userland in Windows 10 bash - if grep -i Microsoft /proc/sys/kernel/osrelease > /dev/null 2>&1; then - localOsVar="Microsoft" - else - localOsVar="$(uname -spio 2>&1)" - if [ $? != 0 ]; then - localOsVar="$(uname -v 2>&1)" - if [ $? != 0 ]; then - localOsVar="$(uname)" - fi - fi - fi - fi + # 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 + localOsVar="BusyBox" + else + # Detecting the special ubuntu userland in Windows 10 bash + if grep -i Microsoft /proc/sys/kernel/osrelease > /dev/null 2>&1; then + localOsVar="Microsoft" + else + localOsVar="$(uname -spio 2>&1)" + if [ $? != 0 ]; then + localOsVar="$(uname -v 2>&1)" + if [ $? != 0 ]; then + localOsVar="$(uname)" + fi + fi + fi + fi case $localOsVar in *"BSD"*) @@ -118,11 +118,11 @@ function SetOSSettings { esac if ([ "$USER" != "" ] && [ "$(whoami)" != "$USER" ] && [ "$FAKEROOT" == "" ]); then - QuickLogger "Must be run as $USER." + QuickLogger "Must be run as $USER." exit 1 fi - OS=$(urlencode "$localOsVar") + OS=$(UrlEncode "$localOsVar") } function GetInit { @@ -262,22 +262,22 @@ function CopyServiceFiles { } function Statistics { - if type wget > /dev/null; then - wget -qO- "$STATS_LINK" > /dev/null 2>&1 - if [ $? == 0 ]; then - return 0 - fi + if type wget > /dev/null; then + wget -qO- "$STATS_LINK" > /dev/null 2>&1 + if [ $? == 0 ]; then + return 0 + fi fi - if type curl > /dev/null; then - curl "$STATS_LINK" -o /dev/null > /dev/null 2>&1 - if [ $? == 0 ]; then - return 0 - fi + if type curl > /dev/null; then + curl "$STATS_LINK" -o /dev/null > /dev/null 2>&1 + if [ $? == 0 ]; then + return 0 + fi fi - QuickLogger "Neiter wget nor curl could be used for. Cannot run statistics. Use the provided link please." - return 1 + QuickLogger "Neiter wget nor curl could be used for. Cannot run statistics. Use the provided link please." + return 1 } function Usage { diff --git a/dev/merge.sh b/dev/merge.sh index 0765084..7ab3c91 100755 --- a/dev/merge.sh +++ b/dev/merge.sh @@ -68,12 +68,12 @@ function __PREPROCESSOR_MergeSubset { local subsetFile="${3}" local mergedFile="${4}" - sed -n "/$subsetBegin/,/$subsetEnd/p" "$subsetFile" > "$subsetFile.$subsetBegin" + 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" + 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 @@ -84,13 +84,13 @@ function __PREPROCESSOR_MergeSubset { exit 1 fi - rm -f "$mergedFile" + rm -f "$mergedFile" if [ $? != 0 ]; then QuickLogger "Cannot remove merged original file [$mergedFile]." "stderr" exit 1 fi - mv "$mergedFile.tmp" "$mergedFile" + mv "$mergedFile.tmp" "$mergedFile" if [ $? != 0 ]; then QuickLogger "Cannot move merged tmp file to original [$mergedFile]." "stderr" exit 1 diff --git a/dev/n_osync.sh b/dev/n_osync.sh index 4265935..46334af 100755 --- a/dev/n_osync.sh +++ b/dev/n_osync.sh @@ -124,60 +124,60 @@ function TrapQuit { } function CheckEnvironment { - __CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG + __CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG - if [ "$REMOTE_OPERATION" == "yes" ]; then - if ! type ssh > /dev/null 2>&1 ; then - Logger "ssh not present. Cannot start sync." "CRITICAL" - exit 1 - fi + if [ "$REMOTE_OPERATION" == "yes" ]; then + if ! type ssh > /dev/null 2>&1 ; then + Logger "ssh not present. Cannot start sync." "CRITICAL" + exit 1 + fi if [ "$SSH_PASSWORD_FILE" != "" ] && ! type sshpass > /dev/null 2>&1 ; then Logger "sshpass not present. Cannot use password authentication." "CRITICAL" exit 1 fi - fi + fi - if ! type rsync > /dev/null 2>&1 ; then - Logger "rsync not present. Sync cannot start." "CRITICAL" - exit 1 - fi + if ! type rsync > /dev/null 2>&1 ; then + Logger "rsync not present. Sync cannot start." "CRITICAL" + exit 1 + fi - if ! type pgrep > /dev/null 2>&1 ; then - Logger "pgrep not present. Sync cannot start." "CRITICAL" - exit 1 - fi + if ! type pgrep > /dev/null 2>&1 ; then + Logger "pgrep not present. Sync cannot start." "CRITICAL" + exit 1 + fi } # Only gets checked in config file mode where all values should be present function CheckCurrentConfig { - __CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG - - # 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) - 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" - eval "$test" - done - - # 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) - for i in "${num_vars[@]}"; do + __CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG + + # 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) + 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" + eval "$test" + done + + # 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) + 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" - eval "$test" - done + eval "$test" + done } # Gets checked in quicksync and config file mode function CheckCurrentConfigAll { - __CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG + __CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG local tmp - if [ "$INSTANCE_ID" == "" ]; then - Logger "No INSTANCE_ID defined in config file." "CRITICAL" - exit 1 - fi + if [ "$INSTANCE_ID" == "" ]; then + Logger "No INSTANCE_ID defined in config file." "CRITICAL" + exit 1 + fi if [ "$INITIATOR_SYNC_DIR" == "" ]; then 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 & pids="$pids;$!" fi - INITIATOR_LOCK_FILE_EXISTS=true - TARGET_LOCK_FILE_EXISTS=true + INITIATOR_LOCK_FILE_EXISTS=true + TARGET_LOCK_FILE_EXISTS=true WaitForTaskCompletion $pids 720 1800 $SLEEP_TIME $KEEP_LOGGING true true false retval=$? if [ $retval -ne 0 ]; then - IFS=';' read -r -a pidArray <<< "$(eval echo \"\$WAIT_FOR_TASK_COMPLETION_${FUNCNAME[0]}\")" - for pid in "${pidArray[@]}"; do - pid=${pid%:*} - if [ "$pid" == "$initiatorPid" ]; then - INITIATOR_LOCK_FILE_EXISTS=false - elif [ "$pid" == "$targetPid" ]; then - TARGET_LOCK_FILE_EXISTS=false - fi - done - - Logger "Cancelling task." "CRITICAL" $retval + IFS=';' read -r -a pidArray <<< "$(eval echo \"\$WAIT_FOR_TASK_COMPLETION_${FUNCNAME[0]}\")" + for pid in "${pidArray[@]}"; do + pid=${pid%:*} + if [ "$pid" == "$initiatorPid" ]; then + INITIATOR_LOCK_FILE_EXISTS=false + elif [ "$pid" == "$targetPid" ]; then + TARGET_LOCK_FILE_EXISTS=false + fi + done + + Logger "Cancelling task." "CRITICAL" $retval exit 1 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" 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 - rm -f ".$PROGRAM.ctime_mtime.$replicaType.$SCRIPT_PID" - fi + if [ -f ".$PROGRAM.ctime_mtime.$replicaType.$SCRIPT_PID" ]; then + rm -f ".$PROGRAM.ctime_mtime.$replicaType.$SCRIPT_PID" + fi ENDSSH retval=$? 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 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 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" @@ -1414,7 +1414,7 @@ function Sync { echo "${SYNC_ACTION[1]}" > "${INITIATOR[$__targetLastActionFile]}" fi - exit 1 + exit 1 else echo "${SYNC_ACTION[1]}" > "${INITIATOR[$__initiatorLastActionFile]}" echo "${SYNC_ACTION[1]}" > "${INITIATOR[$__targetLastActionFile]}" @@ -1459,7 +1459,7 @@ function Sync { echo "${SYNC_ACTION[2]}" > "${INITIATOR[$__targetLastActionFile]}" fi - exit 1 + exit 1 else echo "${SYNC_ACTION[2]}" > "${INITIATOR[$__initiatorLastActionFile]}" echo "${SYNC_ACTION[2]}" > "${INITIATOR[$__targetLastActionFile]}" @@ -1583,7 +1583,7 @@ function Sync { echo "${SYNC_ACTION[5]}" > "${INITIATOR[$__targetLastActionFile]}" fi - exit 1 + exit 1 else echo "${SYNC_ACTION[5]}" > "${INITIATOR[$__initiatorLastActionFile]}" echo "${SYNC_ACTION[5]}" > "${INITIATOR[$__targetLastActionFile]}" @@ -1629,7 +1629,7 @@ function Sync { echo "${SYNC_ACTION[6]}" > "${INITIATOR[$__targetLastActionFile]}" fi - exit 1 + exit 1 else echo "${SYNC_ACTION[6]}" > "${INITIATOR[$__initiatorLastActionFile]}" echo "${SYNC_ACTION[6]}" > "${INITIATOR[$__targetLastActionFile]}" @@ -1885,10 +1885,10 @@ function Init { INITIATOR_SYNC_DIR="${INITIATOR_SYNC_DIR%/}/" TARGET_SYNC_DIR="${TARGET_SYNC_DIR%/}/" - # Expand ~ if exists - INITIATOR_SYNC_DIR="${INITIATOR_SYNC_DIR/#\~/$HOME}" - TARGET_SYNC_DIR="${TARGET_SYNC_DIR/#\~/$HOME}" - SSH_RSA_PRIVATE_KEY="${SSH_RSA_PRIVATE_KEY/#\~/$HOME}" + # Expand ~ if exists + INITIATOR_SYNC_DIR="${INITIATOR_SYNC_DIR/#\~/$HOME}" + TARGET_SYNC_DIR="${TARGET_SYNC_DIR/#\~/$HOME}" + SSH_RSA_PRIVATE_KEY="${SSH_RSA_PRIVATE_KEY/#\~/$HOME}" SSH_PASSWORD_FILE="${SSH_PASSWORD_FILE/#\~/$HOME}" ## Replica format @@ -1900,9 +1900,9 @@ function Init { local deleteDir="deleted" local partialDir="_partial" local lastAction="last-action" - local resumeCount="resume-count" + local resumeCount="resume-count" if [ "$_DRYRUN" == true ]; then - local drySuffix="-dry" + local drySuffix="-dry" else local drySuffix= fi @@ -2012,8 +2012,8 @@ function Usage { __CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG if [ "$IS_STABLE" != "yes" ]; then - echo -e "\e[93mThis is an unstable dev build. Please use with caution.\e[0m" - fi + echo -e "\e[93mThis is an unstable dev build. Please use with caution.\e[0m" + fi echo "$PROGRAM $PROGRAM_VERSION $PROGRAM_BUILD" echo "$AUTHOR" diff --git a/dev/ofunctions.sh b/dev/ofunctions.sh index d613981..7e4554a 100644 --- a/dev/ofunctions.sh +++ b/dev/ofunctions.sh @@ -39,7 +39,7 @@ _LOGGER_VERBOSE=false _LOGGER_ERR_ONLY=false _LOGGER_PREFIX="date" if [ "$KEEP_LOGGING" == "" ]; then - KEEP_LOGGING=1801 + KEEP_LOGGING=1801 fi # Initial error status, logging 'WARN', 'ERROR' or 'CRITICAL' will enable alerts flags diff --git a/dev/tests/run_tests.sh b/dev/tests/run_tests.sh index 334aa05..15a0ec6 100755 --- a/dev/tests/run_tests.sh +++ b/dev/tests/run_tests.sh @@ -156,7 +156,7 @@ function CreateOldFile () { assertEquals "touch [$filePath]" "0" $? # 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 debugfs -w -R 'set_inode_field "'$filePath'" ctime 201001010101' $drive @@ -175,7 +175,7 @@ function PrepareLocalDirs () { mkdir -p "$INITIATOR_DIR" if [ -d "$TARGET_DIR" ]; then - rm -rf "$TARGET_DIR" + rm -rf "$TARGET_DIR" fi mkdir -p "$TARGET_DIR" } @@ -283,8 +283,8 @@ function oneTimeTearDown () { } function setUp () { - rm -rf "$INITIATOR_DIR" - rm -rf "$TARGET_DIR" + rm -rf "$INITIATOR_DIR" + rm -rf "$TARGET_DIR" } # 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 retval=$? 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 # osync v1.1 had different exit codes, 240 was warning, anything else than 0 was error 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 - 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 - 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 done @@ -1256,20 +1256,20 @@ function test_UpgradeConfRun () { return 0 fi - # Basic return code tests. Need to go deep into file presence testing - cd "$OSYNC_DIR" + # Basic return code tests. Need to go deep into file presence testing + cd "$OSYNC_DIR" PrepareLocalDirs - # Make a security copy of the old config file - cp "$CONF_DIR/$OLD_CONF" "$CONF_DIR/$TMP_OLD_CONF" + # Make a security copy of the old config file + cp "$CONF_DIR/$OLD_CONF" "$CONF_DIR/$TMP_OLD_CONF" - ./$OSYNC_UPGRADE "$CONF_DIR/$TMP_OLD_CONF" - assertEquals "Conf file upgrade" "0" $? - ./$OSYNC_EXECUTABLE "$CONF_DIR/$TMP_OLD_CONF" - assertEquals "Upgraded conf file execution test" "0" $? + ./$OSYNC_UPGRADE "$CONF_DIR/$TMP_OLD_CONF" + assertEquals "Conf file upgrade" "0" $? + ./$OSYNC_EXECUTABLE "$CONF_DIR/$TMP_OLD_CONF" + assertEquals "Upgraded conf file execution test" "0" $? - rm -f "$CONF_DIR/$TMP_OLD_CONF" - rm -f "$CONF_DIR/$TMP_OLD_CONF.save" + rm -f "$CONF_DIR/$TMP_OLD_CONF" + rm -f "$CONF_DIR/$TMP_OLD_CONF.save" } function test_DaemonMode () { @@ -1330,7 +1330,7 @@ function test_DaemonMode () { function test_NoRemoteAccessTest () { RemoveSSH - cd "$OSYNC_DIR" + cd "$OSYNC_DIR" PrepareLocalDirs REMOTE_HOST_PING=no ./$OSYNC_EXECUTABLE ${osyncParameters[$__confLocal]} diff --git a/upgrade-v1.0x-v1.2x.sh b/upgrade-v1.0x-v1.2x.sh index d57db7c..ea60bda 100755 --- a/upgrade-v1.0x-v1.2x.sh +++ b/upgrade-v1.0x-v1.2x.sh @@ -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 if ! type "$BASH" > /dev/null; then - echo "Please run this script only with bash shell. Tested on bash >= 3.2" - exit 127 + echo "Please run this script only with bash shell. Tested on bash >= 3.2" + exit 127 fi # Defines all keywords / value sets in osync configuration files @@ -458,12 +458,12 @@ function RewriteOldConfigFiles { exit 1 fi - echo "Backing up [$config_file] as [$config_file.save]" - cp -p "$config_file" "$config_file.save" - if [ $? != 0 ]; then - echo "Cannot backup config file." - exit 1 - fi + echo "Backing up [$config_file] as [$config_file.save]" + cp -p "$config_file" "$config_file.save" + if [ $? != 0 ]; then + echo "Cannot backup config file." + exit 1 + fi echo "Rewriting config file $config_file" @@ -480,34 +480,34 @@ function RewriteOldConfigFiles { } function AddMissingConfigOptions { - local config_file="${1}" - local counter=0 - - while [ $counter -lt ${#KEYWORDS[@]} ]; do - if ! grep "^${KEYWORDS[$counter]}=" > /dev/null "$config_file"; then - echo "${KEYWORDS[$counter]} not found" - if [ $counter -gt 0 ]; then - sed -i'.tmp' '/^'${KEYWORDS[$((counter-1))]}'=*/a\'$'\n'${KEYWORDS[$counter]}'="'"${VALUES[$counter]}"'"\'$'\n''' "$config_file" - if [ $? -ne 0 ]; then - echo "Cannot add missing ${[KEYWORDS[$counter]}." - exit 1 - fi - else - sed -i'.tmp' '/onfig file rev*/a\'$'\n'${KEYWORDS[$counter]}'="'"${VALUES[$counter]}"'"\'$'\n''' "$config_file" - fi - echo "Added missing ${KEYWORDS[$counter]} config option with default option [${VALUES[$counter]}]" - fi - counter=$((counter+1)) - done + local config_file="${1}" + local counter=0 + + while [ $counter -lt ${#KEYWORDS[@]} ]; do + if ! grep "^${KEYWORDS[$counter]}=" > /dev/null "$config_file"; then + echo "${KEYWORDS[$counter]} not found" + if [ $counter -gt 0 ]; then + sed -i'.tmp' '/^'${KEYWORDS[$((counter-1))]}'=*/a\'$'\n'${KEYWORDS[$counter]}'="'"${VALUES[$counter]}"'"\'$'\n''' "$config_file" + if [ $? -ne 0 ]; then + echo "Cannot add missing ${[KEYWORDS[$counter]}." + exit 1 + fi + else + sed -i'.tmp' '/onfig file rev*/a\'$'\n'${KEYWORDS[$counter]}'="'"${VALUES[$counter]}"'"\'$'\n''' "$config_file" + fi + echo "Added missing ${KEYWORDS[$counter]} config option with default option [${VALUES[$counter]}]" + fi + counter=$((counter+1)) + done } 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' '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 @@ -544,9 +544,9 @@ elif [ "$1" != "" ] && [ -f "$1" ] && [ -w "$1" ]; then CONF_FILE="${CONF_FILE%/}" LoadConfigFile "$CONF_FILE" Init - RewriteOldConfigFiles "$CONF_FILE" - AddMissingConfigOptions "$CONF_FILE" - UpdateConfigHeader "$CONF_FILE" + RewriteOldConfigFiles "$CONF_FILE" + AddMissingConfigOptions "$CONF_FILE" + UpdateConfigHeader "$CONF_FILE" RenameStateFiles else Usage