New function step to execute other steps also by alias
Possibilty to skip a step, if run without quiet option WIP build-in function documentation
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
## Version information
|
## Version information
|
||||||
|
|
||||||
VERSION_REV=6
|
VERSION_REV=7
|
||||||
VERSION_MAJOR=0
|
VERSION_MAJOR=0
|
||||||
VERSION_MINOR=0
|
VERSION_MINOR=0
|
||||||
|
|
||||||
@@ -27,14 +27,16 @@ helpSequencer() {
|
|||||||
echo "Usage: ${0##*/} [OPTIONS] [STEP NUMBER(s) or ALIAS] [STEP ARGUMENTS]"
|
echo "Usage: ${0##*/} [OPTIONS] [STEP NUMBER(s) or ALIAS] [STEP ARGUMENTS]"
|
||||||
echo
|
echo
|
||||||
echo " [OPTIONS]"
|
echo " [OPTIONS]"
|
||||||
echo " --dry-run, -d : Only print to console what would be done"
|
echo " --dry-run, -d : Only print to console what would be done"
|
||||||
echo " ! Attention - Sequence must support this"
|
echo " ! Attention - Sequence must support this"
|
||||||
echo " --help, -h : Display help"
|
echo " --help, -h : Display help"
|
||||||
echo " --quiet, -q : Don't ask for permission to execute steps"
|
echo " --helpapi, -ha : Display help about build-in supporting functions"
|
||||||
echo " If called without starting step number, only this help is shown"
|
echo " (e.g. exe,addconf,echerr,...)"
|
||||||
echo " --verbose, -v : Verbose output (use exe() function to call shell commands in seqs)"
|
echo " --quiet, -q : Don't ask for permission to execute steps"
|
||||||
echo " ( e.g.: exe apt update )"
|
echo " If called without starting step number, only this help is shown"
|
||||||
echo " --version : Display version of sequencer and revision of sequence"
|
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
|
||||||
echo " [STEP NUMBER\"(s)\" 1-${MAX_STEP} or ALIAS]"
|
echo " [STEP NUMBER\"(s)\" 1-${MAX_STEP} or ALIAS]"
|
||||||
echo " No STEP or ALIAS : assume 1 as starting point"
|
echo " No STEP or ALIAS : assume 1 as starting point"
|
||||||
@@ -49,10 +51,36 @@ helpSequencer() {
|
|||||||
echo " \$1 is always the step number"
|
echo " \$1 is always the step number"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
helpApi() {
|
||||||
|
echo "sequencer.sh build-in functions"
|
||||||
|
echo
|
||||||
|
echo " echoerr <...>"
|
||||||
|
echo " echo output to stderr"
|
||||||
|
echo " <...> - all parameter are forwarded to echo"
|
||||||
|
echo
|
||||||
|
echo " endCheckEmpty <Variable Name> [Description]"
|
||||||
|
echo " exit 666 if variable is empty"
|
||||||
|
echo " <Variable Name> - Name used within eval"
|
||||||
|
echo " [Description] - Additional text for error output"
|
||||||
|
echo
|
||||||
|
echo " saveReturn [Error Code]"
|
||||||
|
echo " Save error code if it is != 0 for later use with endReturn"
|
||||||
|
echo
|
||||||
|
echo " endReturn [-f] [Message]"
|
||||||
|
echo " Notifys user that there was an error (previously saved by saveReturn)"
|
||||||
|
echo " and asks to continue or end sequence. Always exits with saved error code."
|
||||||
|
echo " -f : force exit with the last saved error code without user input"
|
||||||
|
echo
|
||||||
|
echo " step <Step number or alias>"
|
||||||
|
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 to stderr
|
# Echo to stderr
|
||||||
echoerr() { >&2 echo "$@"; }
|
echoerr() { >&2 echo "$@"; }
|
||||||
|
|
||||||
# endCheckEmpty [VariableName] [DESCRIPTION]
|
# endCheckEmpty <VariableName> [DESCRIPTION]
|
||||||
# DESCRIPTION : Optional text for error
|
# DESCRIPTION : Optional text for error
|
||||||
endCheckEmpty() {
|
endCheckEmpty() {
|
||||||
local errorText=$1
|
local errorText=$1
|
||||||
@@ -260,11 +288,14 @@ execute() {
|
|||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
if [ $QUIET -ne 1 ] ; then
|
if [ $QUIET -ne 1 ] ; then
|
||||||
read -p "Start: y/[n]? " answer
|
read -p "Start: (y)es/[n]o/(s)kip? " answer
|
||||||
case $answer in
|
case $answer in
|
||||||
[yY])
|
[yY])
|
||||||
step_$1 $1 $STEP_ARGS
|
step_$1 $1 $STEP_ARGS
|
||||||
;;
|
;;
|
||||||
|
[sS]) # skip step
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo " [I] Stopping sequence at step $1"
|
echo " [I] Stopping sequence at step $1"
|
||||||
exit 1;
|
exit 1;
|
||||||
@@ -302,6 +333,26 @@ checkStep() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# step <Step Number of Alias>
|
||||||
|
# execute given step
|
||||||
|
step() {
|
||||||
|
local stepNo=0
|
||||||
|
|
||||||
|
checkStep "$1"
|
||||||
|
stepNo=$?
|
||||||
|
if [ "$stepNo" == "0" ] ; then
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
existsFunction step_${stepNo}
|
||||||
|
if [ $? -eq 0 ] ; then
|
||||||
|
eval 'step_'"$stepNo"
|
||||||
|
else
|
||||||
|
echoerr " [E] Invalid step: $stepNo"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# continous <Starting Step Number>
|
# continous <Starting Step Number>
|
||||||
# (max $MAX_STEP)
|
# (max $MAX_STEP)
|
||||||
# execute sequence continously from given starting step
|
# execute sequence continously from given starting step
|
||||||
@@ -499,6 +550,10 @@ main() {
|
|||||||
displayHelp
|
displayHelp
|
||||||
exit 0;
|
exit 0;
|
||||||
;;
|
;;
|
||||||
|
--helpapi|-ha) #show build-in functions
|
||||||
|
helpApi
|
||||||
|
exit 0;
|
||||||
|
;;
|
||||||
--quiet|-q) # detect if option quiet is available
|
--quiet|-q) # detect if option quiet is available
|
||||||
QUIET=1
|
QUIET=1
|
||||||
shift
|
shift
|
||||||
|
Reference in New Issue
Block a user