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_REV=3
|
||||
VERSION_REV=4
|
||||
VERSION_MAJOR=0
|
||||
VERSION_MINOR=0
|
||||
|
||||
@@ -108,39 +108,57 @@ addConf() {
|
||||
-a) # append to existing file
|
||||
confMode="-a"
|
||||
;;
|
||||
*) # default
|
||||
echo "Parameter 1 (-a|-c) missing for addConf()"
|
||||
-s) # skip if CONFIGFILE exists
|
||||
confMode="-s"
|
||||
;;
|
||||
-m) # only add content to missing conf and warn user
|
||||
confMode="-m"
|
||||
;;
|
||||
*) # default
|
||||
echo "Parameter 1 (-a|-c|-m|-s) missing for addConf()"
|
||||
exit 0;
|
||||
;;
|
||||
esac
|
||||
|
||||
echo -n "Writing $3 ... "
|
||||
if [ "$DRY" -ne 0 ] ; then
|
||||
echo "dry-run"
|
||||
echo "-- Writing $3...dry-run"
|
||||
return 0;
|
||||
fi
|
||||
echo -n "Writing $3..."
|
||||
|
||||
# try writing config directly
|
||||
if [ ! -f "$3" ] ; then
|
||||
if [ $confMode == "-c" ] ; then
|
||||
echo "$2" > "$3"
|
||||
else
|
||||
echo "$2" >> "$3"
|
||||
if [ $confMode != "-m" ] ; then
|
||||
# try writing config directly
|
||||
if [ ! -f "$3" ] ; then
|
||||
case "$confMode" in
|
||||
-c|-s)
|
||||
echo "$2" > "$3"
|
||||
;;
|
||||
-a)
|
||||
echo "$2" >> "$3"
|
||||
;;
|
||||
esac
|
||||
echo "ok"
|
||||
return 0
|
||||
fi
|
||||
echo "ok"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# try backup existing config
|
||||
if [ ! -f "$3".bck ] ; then
|
||||
cp -ar "$3" "$3".bck
|
||||
if [ $confMode == "-c" ] ; then
|
||||
echo "$2" > "$3"
|
||||
else
|
||||
echo "$2" >> "$3"
|
||||
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
|
||||
if [ ! -f "$3".bck ] ; then
|
||||
cp -ar "$3" "$3".bck
|
||||
if [ $confMode == "-c" ] ; then
|
||||
echo "$2" > "$3"
|
||||
else
|
||||
echo "$2" >> "$3"
|
||||
fi
|
||||
echo -e "ok \n[WARN] Existing config saved to ${3}.bck"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
echo "[WARN] Existing config saved to ${3}.bck"
|
||||
return 0
|
||||
else
|
||||
echo "nok"
|
||||
fi
|
||||
|
||||
# add configuration to missingConf file
|
||||
@@ -153,7 +171,7 @@ addConf() {
|
||||
echo "$2" >> "$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
|
||||
}
|
||||
|
||||
@@ -230,7 +248,7 @@ continous() {
|
||||
if [[ $step == 0 ]] ; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
||||
for ((i=$step; i<=${MAX_STEP}; i++)); do
|
||||
execute -q $i
|
||||
local res=$?
|
||||
@@ -367,7 +385,7 @@ showVersion() {
|
||||
exe() {
|
||||
local arr=("$@")
|
||||
if [ $DRY -ne 0 ] ; then
|
||||
echo -e "\n-- ${arr[@]}"
|
||||
echo "-- ${arr[@]}"
|
||||
elif [ $VERBOSE -eq 1 ] ; then
|
||||
(set -x; "${arr[@]}")
|
||||
else
|
||||
@@ -378,9 +396,12 @@ exe() {
|
||||
# Handle dry run and verbose output for commands containing pipe and/or redirects
|
||||
# exep <COMMAND TO RUN AS STRING>
|
||||
exep() {
|
||||
if [ $DRY -ne 0 ] || [ $VERBOSE -eq 1 ] ; then
|
||||
echo -e "\n-- $1"
|
||||
if [ $DRY -ne 0 ] ; then
|
||||
echo "-- $1"
|
||||
elif [ $VERBOSE -eq 1 ] ; then
|
||||
echo "++ $1"
|
||||
fi
|
||||
|
||||
if [ $DRY -eq 0 ] ; then
|
||||
bash -c "$1"
|
||||
fi
|
||||
@@ -449,7 +470,7 @@ main() {
|
||||
exit 1;
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [ $DRY -ne 0 ] ; then
|
||||
echo
|
||||
echo "[WARN] Dry run active."
|
||||
|
Reference in New Issue
Block a user