Skip to content

Commit

Permalink
handle unset parameter
Browse files Browse the repository at this point in the history
some scripts (eg. package postinstall script) include bareos-config-lib.sh with settings,
that exit if a variable is undefined.
To prevent problems, function parameter are now used as "${1-}", so that they are never undefined.
Also fixes a bug, when using a database password that contains "/".
"/" is now a allowed character, but "#" is forbidden.

Signed-off-by: Marco van Wieringen <marco.van.wieringen@bareos.com>
  • Loading branch information
joergsteffens authored and Marco van Wieringen committed Apr 26, 2014
1 parent ab2a179 commit 866c1c2
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions scripts/bareos-config-lib.sh.in
Expand Up @@ -36,7 +36,7 @@ os_type=`uname -s`

is_function()
{
func=$1
func=${1-}
test "$func" && type "$func" > /dev/null 2>&1
return $?
}
Expand Down Expand Up @@ -119,7 +119,7 @@ get_database_ddl_dir()

get_database_utility_path()
{
db_type="$1"
db_type="${1-}"

case ${db_type} in
sqlite3)
Expand Down Expand Up @@ -217,15 +217,15 @@ get_config_param()
#

# configuration file
CFG_FILE="$1"
CFG_FILE="${1-}"
# section, currently ignored
SECTION="$2"
SECTION="${2-}"
# name of the section, currently ignored
NAME="$3"
NAME="${3-}"
# parameter to get from config file
PARAM="$4"
PARAM="${4-}"
# default value, if parameter is not found
DEFAULT="$5"
DEFAULT="${5-}"

if ! [ -r "${CFG_FILE}" ]; then
warn "failed to get parameter ${SECTION} ${NAME} ${PARAM}: can't read ${CFG_FILE}"
Expand All @@ -244,8 +244,8 @@ get_config_param()

get_database_param()
{
PARAM="$1"
DEFAULT="$2"
PARAM="${1-}"
DEFAULT="${2-}"

DBCHECK_OUTPUT=`$DBCHECK`
rc=$?
Expand Down Expand Up @@ -279,28 +279,28 @@ get_database_param()

get_database_driver()
{
DEFAULT="$1"
DEFAULT="${1-}"
get_database_param "dbdriver" "$DEFAULT" | grep -v "XXX_REPLACE_WITH_DATABASE_DRIVER_XXX"
return $?
}

get_database_name()
{
DEFAULT="$1"
DEFAULT="${1-}"
get_database_param "dbname" "$DEFAULT"
return $?
}

get_database_user()
{
DEFAULT="$1"
DEFAULT="${1-}"
get_database_param "dbuser" "$DEFAULT"
return $?
}

get_database_password()
{
DEFAULT="$1"
DEFAULT="${1-}"
get_database_param "dbpassword" "$DEFAULT"
return $?
}
Expand Down Expand Up @@ -337,7 +337,7 @@ initialize_database_driver()

is_template_sql_file()
{
input_file=$1
input_file=${1-}

if [ -z "${input_file}" ]; then
return 1
Expand All @@ -357,7 +357,7 @@ get_translated_sql_file()
# replaces variables in a SQL DDL file
# and returns the result as stdout.

input_file=$1
input_file=${1-}

if [ -z "${input_file}" ]; then
return 1
Expand All @@ -374,6 +374,11 @@ get_translated_sql_file()
db_password="${db_password-`get_database_password @db_password@`}"
db_version=`get_database_version`

if echo "$db_password" | grep -q '#'; then
error "database passwords containing # are not supported."
return 3
fi

case ${db_type} in
sqlite3)
;;
Expand All @@ -396,10 +401,10 @@ get_translated_sql_file()
;;
esac

sed -e "s/@DB_NAME@/${db_name}/" \
-e "s/@DB_USER@/${db_user}/" \
-e "s/@DB_PASS@/${pass}/" \
-e "s/@DB_VERSION@/${db_version}/" \
sed -e "s#@DB_NAME@#${db_name}#" \
-e "s#@DB_USER@#${db_user}#" \
-e "s#@DB_PASS@#${pass}#" \
-e "s#@DB_VERSION@#${db_version}#" \
${input_file}
}

Expand All @@ -412,8 +417,8 @@ get_database_grant_priviliges()

#db_name="$1"
db_type="${1:-${db_type:-`get_database_driver_default`}}"
db_user="$2"
db_password="$3"
db_user="${2-}"
db_password="${3-}"
case "$4" in
"")
# full access
Expand Down

0 comments on commit 866c1c2

Please sign in to comment.