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 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 #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 PROGRAM="osync" # Rsync based two way sync engine with fault tolerance
AUTHOR="(C) 2013-2017 by Orsiris de Jong" AUTHOR="(C) 2013-2017 by Orsiris de Jong"
CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr"
PROGRAM_VERSION=1.2.2-dev PROGRAM_VERSION=1.2.2-dev
PROGRAM_BUILD=2017061801 PROGRAM_BUILD=2017072701
IS_STABLE=no IS_STABLE=no
@ -2242,6 +2243,7 @@ function Init {
readonly __timestampAfterFile=17 readonly __timestampAfterFile=17
readonly __timestampAfterFileNoSuffix=18 readonly __timestampAfterFileNoSuffix=18
readonly __conflictListFile=19 readonly __conflictListFile=19
readonly __updateTriggerFile=20
INITIATOR=() INITIATOR=()
INITIATOR[$__type]='initiator' INITIATOR[$__type]='initiator'
@ -2264,6 +2266,7 @@ function Init {
INITIATOR[$__timestampAfterFile]="-timestamps-after-$INSTANCE_ID$drySuffix" INITIATOR[$__timestampAfterFile]="-timestamps-after-$INSTANCE_ID$drySuffix"
INITIATOR[$__timestampAfterFileNoSuffix]="-timestamps-after-$INSTANCE_ID" INITIATOR[$__timestampAfterFileNoSuffix]="-timestamps-after-$INSTANCE_ID"
INITIATOR[$__conflictListFile]="conflicts-$INSTANCE_ID$drySuffix" INITIATOR[$__conflictListFile]="conflicts-$INSTANCE_ID$drySuffix"
INITIATOR[$__updateTriggerFile]="$INITIATOR_SYNC_DIR$OSYNC_DIR/.osync-update.push"
TARGET=() TARGET=()
TARGET[$__type]='target' TARGET[$__type]='target'
@ -2278,7 +2281,6 @@ function Init {
TARGET[$__resumeCount]="$TARGET_SYNC_DIR$OSYNC_DIR/$stateDir/$resumeCount-$INSTANCE_ID$drySuffix" # unused TARGET[$__resumeCount]="$TARGET_SYNC_DIR$OSYNC_DIR/$stateDir/$resumeCount-$INSTANCE_ID$drySuffix" # unused
TARGET[$__treeCurrentFile]="-tree-current-$INSTANCE_ID$drySuffix" # unused TARGET[$__treeCurrentFile]="-tree-current-$INSTANCE_ID$drySuffix" # unused
TARGET[$__treeAfterFile]="-tree-after-$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[$__treeAfterFileNoSuffix]="-tree-after-$INSTANCE_ID" # unused
TARGET[$__deletedListFile]="-deleted-list-$INSTANCE_ID$drySuffix" # unused TARGET[$__deletedListFile]="-deleted-list-$INSTANCE_ID$drySuffix" # unused
TARGET[$__failedDeletedListFile]="-failed-delete-$INSTANCE_ID$drySuffix" TARGET[$__failedDeletedListFile]="-failed-delete-$INSTANCE_ID$drySuffix"
@ -2287,6 +2289,7 @@ function Init {
TARGET[$__timestampAfterFile]="-timestamps-after-$INSTANCE_ID$drySuffix" TARGET[$__timestampAfterFile]="-timestamps-after-$INSTANCE_ID$drySuffix"
TARGET[$__timestampAfterFileNoSuffix]="-timestamps-after-$INSTANCE_ID" TARGET[$__timestampAfterFileNoSuffix]="-timestamps-after-$INSTANCE_ID"
TARGET[$__conflictListFile]="conflicts-$INSTANCE_ID$drySuffix" TARGET[$__conflictListFile]="conflicts-$INSTANCE_ID$drySuffix"
TARGET[$__updateTriggerFile]="$TARGET_SYNC_DIR$OSYNC_DIR/.osync-update.push"
PARTIAL_DIR="${INITIATOR[$__partialDir]}" PARTIAL_DIR="${INITIATOR[$__partialDir]}"
@ -2479,13 +2482,16 @@ _NOLOCKS=false
osync_cmd=$0 osync_cmd=$0
_SUMMARY=false _SUMMARY=false
if [ $# -eq 0 ]
then
Usage
fi
first=1 function GetCommandlineArguments {
for i in "$@"; do local isFirstArgument=true
if [ $# -eq 0 ]
then
Usage
fi
for i in "$@"; do
case $i in case $i in
--dry) --dry)
_DRYRUN=true _DRYRUN=true
@ -2584,27 +2590,28 @@ for i in "$@"; do
_REMOTE_TOKEN=${i##*=} _REMOTE_TOKEN=${i##*=}
;; ;;
*) *)
if [ $first == "0" ]; then if [ $isFirstArgument == false ]; then
Logger "Unknown option '$i'" "CRITICAL" Logger "Unknown option '$i'" "CRITICAL"
Usage Usage
fi fi
;; ;;
esac esac
first=0 isFirstArgument=false
done done
# Remove leading space if there is one # Remove leading space if there is one
opts="${opts# *}" 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 if [ "$INSTANCE_ID" == "" ]; then
INSTANCE_ID="quicksync_task" INSTANCE_ID="quicksync_task"
fi fi
# Let the possibility to initialize those values directly via command line like SOFT_DELETE_DAYS=60 ./osync.sh # 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 if [ $(IsInteger $MINIMUM_SPACE) -ne 1 ]; then
MINIMUM_SPACE=1024 MINIMUM_SPACE=1024
fi fi
@ -2624,6 +2631,7 @@ opts="${opts# *}"
if [ $(IsInteger $SOFT_MAX_EXEC_TIME) -ne 1 ]; then if [ $(IsInteger $SOFT_MAX_EXEC_TIME) -ne 1 ]; then
SOFT_MAX_EXEC_TIME=0 SOFT_MAX_EXEC_TIME=0
fi fi
if [ $(IsInteger $HARD_MAX_EXEC_TIME) -ne 1 ]; then if [ $(IsInteger $HARD_MAX_EXEC_TIME) -ne 1 ]; then
HARD_MAX_EXEC_TIME=0 HARD_MAX_EXEC_TIME=0
fi fi
@ -2631,12 +2639,11 @@ opts="${opts# *}"
if [ "$PATH_SEPARATOR_CHAR" == "" ]; then if [ "$PATH_SEPARATOR_CHAR" == "" ]; then
PATH_SEPARATOR_CHAR=";" PATH_SEPARATOR_CHAR=";"
fi fi
MIN_WAIT=30 MIN_WAIT=30
else else
ConfigFile="${1}" ConfigFile="${1}"
LoadConfigFile "$ConfigFile" LoadConfigFile "$ConfigFile"
fi fi
if [ "$LOGFILE" == "" ]; then if [ "$LOGFILE" == "" ]; then
if [ -w /var/log ]; then if [ -w /var/log ]; then