refcodes-batch.1.0.2.source-code.validate-db-config.job Maven / Gradle / Ivy
#!/bin/bash
# -----------------------------------------------------------------------------
# Shows the according config:
# -----------------------------------------------------------------------------
function showDbConfiguration {
echo "The switch \"-j $JOB\" validates all \"DB\" specific " >&2
echo "settings in the CONFIG file. Supported properties in the CONFIG file are: " >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
echo "DB = (set 'y' if a DB is used/configured, else 'n') " >&2
echo "DB_NAME = (the DB for the given site) " >&2
echo "DB_USER_NAME = (the DB user for accessing the DB for the given site) " >&2
echo "DB_USER_PASSWORD = (the password of the DB user) " >&2
echo "DB_HOSTNAME = (the host on which the DB resides) " >&2
echo "DB_CHARACTER_SET = (the DB character set defines the character set used for creation of the DB)" >&2
echo "DB_COLLATE = (the DB collate defines the collation used for creation of the DB) " >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
if [[ $# -eq 1 ]] ; then
showError "$1"
fi
}
# ------------------------------------------------------------------------------
# Missing property:
# $1: The missing property's name (without prepended "$").
# ------------------------------------------------------------------------------
function exitOnMissingDbProperty {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingDbProperty\" 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
showDbConfiguration "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 exitOnMissingDbPropertyPath {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingDbPropertyPath\" 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
showDbConfiguration "Path or file \"$VALUE\" not found defined in property \"$1\" of the \"$CONFIG\" config !!!"
exit $EXIT_ERROR
fi
}
# -----------------------------------------------------------------------------
if [[ $VERBOSE = y ]] ; then
echo "\"DB\" configuration validation is activated ..." >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $HELP = y ]] ; then
showDbConfiguration
fi
if [[ $HELP = n ]] ; then
if [[ $VERBOSE = y ]] ; then
showProperty "DB"
showProperty "DB_NAME"
showProperty "DB_USER_NAME"
showPasswordProperty "DB_USER_PASSWORD"
showProperty "DB_HOSTNAME"
showProperty "DB_CHARACTER_SET"
showProperty "DB_COLLATE"
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $DB = y ]] ; then
exitOnMissingDbProperty "DB_NAME"
exitOnMissingDbProperty "DB_USER_NAME"
exitOnMissingDbProperty "DB_USER_PASSWORD"
exitOnMissingDbProperty "DB_HOSTNAME"
exitOnMissingDbProperty "DB_CHARACTER_SET"
exitOnMissingDbProperty "DB_COLLATE"
fi
showSuccess "\"DB\" configuration for \"$CONFIG\" validated !"
fi