refcodes-batch.1.0.2.source-code.validate-db-template-config.job Maven / Gradle / Ivy
#!/bin/bash
# -----------------------------------------------------------------------------
# Shows the according config:
# -----------------------------------------------------------------------------
function showDbTemplateConfiguration {
echo "The switch \"-j $JOB\" validates all \"DB_TEMPLATE\" " >&2
echo "specific settings in the CONFIG file. Supported properties in the CONFIG file are:" >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
echo "DB_TEMPLATE = (set 'y' if a DB template is used/configured, else 'n') " >&2
echo "DB_TEMPLATE_NAME = (the DB template for the given site) " >&2
echo "DB_TEMPLATE_USER_NAME = (the DB template user for accessing the DB for the given site)" >&2
echo "DB_TEMPLATE_USER_PASSWORD = (the password of the DB template user) " >&2
echo "DB_TEMPLATE_HOSTNAME = (the host on which the DB template resides) " >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
if [[ $# -eq 1 ]] ; then
showError "$1"
fi
}
# ------------------------------------------------------------------------------
# Missing property:
# $1: The missing property's name (without prepended "$").
# ------------------------------------------------------------------------------
function exitOnMissingDbTemplateProperty {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingDbTemplateProperty\" expects an argument !!!" >&2
exit $EXIT_BUG
fi
# $VALUE is the value of the variable passed as $1:
eval "VALUE=\$$1"
if [ -z "$VALUE" ] ; then
showDbTemplateConfiguration "Missing or empty property \"$1\" !!!"
exit $EXIT_ERROR
fi
}
# ------------------------------------------------------------------------------
# File defined in $CONFIG_FILE non exisiting:
# $1 The property name (without prepended "$") with the (non exisitent) path.
# ------------------------------------------------------------------------------
function exitOnMissingDbTemplatePropertyPath {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingDbTemplatePropertyPath\" expects an argument !!!" >&2
exit $EXIT_BUG
fi
# $VALUE is the value of the variable passed as $1:
eval "VALUE=\$$1"
if [ ! -e "$VALUE" ] && [ ! -L "$VALUE" ] ; then
showDbTemplateConfiguration "Path or file \"$VALUE\" not found defined in property \"$1\" of the \"$CONFIG\" config !!!"
exit $EXIT_ERROR
fi
}
# -----------------------------------------------------------------------------
if [[ $VERBOSE = y ]] ; then
echo "\"DB_TEMPLATE\" configuration validation is activated ..." >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $HELP = y ]] ; then
showDbTemplateConfiguration
fi
if [[ $HELP = n ]] ; then
if [[ $VERBOSE = y ]] ; then
showProperty "DB_TEMPLATE"
showProperty "DB_TEMPLATE_NAME"
showProperty "DB_TEMPLATE_USER_NAME"
showPasswordProperty "DB_TEMPLATE_USER_PASSWORD"
showProperty "DB_TEMPLATE_HOSTNAME"
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $DB_TEMPLATE = y ]] ; then
exitOnMissingDbTemplateProperty "DB_TEMPLATE_NAME"
exitOnMissingDbTemplateProperty "DB_TEMPLATE_USER_NAME"
exitOnMissingDbTemplateProperty "DB_TEMPLATE_USER_PASSWORD"
exitOnMissingDbTemplateProperty "DB_TEMPLATE_HOSTNAME"
fi
showSuccess "\"DB_TEMPLATE\" configuration for \"$CONFIG\" validated !"
fi