Bump to revision 3

addConf with mandatory paramter; suppots appending
This commit is contained in:
2019-05-17 11:59:51 +01:00
parent 34966ddf79
commit ab10ef6504
11 changed files with 103 additions and 53 deletions

View File

@@ -6,7 +6,7 @@
## Version information
VERSION_REV=2
VERSION_REV=3
VERSION_MAJOR=0
VERSION_MINOR=0
@@ -95,29 +95,51 @@ endReturn() {
fi
}
# addConf <CONFIGTEXT> <CONFIGFILE>
# addConf <CONF_MODE> <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 ... "
local confMode=""
case "$1" in
-c) # create a new file
confMode="-c"
;;
-a) # append to existing file
confMode="-a"
;;
*) # default
echo "Parameter 1 (-a|-c) missing for addConf()"
exit 0;
;;
esac
echo -n "Writing $3 ... "
if [ "$DRY" -ne 0 ] ; then
echo "dry-run"
return 0;
fi
# try writing config directly
if [ ! -f "$2" ] ; then
echo "$1" > "$2"
if [ ! -f "$3" ] ; then
if [ $confMode == "-c" ] ; then
echo "$2" > "$3"
else
echo "$2" >> "$3"
fi
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"
if [ ! -f "$3".bck ] ; then
cp -ar "$3" "$3".bck
if [ $confMode == "-c" ] ; then
echo "$2" > "$3"
else
echo "$2" >> "$3"
fi
echo "[WARN] Existing config saved to ${3}.bck"
return 0
fi
@@ -127,11 +149,11 @@ addConf() {
echo -n "### " >> "$MISSING_CONF"
date >> "$MISSING_CONF"
fi
echo "#--- $2 ---" >> "$MISSING_CONF"
echo "$1" >> "$MISSING_CONF"
echo "#--- $3 ---" >> "$MISSING_CONF"
echo "$2" >> "$MISSING_CONF"
echo >> "$MISSING_CONF"
echo "[WARN] Check $(realpath "$missingConf") for configuration conflicts ($2)"
echo "[WARN] Check $(realpath "$missingConf") for configuration conflicts ($3)"
return 1
}
@@ -249,7 +271,7 @@ createTemplate() {
echo " echo \"Doing something...\"" >> $TEMPLATE_NAME
echo "}" >> $TEMPLATE_NAME
echo >> $TEMPLATE_NAME
echo "VERSION_SEQREV=2" >> $TEMPLATE_NAME
echo "VERSION_SEQREV=${VERSION_REV}" >> $TEMPLATE_NAME
echo ". $0" >> $TEMPLATE_NAME
chmod +x $TEMPLATE_NAME
@@ -396,7 +418,12 @@ main() {
showVersion
exit 1
fi
# TODO exclude older versions if needed
# exclude older versions if needed
if [ ! -z $VERSION_SEQREV ] && [ $VERSION_SEQREV -lt 3 ] ; then
echo "[ERROR] Unsupported sequence revision (addConf)"
showVersion
exit 1
fi
if [ -z $VERSION_SEQREV ] ; then
echo -e "[WARNING] No sequence revision found. Trying anyway...\n";
fi