New api function to manage seq configurations (create/use)
Seq template is generated by sequencer.sh; deleting static template
This commit is contained in:
@@ -15,6 +15,6 @@ Contains sequences (seqs) for different tools, servers or occasions.
|
||||
Sequencer include working on sh and bash.
|
||||
|
||||
[...]
|
||||
. ./sequencer.sh
|
||||
. /usr/local/bin/sequencer.sh
|
||||
|
||||
see [seqTemplate.sh](https://winklerfamilie.eu/git/efelon/shell_sequencer/src/branch/master/seqTemplate.sh)
|
||||
see seqTemplateExample.sh (which can be generated when calling sequencer.sh directly)
|
||||
|
@@ -1,53 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
##
|
||||
## Sequencer interface:
|
||||
## - step_[1 - 255]_info [STEP NUMBER]
|
||||
## functions providing short header for help and user interaction
|
||||
## - step_[1 - 255]_alias
|
||||
## (optional) provide a string as alias for this step number
|
||||
## - step_[1 - 255] [STEP NUMBER]
|
||||
## performing custom shell operations
|
||||
##
|
||||
|
||||
step_1_info() { echo "Step $1 header"; }
|
||||
step_1_alias() { ALIAS="begin"; }
|
||||
step_1() {
|
||||
exe cat '.no f"le'
|
||||
saveReturn $?
|
||||
}
|
||||
|
||||
step_2_info() { echo "Step $1 header"; }
|
||||
step_2() {
|
||||
echo -e "Zwei"
|
||||
endReturn
|
||||
echo zwo
|
||||
}
|
||||
|
||||
step_3_info() { echo "Step $1 header"; }
|
||||
step_3() {
|
||||
echo drei
|
||||
}
|
||||
|
||||
step_10_info() { echo "Step $1 header"; }
|
||||
step_10() {
|
||||
echo zehn
|
||||
}
|
||||
|
||||
step_11_info() { echo "Step $1 header"; }
|
||||
step_11_alias() { ALIAS="elf"; }
|
||||
step_11() {
|
||||
echo elf
|
||||
}
|
||||
|
||||
# Sequence Revision
|
||||
VERSION_SEQREV=3
|
||||
|
||||
# Workaround when called from different directory
|
||||
# Not needed when path to sequencer is absolut
|
||||
#
|
||||
# It is recommended to copy or link sequencer.sh to
|
||||
# /usr/local/bin
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
|
||||
# Path to local sequencer.sh script
|
||||
. ${DIR}/./sequencer/sequencer.sh
|
@@ -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
|
||||
|
Reference in New Issue
Block a user