Introduce versioning to sequencer and seqs

Refactored sequencer option handling

More robust way to include sequencer.sh to seqs
This commit is contained in:
2019-04-05 15:32:53 +01:00
parent 09f082a83f
commit baef4e8d56
4 changed files with 87 additions and 27 deletions

View File

@@ -23,23 +23,24 @@ step_2() {
step_3_info() { echo "Step $1 header"; }
step_3() {
echo -e "Drei"
echo drei
}
step_10_info() { echo "Step $1 header"; }
step_10() {
echo -e "Zehn"
echo zehn
}
step_11_info() { echo "Step $1 header"; }
step_11() {
echo -e"Elf"
echo elf
}
#
## Path to local sequencer.sh script
# Sequence Revision
VERSION_SEQREV=1
. ./sequencer/sequencer.sh
# Workaround when called from different directory
# Not needed when path to sequencer is absolut
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
# Path to local sequencer.sh script
. ${DIR}/./sequencer/sequencer.sh

View File

@@ -112,5 +112,11 @@ step_20() {
chmod 644 /etc/gitea/app.ini
}
# Sequence Revision
VERSION_SEQREV=1
# Workaround when called from different directory
# Not needed when path to sequencer is absolut
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
# Path to sequencer
. ../sequencer/sequencer.sh
. ${DIR}/../sequencer/sequencer.sh

View File

@@ -132,5 +132,11 @@ step_42() {
chmod -R ug=rwX /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd
}
# Sequence Revision
VERSION_SEQREV=1
# Workaround when called from different directory
# Not needed when path to sequencer is absolut
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
# Path to sequencer
. ../sequencer/sequencer.sh
. ${DIR}/../sequencer/sequencer.sh

View File

@@ -4,25 +4,34 @@
## which uses the sequencer.sh to provide sequencial operations with or without
## user interaction (see seqTemplate.sh)
## Version information
VERSION_REV=1
VERSION_MAJOR=0
VERSION_MINOR=0
## Start of generic script part
QUIET=0
ERNO=0
MAX_STEP=255
TEMPLATE_NAME=seqTemplateExample.sh
VERSION_STRING="${VERSION_REV}.${VERSION_MAJOR}.${VERSION_MINOR}"
function helpSequencer() {
echo "Usage: ${0##*/} [Options] [Step Number(s)]"
echo
echo " [Options]"
echo " -q : Don't ask for permission to execute next step"
echo " If called without starting step number only this help is shown"
echo " [Options]"
echo " --help, -h : Display help"
echo " --quiet, -q : Don't ask for permission to execute steps"
echo " If called without starting step number, only this help is shown"
echo " --version,-v : Display version of sequencer and revision of sequence"
echo
echo " [Step Number(s) 1-${MAX_STEP}]"
echo " Single step number : starting point of process"
echo " Multiple step numbers : execute only given steps"
echo " execute only one step with using special step 0"
echo " ( e.g. only execute step 4: $0 4 0 )"
echo " [Step Number(s) 1-${MAX_STEP}]"
echo " Single step number : starting point of process"
echo " Multiple step numbers : execute only given steps"
echo " execute only one step with using special step 0"
echo " ( e.g. only execute step 4: $0 4 0 )"
}
# endCheckEmpty [VariableName] [DESCRIPTION]
@@ -217,22 +226,60 @@ function displayHelp() {
fi
}
# showVersion
function showVersion() {
echo "Sequencer ${VERSION_STRING}"
echo -n "Seq Revision "
if [ ! -z "${VERSION_SEQREV}" ] ; then
echo "${VERSION_SEQREV}"
else
echo "-"
fi
}
main() {
# detect if option quiet is available
if [ ! -z "$1" ] && [ $1 == "-q" ] ; then
QUIET=1
shift
local START=0
# option check
case "$1" in
--help|-h) # show only help
displayHelp
exit 0;
;;
--quiet|-q) # detect if option quiet is available
QUIET=1
shift
;;
--version|-v) # version request
showVersion
exit 0;
;;
"") # Empty -> show help
displayHelp
# Assume starting at one for interactive mode
START=1
;;
esac
# compatibility check of sequence
if [ ! -z $VERSION_SEQREV ] && [ $VERSION_SEQREV -gt $VERSION_REV ] ; then
echo "[ERROR] Unsupported sequence revision"
showVersion
exit 1
fi
# TODO exclude older versions if needed
if [ -z $VERSION_SEQREV ] ; then
echo -e "[WARNING] No sequence revision found. Trying anyway...\n";
fi
# display help
if [ -z "$1" ] ; then
displayHelp
START=1
# check for starting step
if [ ! -z "$1" ] ; then
START=$1
else
# End here on quiet mode and no step was given
if [ $QUIET -eq 1 ] ; then
exit 1;
fi
else
START=$1
fi
# check if more than one step is given and select execution mode