New api function to manage seq configurations (create/use)

Seq template is generated by sequencer.sh; deleting static template
This commit is contained in:
2020-01-13 11:48:15 +01:00
parent 2e6984aac8
commit 4b4df3132a
3 changed files with 94 additions and 61 deletions

View File

@@ -7,8 +7,8 @@
## Version information
VERSION_REV=9
VERSION_MAJOR=2
VERSION_REV=10
VERSION_MAJOR=0
VERSION_MINOR=0
## Start of generic script part
@@ -21,6 +21,9 @@ ERNO=0
STEP_ARGS=
MAX_STEP=512
ALIAS=
SEQ_CONFIG_NAME=".seqs"
SEQ_CONFIG_HOME="$HOME/$SEQ_CONFIG_NAME"
SEQ_CONFIG_FILE=
TEMPLATE_NAME=seqTemplateExample.sh
MISSING_CONF=missingConf.log
VERSION_STRING="${VERSION_REV}.${VERSION_MAJOR}.${VERSION_MINOR}"
@@ -74,6 +77,11 @@ helpApi() {
echo " \$DRY"
echo " 0 : default"
echo " 1 (-d) : Commands shall only be printed but not executed"
echo " \$SEQ_CONFIG_HOME"
echo " Path to user specific seq configuration directory"
echo " \$SEQ_CONFIG_FILE"
echo " Path to user specific seq configuration file"
echo " Will be empty if unused"
echo
echo "sequencer.sh build-in functions:"
echo
@@ -88,6 +96,16 @@ helpApi() {
echo " - Shell commands cd, read, ... won't work because COMMANDLINE is started in a new shell."
echo " - All apostrophes need to be esacped since the command line is given as string."
echo
echo " initSeqConfig [OPTION] <NAME> [TEMPLATE]"
echo " Create a configuration file in $SEQ_CONFIG_HOME/ and source it if already existent."
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
echo " addConf <OPTIONS> [SOURCE TYPE] <SOURCE> <DESTINATION FILE>"
echo " Trying to write or append text or a file (<SOURCE>) to a destination file."
echo " If the CONFIGFILE exists, a backup (name_%Y%m%d-%H%M%S.bck) is saved at the same location."
@@ -254,6 +272,68 @@ endReturn() {
fi
}
# initSeqConfig [OPTION] <NAME> [TEMPLATE]
# Create a configuration file in the users' home.
# Source it if already existent
# [OPTION]
# -t : Source config also if created from template
# Return
# 0 : Sourced configuration or
# (-t) : Created and sourced configuration from template
# 1 : Created configuration from template but not sourced
# 2 : or created empty configuration
initSeqConfig() {
local sourceAlways=0
for arg in "$@" ; do
case "$1" in
-t)
sourceAlways=1
shift
;;
esac
done
local configLoc="$SEQ_CONFIG_HOME/$1"
local configTemplate="$2"
# Create config subdir in users home
if [ ! -e "$SEQ_CONFIG_HOME/" ] ; then
echo -n " [I] Creating $(realpath $SEQ_CONFIG_HOME)..."
exe mkdir -p "$SEQ_CONFIG_HOME" && echo "Ok" || echo "Nok"
fi
if [ -s "$configLoc" ] ; then
echo " [I] Using configuration file: $configLoc"
SEQ_CONFIG_FILE="$configLoc"
. "$configLoc"
return 0
fi
# Config does not exist, check for template
if [ -s "$configTemplate" ] ; then
exe cp -ar "$configTemplate" "$configLoc"
endReturn -o $? "Failed to create configuration"
if [ $sourceAlways -eq 0 ] ; then
echoerr " [W] Seq configuration created from template"
echoerr " Please modify "$configLoc" to your needs first"
return 1
else
echo " [W] Using seq configuration from template $configTemplate"
SEQ_CONFIG_FILE="$configLoc"
. "$configLoc"
return 0
fi
else
echo " [W] Seq configuration template empty"
fi
# Create empty config file
echo " [W] Created empty configuration file $configLoc"
exe touch "$configLoc"
return 2
}
# addConf <CONF_MODE> [FILE_MODE] <SOURCE> <DESTINATION_FILE>
# trying to write a file
# if exists, one attempt is made to create bck file of it
@@ -520,7 +600,7 @@ selection() {
done
}
# Creating a minimal step definition template
# Creating a minimal seq (step definition) template
createTemplate() {
if [ -f $TEMPLATE_NAME ] ; then
return 1
@@ -532,13 +612,19 @@ createTemplate() {
echo "# Get script working directory" >> $TEMPLATE_NAME
echo "# (when called from a different directory)" >> $TEMPLATE_NAME
echo "WDIR=\"\$( cd \"\$( dirname \"\${BASH_SOURCE[0]}\" )\" >>/dev/null 2>&1 && pwd )\"" >> $TEMPLATE_NAME
echo "CONFIG_FILE=\"\$WDIR/\${toolName}.cfg\"" >> $TEMPLATE_NAME
echo "CONFIG_FILE_DEFAULT=\"\${CONFIG_FILE}.example\"" >> $TEMPLATE_NAME
echo "CONFIG=0" >> $TEMPLATE_NAME
echo "CONFIG_FILE_NAME=\"\${toolName}.cfg\"" >> $TEMPLATE_NAME
echo "CONFIG_FILE_TEMPLATE=\"\$WDIR/\${CONFIG_FILE_NAME}.example\"" >> $TEMPLATE_NAME
echo >> $TEMPLATE_NAME
echo "step_config() {" >> $TEMPLATE_NAME
echo " echo \"Called once before executing steps.\"" >> $TEMPLATE_NAME
echo " echo \"e.g. to source a config file:\"" >> $TEMPLATE_NAME
echo " ## e.g. to source a config file manually:" >> $TEMPLATE_NAME
echo " #. \"\$CONFIG_FILE\"" >> $TEMPLATE_NAME
echo " ## or to use sequencer api:" >> $TEMPLATE_NAME
echo " #initSeqConfig \"\$CONFIG_FILE_NAME\" \"\$CONFIG_FILE_TEMPLATE\"" >> $TEMPLATE_NAME
echo " #if [ \$CONFIG -ne 0 ] ; then" >> $TEMPLATE_NAME
echo " # CONFIG=1" >> $TEMPLATE_NAME
echo " #fi" >> $TEMPLATE_NAME
echo "}" >> $TEMPLATE_NAME
echo >> $TEMPLATE_NAME
echo "step_1_info() { echo \"My custom step\"; }" >> $TEMPLATE_NAME