New common function to create config files savely

This commit is contained in:
2019-04-09 11:01:09 +01:00
parent 60ee5d776f
commit 0f206660a6

View File

@@ -17,6 +17,7 @@ ERNO=0
MAX_STEP=255 MAX_STEP=255
ALIAS= ALIAS=
TEMPLATE_NAME=seqTemplateExample.sh TEMPLATE_NAME=seqTemplateExample.sh
MISSING_CONF=missingConf.h
VERSION_STRING="${VERSION_REV}.${VERSION_MAJOR}.${VERSION_MINOR}" VERSION_STRING="${VERSION_REV}.${VERSION_MAJOR}.${VERSION_MINOR}"
helpSequencer() { helpSequencer() {
@@ -88,6 +89,41 @@ endReturn() {
fi fi
} }
# addConf <CONFIGTEXT> <CONFIGFILE>
# trying to write a file
# if exists, one attempt is made to create bck file of it
# if all fails, a log file is created with the conflicts to be resolved by the user
addConf() {
echo -n "Writing $2 ... "
# try writing config directly
if [ ! -f "$2" ] ; then
echo "$1" > "$2"
echo "ok"
return 0
fi
# try backup existing config
if [ ! -f "$2".bck ] ; then
cp -ar "$2" "$2".bck
echo "$1" > "$2"
echo "[WARN] Existing config saved to ${2}.bck"
return 0
fi
# add configuration to missingConf file
if [ "$missingDate" = "" ] ; then
missingDate=set
echo -n "### " >> "$MISSING_CONF"
date >> "$MISSING_CONF"
fi
echo "#--- $2 ---" >> "$MISSING_CONF"
echo "$1" >> "$MISSING_CONF"
echo >> "$MISSING_CONF"
echo "[WARN] Check $(realpath "$missingConf") for configuration conflicts ($2)"
return 1
}
# execute [-q] <Step Number> # execute [-q] <Step Number>
# -q: don't stop and don't report step functions which cannot be found # -q: don't stop and don't report step functions which cannot be found
# execute given step_<Step Number> function # execute given step_<Step Number> function