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