Moved commandline args setup to sub function

This commit is contained in:
deajan 2017-07-27 22:50:48 +02:00
parent a80b65860a
commit 09c664fe4b
1 changed files with 164 additions and 157 deletions

View File

@ -2,12 +2,13 @@
#TODO treeList, deleteList, _getFileCtimeMtime, conflictList should be called without having statedir informed. Just give the full path ?
#TODO check if _getCtimeMtime | sort removal needs to be backported
#Check dryruns with nosuffix mode for timestampList
PROGRAM="osync" # Rsync based two way sync engine with fault tolerance
AUTHOR="(C) 2013-2017 by Orsiris de Jong"
CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr"
PROGRAM_VERSION=1.2.2-dev
PROGRAM_BUILD=2017061801
PROGRAM_BUILD=2017072701
IS_STABLE=no
@ -2242,6 +2243,7 @@ function Init {
readonly __timestampAfterFile=17
readonly __timestampAfterFileNoSuffix=18
readonly __conflictListFile=19
readonly __updateTriggerFile=20
INITIATOR=()
INITIATOR[$__type]='initiator'
@ -2264,6 +2266,7 @@ function Init {
INITIATOR[$__timestampAfterFile]="-timestamps-after-$INSTANCE_ID$drySuffix"
INITIATOR[$__timestampAfterFileNoSuffix]="-timestamps-after-$INSTANCE_ID"
INITIATOR[$__conflictListFile]="conflicts-$INSTANCE_ID$drySuffix"
INITIATOR[$__updateTriggerFile]="$INITIATOR_SYNC_DIR$OSYNC_DIR/.osync-update.push"
TARGET=()
TARGET[$__type]='target'
@ -2278,7 +2281,6 @@ function Init {
TARGET[$__resumeCount]="$TARGET_SYNC_DIR$OSYNC_DIR/$stateDir/$resumeCount-$INSTANCE_ID$drySuffix" # unused
TARGET[$__treeCurrentFile]="-tree-current-$INSTANCE_ID$drySuffix" # unused
TARGET[$__treeAfterFile]="-tree-after-$INSTANCE_ID$drySuffix" # unused
#WIP NoSuffix file to add to timestamp
TARGET[$__treeAfterFileNoSuffix]="-tree-after-$INSTANCE_ID" # unused
TARGET[$__deletedListFile]="-deleted-list-$INSTANCE_ID$drySuffix" # unused
TARGET[$__failedDeletedListFile]="-failed-delete-$INSTANCE_ID$drySuffix"
@ -2287,6 +2289,7 @@ function Init {
TARGET[$__timestampAfterFile]="-timestamps-after-$INSTANCE_ID$drySuffix"
TARGET[$__timestampAfterFileNoSuffix]="-timestamps-after-$INSTANCE_ID"
TARGET[$__conflictListFile]="conflicts-$INSTANCE_ID$drySuffix"
TARGET[$__updateTriggerFile]="$TARGET_SYNC_DIR$OSYNC_DIR/.osync-update.push"
PARTIAL_DIR="${INITIATOR[$__partialDir]}"
@ -2479,13 +2482,16 @@ _NOLOCKS=false
osync_cmd=$0
_SUMMARY=false
if [ $# -eq 0 ]
then
Usage
fi
first=1
for i in "$@"; do
function GetCommandlineArguments {
local isFirstArgument=true
if [ $# -eq 0 ]
then
Usage
fi
for i in "$@"; do
case $i in
--dry)
_DRYRUN=true
@ -2584,27 +2590,28 @@ for i in "$@"; do
_REMOTE_TOKEN=${i##*=}
;;
*)
if [ $first == "0" ]; then
if [ $isFirstArgument == false ]; then
Logger "Unknown option '$i'" "CRITICAL"
Usage
fi
;;
esac
first=0
done
isFirstArgument=false
done
# Remove leading space if there is one
opts="${opts# *}"
# Remove leading space if there is one
opts="${opts# *}"
}
## Here we set default options for quicksync tasks when no configuration file is provided.
GetCommandlineArguments "$@"
if [ $_QUICK_SYNC -eq 2 ]; then
## Here we set default options for quicksync tasks when no configuration file is provided.
if [ $_QUICK_SYNC -eq 2 ]; then
if [ "$INSTANCE_ID" == "" ]; then
INSTANCE_ID="quicksync_task"
fi
# Let the possibility to initialize those values directly via command line like SOFT_DELETE_DAYS=60 ./osync.sh
if [ $(IsInteger $MINIMUM_SPACE) -ne 1 ]; then
MINIMUM_SPACE=1024
fi
@ -2624,6 +2631,7 @@ opts="${opts# *}"
if [ $(IsInteger $SOFT_MAX_EXEC_TIME) -ne 1 ]; then
SOFT_MAX_EXEC_TIME=0
fi
if [ $(IsInteger $HARD_MAX_EXEC_TIME) -ne 1 ]; then
HARD_MAX_EXEC_TIME=0
fi
@ -2631,12 +2639,11 @@ opts="${opts# *}"
if [ "$PATH_SEPARATOR_CHAR" == "" ]; then
PATH_SEPARATOR_CHAR=";"
fi
MIN_WAIT=30
else
else
ConfigFile="${1}"
LoadConfigFile "$ConfigFile"
fi
fi
if [ "$LOGFILE" == "" ]; then
if [ -w /var/log ]; then