New paramter for addConf (skip backup if exist; only add to missing conf)
Various output text corrections (context dry run and verbose)
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
## Version information
|
## Version information
|
||||||
|
|
||||||
VERSION_REV=3
|
VERSION_REV=4
|
||||||
VERSION_MAJOR=0
|
VERSION_MAJOR=0
|
||||||
VERSION_MINOR=0
|
VERSION_MINOR=0
|
||||||
|
|
||||||
@@ -108,29 +108,43 @@ addConf() {
|
|||||||
-a) # append to existing file
|
-a) # append to existing file
|
||||||
confMode="-a"
|
confMode="-a"
|
||||||
;;
|
;;
|
||||||
|
-s) # skip if CONFIGFILE exists
|
||||||
|
confMode="-s"
|
||||||
|
;;
|
||||||
|
-m) # only add content to missing conf and warn user
|
||||||
|
confMode="-m"
|
||||||
|
;;
|
||||||
*) # default
|
*) # default
|
||||||
echo "Parameter 1 (-a|-c) missing for addConf()"
|
echo "Parameter 1 (-a|-c|-m|-s) missing for addConf()"
|
||||||
exit 0;
|
exit 0;
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
echo -n "Writing $3 ... "
|
|
||||||
if [ "$DRY" -ne 0 ] ; then
|
if [ "$DRY" -ne 0 ] ; then
|
||||||
echo "dry-run"
|
echo "-- Writing $3...dry-run"
|
||||||
return 0;
|
return 0;
|
||||||
fi
|
fi
|
||||||
|
echo -n "Writing $3..."
|
||||||
|
|
||||||
|
if [ $confMode != "-m" ] ; then
|
||||||
# try writing config directly
|
# try writing config directly
|
||||||
if [ ! -f "$3" ] ; then
|
if [ ! -f "$3" ] ; then
|
||||||
if [ $confMode == "-c" ] ; then
|
case "$confMode" in
|
||||||
|
-c|-s)
|
||||||
echo "$2" > "$3"
|
echo "$2" > "$3"
|
||||||
else
|
;;
|
||||||
|
-a)
|
||||||
echo "$2" >> "$3"
|
echo "$2" >> "$3"
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
echo "ok"
|
echo "ok"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $confMode == "-s" ] ; then
|
||||||
|
# if skip is selected, don't try to backup but add confilict entry
|
||||||
|
echo "skipping (exists)"
|
||||||
|
else
|
||||||
# try backup existing config
|
# try backup existing config
|
||||||
if [ ! -f "$3".bck ] ; then
|
if [ ! -f "$3".bck ] ; then
|
||||||
cp -ar "$3" "$3".bck
|
cp -ar "$3" "$3".bck
|
||||||
@@ -139,9 +153,13 @@ addConf() {
|
|||||||
else
|
else
|
||||||
echo "$2" >> "$3"
|
echo "$2" >> "$3"
|
||||||
fi
|
fi
|
||||||
echo "[WARN] Existing config saved to ${3}.bck"
|
echo -e "ok \n[WARN] Existing config saved to ${3}.bck"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "nok"
|
||||||
|
fi
|
||||||
|
|
||||||
# add configuration to missingConf file
|
# add configuration to missingConf file
|
||||||
if [ "$missingDate" = "" ] ; then
|
if [ "$missingDate" = "" ] ; then
|
||||||
@@ -153,7 +171,7 @@ addConf() {
|
|||||||
echo "$2" >> "$MISSING_CONF"
|
echo "$2" >> "$MISSING_CONF"
|
||||||
echo >> "$MISSING_CONF"
|
echo >> "$MISSING_CONF"
|
||||||
|
|
||||||
echo "[WARN] Check $(realpath "$missingConf") for configuration conflicts ($3)"
|
echo "[WARN] Check $(realpath "$MISSING_CONF") for configuration conflicts ($3)"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,7 +385,7 @@ showVersion() {
|
|||||||
exe() {
|
exe() {
|
||||||
local arr=("$@")
|
local arr=("$@")
|
||||||
if [ $DRY -ne 0 ] ; then
|
if [ $DRY -ne 0 ] ; then
|
||||||
echo -e "\n-- ${arr[@]}"
|
echo "-- ${arr[@]}"
|
||||||
elif [ $VERBOSE -eq 1 ] ; then
|
elif [ $VERBOSE -eq 1 ] ; then
|
||||||
(set -x; "${arr[@]}")
|
(set -x; "${arr[@]}")
|
||||||
else
|
else
|
||||||
@@ -378,9 +396,12 @@ exe() {
|
|||||||
# Handle dry run and verbose output for commands containing pipe and/or redirects
|
# Handle dry run and verbose output for commands containing pipe and/or redirects
|
||||||
# exep <COMMAND TO RUN AS STRING>
|
# exep <COMMAND TO RUN AS STRING>
|
||||||
exep() {
|
exep() {
|
||||||
if [ $DRY -ne 0 ] || [ $VERBOSE -eq 1 ] ; then
|
if [ $DRY -ne 0 ] ; then
|
||||||
echo -e "\n-- $1"
|
echo "-- $1"
|
||||||
|
elif [ $VERBOSE -eq 1 ] ; then
|
||||||
|
echo "++ $1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $DRY -eq 0 ] ; then
|
if [ $DRY -eq 0 ] ; then
|
||||||
bash -c "$1"
|
bash -c "$1"
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user