From 0f206660a640ec7397123ff5390f328c7fa70f5c Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Tue, 9 Apr 2019 11:01:09 +0100 Subject: [PATCH] New common function to create config files savely --- sequencer/sequencer.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/sequencer/sequencer.sh b/sequencer/sequencer.sh index badc067..b13f329 100755 --- a/sequencer/sequencer.sh +++ b/sequencer/sequencer.sh @@ -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 +# 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] # -q: don't stop and don't report step functions which cannot be found # execute given step_ function