Fix crash when invalid alias strings contain '.' are processed

Help and commandline informational output
This commit is contained in:
2019-11-20 15:22:02 +00:00
parent 046f80f865
commit e5678c9692

View File

@@ -37,7 +37,8 @@ helpSequencer() {
echo " --version : Display version of sequencer and revision of sequence"
echo
echo " [STEP NUMBER\"(s)\" 1-${MAX_STEP} or ALIAS]"
echo " Single STEP or ALIAS : starting point of process"
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 " execute only one step with using special step 0"
echo " ( e.g. only execute step 4: $0 \"4 0\" )"
@@ -58,7 +59,7 @@ endCheckEmpty() {
errorText=$2
fi
if [ -z $ref ] ; then
echo -e "[Error] $errorText must not be empty.\nAborting installation."
echo -e " [E] $errorText must not be empty.\nAborting installation."
exit 666
fi
}
@@ -80,13 +81,13 @@ saveReturn() {
endReturn() {
if [[ ( $ERNO -ne 0 && $QUIET -ne 0 ) || ( $ERNO -ne 0 && ! -z $1 && $1 == "-f" ) ]] ; then
echo
echo -e "[Error] Return value $ERNO detected.\nAborting installation."
echo -e " [E] Return value $ERNO detected.\nAborting installation."
exit $ERNO
fi
if [ $ERNO -ne 0 ] ; then
echo
echo "[Error] Return value $ERNO detected."
read -p "End installation: y(default)/n? " answer
echo " [E] Return value $ERNO detected."
read -p "End installation: [y]/n? " answer
case $answer in
[nN])
echo
@@ -127,10 +128,10 @@ addConf() {
esac
if [ "$DRY" -ne 0 ] ; then
echo "-- Writing $3...dry-run"
echo " [I] Writing $3...dry-run"
return 0;
fi
echo -n "Writing $3..."
echo -n " [I] Writing $3..."
if [ $confMode != "-m" ] ; then
# try writing config directly
@@ -160,7 +161,7 @@ addConf() {
else
echo "$2" >> "$3"
fi
echo -e "ok \n[WARN] Existing config saved to ${addConfBackup}"
echo -e "ok \n [W] Existing config saved to ${addConfBackup}"
return 0
else
echo "nok (backup exists)"
@@ -180,7 +181,7 @@ addConf() {
echo "$2" >> "$MISSING_CONF"
echo >> "$MISSING_CONF"
echo "[WARN] Check $(realpath "$MISSING_CONF") for configuration conflicts ($3)"
echo " [W] Check $(realpath "$MISSING_CONF") for configuration conflicts ($3)"
return 1
}
@@ -208,7 +209,7 @@ execute() {
return $NOTFOUND
fi
echo -en "\n[STEP $1] "
echo -en "\n [STEP $1] "
existsFunction step_${1}_info
if [ $? -eq 0 ] ; then
step_${1}_info $1
@@ -217,7 +218,7 @@ execute() {
echo
fi
if [ $QUIET -ne 1 ] ; then
read -p "Start: y/n(default)? " answer
read -p "Start: y/[n]? " answer
case $answer in
[yY])
step_$1 $1 "$STEP_ARGS"
@@ -237,16 +238,26 @@ execute() {
# Check sanitiy of step number or
# Check if alias exists
checkStep() {
if (( $1 < 1 || $1 > $MAX_STEP )) ; then
eval 'local ref=$alias_'$1
if [ -z $ref ] || [ "$ref" == "$1" ] ; then
local rex='^[0-9]+$'
local ref=""
# Check if string is a number or alias
if ! [[ "$1" =~ $rex ]] ; then
eval 'ref=$alias_'"$1"
# Catch special character after eval
if ! [[ "$ref" =~ $rex ]] ; then
echo " [E] Invalid step: $1"
ref=0
fi
else
ref=$1
fi
if (( $ref < 1 || $ref > $MAX_STEP )) ; then
return 0
else
return $ref
fi
else
return $1
fi
}
# continous <Starting Step Number>
@@ -255,7 +266,7 @@ checkStep() {
continous() {
local step=0
checkStep $1
checkStep "$1"
step=$?
if [[ $step == 0 ]] ; then
return 1
@@ -277,7 +288,7 @@ selection() {
local step=0
local array=("$@")
for i in ${array[@]} ; do
checkStep $i
checkStep "$i"
step=$?
# stop on step 0
if [ $step -eq 0 ] ; then
@@ -348,7 +359,7 @@ displayHelp() {
if [ $stepsFound -eq 0 ] ; then
echo -e "\n It seems ${0##*/} was called directly."
echo -e " Please create a sequence script first.\n"
read -p " Create a template now? y/n(default)? " answer
read -p " Create a template now? y/[n]? " answer
case $answer in
[yY])
createTemplate
@@ -475,18 +486,18 @@ main() {
# compatibility check of sequence
if [ ! -z $VERSION_SEQREV ] && [ $VERSION_SEQREV -gt $VERSION_REV ] ; then
echo "[ERROR] Unsupported sequence revision"
echo " [E] Unsupported sequence revision"
showVersion
exit 1
fi
# exclude older versions if needed
if [ ! -z $VERSION_SEQREV ] && [ $VERSION_SEQREV -lt 3 ] ; then
echo "[ERROR] Unsupported sequence revision (addConf)"
echo " [E] Unsupported sequence revision (addConf)"
showVersion
exit 1
fi
if [ -z $VERSION_SEQREV ] ; then
echo -e "[WARNING] No sequence revision found. Trying anyway...\n";
echo -e " [W] No sequence revision found. Trying anyway...\n";
fi
# check for starting step
@@ -499,7 +510,7 @@ main() {
if [ $DRY -ne 0 ] ; then
echo
echo "[WARN] Dry run active."
echo " [W] Dry run active."
echo " Printed commands may not be accurate (e.g. quotation incorrect)"
echo " Sequence may ignore dry run"
read -p "Press enter to continue or Ctrl + c to abort"