From 18d17bba9777605eee9f4f93d726603cc8d8647b Mon Sep 17 00:00:00 2001 From: Emil Breiner Date: Tue, 23 Mar 2021 16:51:55 +0100 Subject: [PATCH] creation of backupninja.conf.d to customize backupninja.conf parameters Introduction of a conf.d directory to safely override parameters from the backupninja.conf. Change-Id: Ie17c4b9891f6eb31cb19a62ca09f0839aea7967e Signed-Off-By: Emil Breiner --- etc/backupninja.conf.in | 3 +++ lib/tools.in | 32 +++++++++++++++++++++++++++++--- man/backupninja.conf.5 | 5 +++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/etc/backupninja.conf.in b/etc/backupninja.conf.in index f2366a3..351c207 100644 --- a/etc/backupninja.conf.in +++ b/etc/backupninja.conf.in @@ -75,6 +75,9 @@ usecolors = yes # default value for 'when' when = everyday at 01:00 +# conf.d for backupninja.conf overrides +config_d_directory = @CFGDIR@/backupninja.conf.d + # programs paths # SLAPCAT=/usr/sbin/slapcat # LDAPSEARCH=/usr/bin/ldapsearch diff --git a/lib/tools.in b/lib/tools.in index 55c2650..68aed4b 100644 --- a/lib/tools.in +++ b/lib/tools.in @@ -58,20 +58,46 @@ function version_ge() { function setfile() { CURRENT_CONF_FILE=$1 + # initialize empty and ommit a default value + CURRENT_CONF_D_DIR="" + getconf config_d_directory + # for consistency the config key is in lowercase + CURRENT_CONF_D_DIR=$config_d_directory } function setsection() { CURRENT_SECTION=$1 } -# # sets a global var with name equal to $1 # to the value of the configuration parameter $1 # $2 is the default. -# +# Begin by parsing the conf.d directory for configs. +# If the param is not found there fallback on the packaged backupninja.conf. +# if the param is still not found fallback to the default. function getconf() { + ret="" CURRENT_PARAM=$1 - ret=`@AWK@ -f $libdirectory/parseini S=$CURRENT_SECTION P=$CURRENT_PARAM $CURRENT_CONF_FILE` + + # check if conf.d directory exists + if [ -d "$CURRENT_CONF_D_DIR" ]; then + CURRENT_CONF_D_FILES=$CURRENT_CONF_D_DIR/*.conf + # iterate over all *.conf files in conf.d dir + for CURRENT_CONF_D_FILE in $CURRENT_CONF_D_FILES; do + # retrieve param from file + ret=`@AWK@ -f $libdirectory/parseini S=$CURRENT_SECTION P=$CURRENT_PARAM $CURRENT_CONF_D_FILE` + # exit the iteration if the param is set + if [ -n "$ret" ]; then + break + fi + done + fi + + # after exiting the loop caused by a not set param parse the packaged backupninja.conf + if [ "$ret" == "" ]; then + ret=$(@AWK@ -f $libdirectory/parseini S=$CURRENT_SECTION P=$CURRENT_PARAM $CURRENT_CONF_FILE) + fi + # if nothing is returned, set the default if [ "$ret" == "" -a "$2" != "" ]; then ret="$2" diff --git a/man/backupninja.conf.5 b/man/backupninja.conf.5 index ff6b055..ab19700 100644 --- a/man/backupninja.conf.5 +++ b/man/backupninja.conf.5 @@ -124,6 +124,11 @@ These values for 'when' are invalid: when = tuesday at 2 when = tues at 02 +.TP +.B config_d_directory +Directory for configuration overrides. Files dropped in this directory have +to end with .conf. Misspelled parameter break the parsing of this directory. + .TP .SH DEFAULTS