Skip to content

Commit

Permalink
get_database_param: return default value
Browse files Browse the repository at this point in the history
return the default value, if calling bareos-dhcheck fails.

Signed-off-by: Marco van Wieringen <marco.van.wieringen@bareos.com>
  • Loading branch information
joergsteffens authored and Marco van Wieringen committed Apr 3, 2014
1 parent dd7c345 commit 76be78a
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions scripts/bareos-config-lib.sh.in
Expand Up @@ -4,7 +4,7 @@ CONFIG_LIB=@scriptdir@/bareos-config-lib.sh
DIR_CFG=@sysconfdir@
CFG_DIR=${DIR_CFG}/bareos-dir.conf
DIR_SCRIPTS=@scriptdir@
DBCHECK="@sbindir@/bareos-dbcheck -B -c ${CFG_DIR}";
DBCHECK="@sbindir@/bareos-dbcheck -B -c ${CFG_DIR}"

SEC_GROUPS="tape disk"

Expand Down Expand Up @@ -246,12 +246,35 @@ get_database_param()
{
PARAM="$1"
DEFAULT="$2"
# DBCHECKS gets the database from the Director config file in a standard format,

DBCHECK_OUTPUT=`$DBCHECK`
rc=$?
if [ $rc != 0 ]; then
temp_log="/tmp/bareos-config.$$.log"
echo "executing: $DBCHECK" >> $temp_log
echo "${DBCHECK_OUTPUT}" >> $temp_log
echo "" >> $temp_log

# if default value is given, return it anyway
if [ -n "$DEFAULT" ]; then
warn "failed to get \"${PARAM}\" from config, using default value \"${DEFAULT}\", see $temp_log"
echo "$DEFAULT"
else
warn "failed to get \"${PARAM}\" from config, see $temp_log"
fi

return 1
fi

# DBCHECK gets the database parameter from the Director config file in a standard format,
# however, it writes "db_name" (like the environment variables)
# instead of "dbname" like in the config file.
# Replace "db_" by "db" to be compatible with the config file.
$DBCHECK | sed "s/^db_/db/" | sed -n "s/^${PARAM}=//p"
return $?
VALUE=`echo "$DBCHECK_OUTPUT" | sed "s/^db_/db/" | sed -n "s/^${PARAM}=//p"`

[ -z "$VALUE" ] && VALUE="$DEFAULT"
echo "$VALUE"
return $rc
}

get_database_driver()
Expand Down

0 comments on commit 76be78a

Please sign in to comment.