New common function to create config files savely
This commit is contained in:
@@ -17,6 +17,7 @@ ERNO=0
|
||||
MAX_STEP=255
|
||||
ALIAS=
|
||||
TEMPLATE_NAME=seqTemplateExample.sh
|
||||
MISSING_CONF=missingConf.h
|
||||
VERSION_STRING="${VERSION_REV}.${VERSION_MAJOR}.${VERSION_MINOR}"
|
||||
|
||||
helpSequencer() {
|
||||
@@ -88,6 +89,41 @@ endReturn() {
|
||||
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>
|
||||
# -q: don't stop and don't report step functions which cannot be found
|
||||
# execute given step_<Step Number> function
|
||||
|
Reference in New Issue
Block a user