New function "configuration profiles" for sequencer (initSeqConfig)
Changed usage definition to "cat" instead of echo
This commit is contained in:
@@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
## Version information
|
## Version information
|
||||||
|
|
||||||
VERSION_REV=11
|
VERSION_REV=12
|
||||||
VERSION_MAJOR=1
|
VERSION_MAJOR=0
|
||||||
VERSION_MINOR=5
|
VERSION_MINOR=0
|
||||||
|
|
||||||
## Start of generic script part
|
## Start of generic script part
|
||||||
|
|
||||||
@@ -25,143 +25,151 @@ ALIAS=
|
|||||||
SEQ_CONFIG_NAME=".seqs"
|
SEQ_CONFIG_NAME=".seqs"
|
||||||
SEQ_CONFIG_HOME="$HOME/$SEQ_CONFIG_NAME"
|
SEQ_CONFIG_HOME="$HOME/$SEQ_CONFIG_NAME"
|
||||||
SEQ_CONFIG_FILE=
|
SEQ_CONFIG_FILE=
|
||||||
|
SEQ_PROFILE_NAME=default
|
||||||
TEMPLATE_NAME=seqTemplateExample.sh
|
TEMPLATE_NAME=seqTemplateExample.sh
|
||||||
MISSING_CONF=missingConf.log
|
MISSING_CONF=missingConf.log
|
||||||
VERSION_STRING="${VERSION_REV}.${VERSION_MAJOR}.${VERSION_MINOR}"
|
VERSION_STRING="${VERSION_REV}.${VERSION_MAJOR}.${VERSION_MINOR}"
|
||||||
|
|
||||||
helpSequencer() {
|
helpSequencer() {
|
||||||
echo "Usage: ${0##*/} [OPTIONS] [STEP NUMBER(s) or ALIAS] [STEP ARGUMENTS]"
|
cat <<USAGE_EOF
|
||||||
echo
|
Usage: ${0##*/} [OPTIONS] [STEP NUMBER(s) or ALIAS] [STEP ARGUMENTS]
|
||||||
echo " [OPTIONS]"
|
|
||||||
echo " --dry-run, -d : Only print to console what would be done"
|
[OPTIONS]
|
||||||
echo " ! Attention - Sequence must support this"
|
--dry-run, -d : Only print to console what would be done
|
||||||
echo " --help, -h : Display help"
|
! Attention - Sequence must support this
|
||||||
echo " --helpapi, -ha : Display help about build-in supporting functions"
|
--help, -h : Display help
|
||||||
echo " (e.g. exe,addconf,echerr,...)"
|
--helpapi, -ha : Display help about build-in supporting functions
|
||||||
echo " --quiet, -q : Don't ask for permission to execute steps"
|
(e.g. exe,addconf,echerr,...)
|
||||||
echo " If called without starting step number, only this help is shown"
|
--profile, -p : Sequence configuration profile name (default: \"default\")
|
||||||
echo " -qq : Same as --quiet but suppresses regular sequencer.sh output"
|
If supported by seq
|
||||||
echo " --single, -s : Execute only one step"
|
--quiet, -q : Don't ask for permission to execute steps
|
||||||
echo " If more than one step is requested, only the first will be executed"
|
If called without starting step number, only this help is shown
|
||||||
echo " --verbose, -v : Verbose output (use exe() function to call shell commands in seqs)"
|
-qq : Same as --quiet but suppresses regular sequencer.sh output
|
||||||
echo " ( e.g.: exe apt update )"
|
--single, -s : Execute only one step
|
||||||
echo " --version : Display version of sequencer and revision of sequence"
|
If more than one step is requested, only the first will be executed
|
||||||
echo
|
--verbose, -v : Verbose output (use exe() function to call shell commands in seqs)
|
||||||
echo " [STEP NUMBER\"(s)\" 1-${MAX_STEP} or ALIAS]"
|
( e.g.: exe apt update )
|
||||||
echo " No STEP or ALIAS : assume 1 as starting point"
|
--version : Display version of sequencer and revision of sequence
|
||||||
echo " Single STEP or ALIAS : starting point of sequential process"
|
|
||||||
echo " Multiple STEPS or ALIAS : execute only given steps"
|
[STEP NUMBER\"(s)\" 1-${MAX_STEP} or ALIAS]
|
||||||
echo " (e.g. $0 \"2 4 12\")"
|
No STEP or ALIAS : assume 1 as starting point
|
||||||
echo " multiple steps need to be given as string"
|
Single STEP or ALIAS : starting point of sequential process
|
||||||
echo " [STEP ARGUMENTS]"
|
Multiple STEPS or ALIAS : execute only given steps
|
||||||
echo " * : Arguments will be passed to selected steps and step infos as:"
|
(e.g. $0 \"2 4 12\")
|
||||||
echo " \$2 ..."
|
multiple steps need to be given as string
|
||||||
echo " \$1 is always the step number"
|
[STEP ARGUMENTS]
|
||||||
|
* : Arguments will be passed to selected steps and step infos as:
|
||||||
|
\$2 ...
|
||||||
|
\$1 is always the step number
|
||||||
|
USAGE_EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
helpApi() {
|
helpApi(){
|
||||||
echo "sequencer.sh API"
|
cat <<USAGE_API
|
||||||
echo
|
sequencer.sh API
|
||||||
echo "The sequencer.sh build-in functions are available in all sequence functions:"
|
|
||||||
echo "- step_config"
|
The sequencer.sh build-in functions are available in all sequence functions:
|
||||||
echo " If optional step_config is defined in the sequence, it will be called once before any step."
|
- step_config
|
||||||
echo "- step_[1-${MAX_STEP}]_info"
|
If optional step_config is defined in the sequence, it will be called once before any step.
|
||||||
echo "- step_[1-${MAX_STEP}]_alias"
|
- step_[1-${MAX_STEP}]_info
|
||||||
echo "- step_[1-${MAX_STEP}]"
|
- step_[1-${MAX_STEP}]_alias
|
||||||
echo
|
- step_[1-${MAX_STEP}]
|
||||||
echo "sequencer.sh global variables:"
|
|
||||||
echo
|
sequencer.sh global variables:
|
||||||
echo " \$QUIET"
|
|
||||||
echo " 0 : default"
|
\$QUIET
|
||||||
echo " 1 (-q) : No user interaction (e.g. question to start a step)"
|
0 : default
|
||||||
echo " 2 (-qq) : 1 and no regular output of sequencer.sh"
|
1 (-q) : No user interaction (e.g. question to start a step)
|
||||||
echo " \$DRY"
|
2 (-qq) : 1 and no regular output of sequencer.sh
|
||||||
echo " 0 : default"
|
\$DRY
|
||||||
echo " 1 (-d) : Commands shall only be printed but not executed"
|
0 : default
|
||||||
echo " \$VERBOSE"
|
1 (-d) : Commands shall only be printed but not executed
|
||||||
echo " 0 : default"
|
\$VERBOSE
|
||||||
echo " 1 : Print full command from exe() or exep() before executing"
|
0 : default
|
||||||
echo " \$SEQ_CONFIG_HOME"
|
1 : Print full command from exe() or exep() before executing
|
||||||
echo " Path to user specific seq configuration directory"
|
\$SEQ_CONFIG_HOME
|
||||||
echo " \$SEQ_CONFIG_FILE"
|
Path to user specific seq configuration directory
|
||||||
echo " Path to user specific seq configuration file"
|
\$SEQ_CONFIG_FILE
|
||||||
echo " Will be empty if unused"
|
Path to user specific seq configuration file
|
||||||
echo
|
Will be empty if unused
|
||||||
echo "sequencer.sh build-in functions:"
|
|
||||||
echo
|
sequencer.sh build-in functions:
|
||||||
echo " exe [COMMANDLINE]"
|
|
||||||
echo " Execute command line without pipes or redirects (>,<,|)."
|
exe [COMMANDLINE]
|
||||||
echo " Supporting: dry-run (-d): only print command without execution"
|
Execute command line without pipes or redirects (>,<,|).
|
||||||
echo " verbose (-v): print command before execution"
|
Supporting: dry-run (-d): only print command without execution
|
||||||
echo
|
verbose (-v): print command before execution
|
||||||
echo " exep \"[COMMANDLINE]\""
|
|
||||||
echo " See exe, but support for pipes or redirects."
|
exep \"[COMMANDLINE]\"
|
||||||
echo " Important:"
|
See exe, but support for pipes or redirects.
|
||||||
echo " - Shell commands cd, read, ... won't work because COMMANDLINE is started in a new shell."
|
Important:
|
||||||
echo " - All apostrophes need to be esacped since the command line is given as string."
|
- 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 " initSeqConfig [OPTION] <NAME> [TEMPLATE]"
|
|
||||||
echo " Create a configuration file in $SEQ_CONFIG_HOME/ and source it if already existent."
|
initSeqConfig [OPTION] <NAME> [TEMPLATE]
|
||||||
echo " [OPTION]"
|
Create a configuration file in $SEQ_CONFIG_HOME/ and source it if already existent.
|
||||||
echo " -t : Source config also if created from template"
|
[OPTION]
|
||||||
echo " -e : Create empty configuration if no template is found"
|
-p : Use profiles
|
||||||
echo " Returns"
|
-t : Source config also if created from template
|
||||||
echo " 0 : sourced configuration or"
|
-e : Create empty configuration if no template is found
|
||||||
echo " (-t) : created and sourced configuration from template"
|
Returns
|
||||||
echo " 1 : created configuration from template but not sourced"
|
0 : sourced configuration or
|
||||||
echo " 2 : created empty configuration"
|
(-t) : created and sourced configuration from template
|
||||||
echo " 3 : No configuration created"
|
1 : created configuration from template but not sourced
|
||||||
echo
|
2 : created empty configuration
|
||||||
echo " addConf <OPTIONS> [SOURCE TYPE] <SOURCE> <DESTINATION FILE>"
|
3 : No configuration created
|
||||||
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."
|
addConf <OPTIONS> [SOURCE TYPE] <SOURCE> <DESTINATION FILE>
|
||||||
echo " If -s fails or -m, \"$(realpath "$MISSING_CONF")\" is created with the conflicts"
|
Trying to write or append text or a file (<SOURCE>) to a destination file.
|
||||||
echo " to be resolved by the user."
|
If the CONFIGFILE exists, a backup (name_%Y%m%d-%H%M%S.bck) is saved at the same location.
|
||||||
echo " <OPTIONS>"
|
If -s fails or -m, \"$(realpath "$MISSING_CONF")\" is created with the conflicts
|
||||||
echo " -c : create a new file"
|
to be resolved by the user.
|
||||||
echo " -a : append to existing file"
|
<OPTIONS>
|
||||||
echo " -s : skip if CONFIGFILE exists (no backup and entry in missing conf)"
|
-c : create a new file
|
||||||
echo " -m : only add content to missing conf and warn user"
|
-a : append to existing file
|
||||||
echo " [SOURCE TYPE]"
|
-s : skip if CONFIGFILE exists (no backup and entry in missing conf)
|
||||||
echo " -f : <SOURCE> is a file"
|
-m : only add content to missing conf and warn user
|
||||||
echo " <SOURCE>"
|
[SOURCE TYPE]
|
||||||
echo " Text or file (-f) to create or added to <DESTINATION FILE>"
|
-f : <SOURCE> is a file
|
||||||
echo " <DESTINATION FILE>"
|
<SOURCE>
|
||||||
echo " Target file to be created or modified."
|
Text or file (-f) to create or added to <DESTINATION FILE>
|
||||||
echo
|
<DESTINATION FILE>
|
||||||
echo " step <STEP NUMBER OR ALIAS>"
|
Target file to be created or modified.
|
||||||
echo " Executes a single step also by alias. Useful if step numbers get reorganized."
|
|
||||||
echo " dry-run is not applied in this function! The executed step is responsible."
|
step <STEP NUMBER OR ALIAS>
|
||||||
echo
|
Executes a single step also by alias. Useful if step numbers get reorganized.
|
||||||
echo " echoerr [...]"
|
dry-run is not applied in this function! The executed step is responsible.
|
||||||
echo " echo to stderr"
|
|
||||||
echo " [...] : all parameter are forwarded to echo"
|
echoerr [...]
|
||||||
echo
|
echo to stderr
|
||||||
echo " echoinfo [...]"
|
[...] : all parameter are forwarded to echo
|
||||||
echo " echo additional correctly indented line to step info"
|
|
||||||
echo " [...] : all parrameter are forwared to echo"
|
echoinfo [...]
|
||||||
echo
|
echo additional correctly indented line to step info
|
||||||
echo " endCheckEmpty <VARIABLENAME> [DESCRIPTION]"
|
[...] : all parrameter are forwared to echo
|
||||||
echo " exit 666 if variable is empty"
|
|
||||||
echo " <VARIABLENAME> : Name used within eval"
|
endCheckEmpty <VARIABLENAME> [DESCRIPTION]
|
||||||
echo " [DESCRIPTION] : Additional text for error output"
|
exit 666 if variable is empty
|
||||||
echo
|
<VARIABLENAME> : Name used within eval
|
||||||
echo " saveReturn [ERRORCODE]"
|
[DESCRIPTION] : Additional text for error output
|
||||||
echo " Save ERRORCODE if it is != 0 for later use with endReturn"
|
|
||||||
echo
|
saveReturn [ERRORCODE]
|
||||||
echo " getReturn"
|
Save ERRORCODE if it is != 0 for later use with endReturn
|
||||||
echo " Return last saved error code"
|
|
||||||
echo
|
getReturn
|
||||||
echo " endReturn [OPTIONS] [MESSAGE]"
|
Return last saved error code
|
||||||
echo " Notifys user that there was an error (previously saved by saveReturn,"
|
|
||||||
echo " or -o [ERRORCODE]) and asks to continue or end the sequence."
|
endReturn [OPTIONS] [MESSAGE]
|
||||||
echo " Always exits with evaluated error code."
|
Notifys user that there was an error (previously saved by saveReturn,
|
||||||
echo " [OPTIONS]"
|
or -o [ERRORCODE]) and asks to continue or end the sequence.
|
||||||
echo " -f : force exit without user input, if error code is not 0"
|
Always exits with evaluated error code.
|
||||||
echo " -o ERRORCODE : override stored error code and check ERRORCODE"
|
[OPTIONS]
|
||||||
echo " [MESSAGE]"
|
-f : force exit without user input, if error code is not 0
|
||||||
echo " String which is displayed in the error output"
|
-o ERRORCODE : override stored error code and check ERRORCODE
|
||||||
echo
|
[MESSAGE]
|
||||||
|
String which is displayed in the error output
|
||||||
|
|
||||||
|
USAGE_API
|
||||||
}
|
}
|
||||||
|
|
||||||
# Echo to stderr
|
# Echo to stderr
|
||||||
@@ -291,6 +299,7 @@ endReturn() {
|
|||||||
# Create a configuration file in the users' home.
|
# Create a configuration file in the users' home.
|
||||||
# Source it if already existent
|
# Source it if already existent
|
||||||
# [OPTION]
|
# [OPTION]
|
||||||
|
# -p : <NAME> is subfolder used for profiles
|
||||||
# -t : Source config also if created from template
|
# -t : Source config also if created from template
|
||||||
# -e : Create empty configuration if no template is found
|
# -e : Create empty configuration if no template is found
|
||||||
# Return
|
# Return
|
||||||
@@ -303,27 +312,36 @@ initSeqConfig() {
|
|||||||
local arg
|
local arg
|
||||||
local sourceAlways=0
|
local sourceAlways=0
|
||||||
local createEmpty=0
|
local createEmpty=0
|
||||||
|
local seqProfiles=0
|
||||||
for arg in "$@" ; do
|
for arg in "$@" ; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-t)
|
|
||||||
sourceAlways=1
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-e)
|
-e)
|
||||||
createEmpty=1
|
createEmpty=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-p)
|
||||||
|
seqProfiles=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-t)
|
||||||
|
sourceAlways=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
local configLoc="$SEQ_CONFIG_HOME/$1"
|
local configLoc="$SEQ_CONFIG_HOME/$1"
|
||||||
|
if [ $seqProfiles -ne 0 ] ; then
|
||||||
|
configLoc="$SEQ_CONFIG_HOME/$1/${SEQ_PROFILE_NAME}.cfg"
|
||||||
|
fi
|
||||||
|
local configDir="$(dirname $configLoc)"
|
||||||
local configTemplate="$2"
|
local configTemplate="$2"
|
||||||
|
|
||||||
# Create config subdir in users home
|
# Create config subdir in users home
|
||||||
if [ ! -e "$SEQ_CONFIG_HOME/" ] ; then
|
if [ ! -e "$configDir/" ] ; then
|
||||||
echo -n " [I] Creating $(realpath $SEQ_CONFIG_HOME)..."
|
echo -n " [I] Creating $(realpath $configDir)..."
|
||||||
exe mkdir -p "$SEQ_CONFIG_HOME" && echo "Ok" || echo "Nok"
|
exe mkdir -p "$configDir" && echo "Ok" || echo "Nok"
|
||||||
exe chmod 700 "$SEQ_CONFIG_HOME"
|
exe chmod 700 "$configDir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -s "$configLoc" ] ; then
|
if [ -s "$configLoc" ] ; then
|
||||||
@@ -343,7 +361,7 @@ initSeqConfig() {
|
|||||||
endReturn -o $? "Unable to use existing configuration: $configExists"
|
endReturn -o $? "Unable to use existing configuration: $configExists"
|
||||||
|
|
||||||
echoerr " [I] Using existing configuration: $configExists"
|
echoerr " [I] Using existing configuration: $configExists"
|
||||||
echoerr " (Moved to $SEQ_CONFIG_HOME)"
|
echoerr " (Moved to $configDir)"
|
||||||
. "$configLoc"
|
. "$configLoc"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@@ -358,7 +376,7 @@ initSeqConfig() {
|
|||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
echo " [W] Using seq configuration from template $configTemplate"
|
echo " [W] Using seq configuration from template $configTemplate"
|
||||||
echo " (Copied to $SEQ_CONFIG_HOME)"
|
echo " (Copied to $configDir)"
|
||||||
SEQ_CONFIG_FILE="$configLoc"
|
SEQ_CONFIG_FILE="$configLoc"
|
||||||
. "$configLoc"
|
. "$configLoc"
|
||||||
return 0
|
return 0
|
||||||
@@ -872,6 +890,11 @@ main() {
|
|||||||
helpApi
|
helpApi
|
||||||
exit 0;
|
exit 0;
|
||||||
;;
|
;;
|
||||||
|
--profile|-p) # seq profile name
|
||||||
|
shift
|
||||||
|
SEQ_PROFILE_NAME="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--quiet|-q|-qq) # detect if option quiet is available
|
--quiet|-q|-qq) # detect if option quiet is available
|
||||||
if [ "$1" == "-qq" ] ; then
|
if [ "$1" == "-qq" ] ; then
|
||||||
QUIET=2
|
QUIET=2
|
||||||
|
Reference in New Issue
Block a user