From 0ec36247f7f2585a5980a1c3f9dae739596aec5e Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Mon, 13 Jan 2020 14:12:04 +0100 Subject: [PATCH] Use available configuration file if exists in the same directory as the template --- sequencer/sequencer.sh | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/sequencer/sequencer.sh b/sequencer/sequencer.sh index 7d1b1c9..f32797f 100755 --- a/sequencer/sequencer.sh +++ b/sequencer/sequencer.sh @@ -101,10 +101,10 @@ helpApi() { echo " [OPTION]" echo " -t : Source config also if created from template" echo " Returns" - echo " 0 : Sourced configuration or" - echo " (-t) : Created and sourced configuration from template" - echo " 1 : Created configuration from template but not sourced" - echo " 2 : or created empty configuration" + echo " 0 : sourced configuration or" + echo " (-t) : created and sourced configuration from template" + echo " 1 : created configuration from template but not sourced" + echo " 2 : created empty configuration" echo echo " addConf [SOURCE TYPE] " echo " Trying to write or append text or a file () to a destination file." @@ -279,9 +279,9 @@ endReturn() { # -t : Source config also if created from template # Return # 0 : Sourced configuration or -# (-t) : Created and sourced configuration from template +# (-t) : created and sourced configuration from template # 1 : Created configuration from template but not sourced -# 2 : or created empty configuration +# 2 : Created empty configuration initSeqConfig() { local sourceAlways=0 for arg in "$@" ; do @@ -311,6 +311,19 @@ initSeqConfig() { # Config does not exist, check for template if [ -s "$configTemplate" ] ; then + + # Check first if there is an existing configuration at the templates position + local configExists="$(dirname $configTemplate)/$1" + if [ -s "$configExists" ] ; then + exe mv "$configExists" "$configLoc" + endReturn -o $? "Unable to use existing configuration: $configExists" + + echoerr " [I] Using existing configuration: $configExists" + echoerr " (Moved to $SEQ_CONFIG_HOME)" + . "$configLoc" + return 0 + fi + exe cp -ar "$configTemplate" "$configLoc" endReturn -o $? "Failed to create configuration" @@ -320,6 +333,7 @@ initSeqConfig() { return 1 else echo " [W] Using seq configuration from template $configTemplate" + echo " (Copied to $SEQ_CONFIG_HOME)" SEQ_CONFIG_FILE="$configLoc" . "$configLoc" return 0 @@ -724,6 +738,7 @@ displayHelp() { echo " - step_${i}_info() missing" fi done + echo fi }