All Downloads are FREE. Search and download functionalities are using the official Maven repository.

refcodes-batch.0.3.0.source-code.validate-db-mirror-config.job Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
#!/bin/bash

# -----------------------------------------------------------------------------
# Shows the according config:
# -----------------------------------------------------------------------------
function showDbMirrorConfiguration {
	echo "The switch \"-j $JOB\" validates all \"DB_MIRROR\" specific                     " >&2
	echo "settings in the CONFIG file. Supported properties in the CONFIG file are:       " >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
	echo "DB_MIRROR = (set to 'y' if a DB mirror is used/configured, else 'n')            " >&2
	echo "DB_MIRROR_NAME = (the DB mirror name for the DB to be used)                     " >&2
	echo "DB_MIRROR_USER_NAME = (the DB mirror user to be used)                           " >&2
	echo "DB_MIRROR_USER_PASSWORD = (the DB mirror's user password to be use)             " >&2
	echo "DB_MIRROR_HOSTNAME = (the host on which the DB mirror resides)                  " >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
	if [[ $# -eq 1 ]] ; then
		showError "$1"
	fi
}

# ------------------------------------------------------------------------------
# Missing property: 
# $1: The missing property's name (without prepended "$").
# ------------------------------------------------------------------------------
function exitOnDbMirrorDbMirrorProperty {
	if [ -z "$1" ] ; then
		showError "Argument missing: The function \"exitOnDbMirrorDbMirrorProperty\" 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
		showDbMirrorConfiguration "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 exitOnDbMirrorDbMirrorPropertyPath {
	if [ -z "$1" ] ; then
		showError "Argument missing: The function \"exitOnDbMirrorDbMirrorPropertyPath\" 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
		showDbMirrorConfiguration "Path or file \"$VALUE\" not found defined in property \"$1\" of the \"$CONFIG\" config !!!"
		exit $EXIT_ERROR
	fi
}

# -----------------------------------------------------------------------------

if [[ $VERBOSE = y ]] ; then
	echo "\"DB_MIRROR\" configuration validation is activated ..." >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
fi

if [[ $HELP = y ]] ; then
	showDbMirrorConfiguration 
fi

if [[ $HELP = n ]] ; then
	if [[ $VERBOSE = y ]] ; then
		showProperty "DB_MIRROR"
		showProperty "DB_MIRROR_NAME"
		showProperty "DB_MIRROR_USER_NAME"
		showPasswordProperty "DB_MIRROR_USER_PASSWORD"
		showProperty "DB_MIRROR_HOSTNAME"
		# echo "--------------------------------------------------------------------------------" >&2
		logSeparator
	fi

	if [[ $DB_MIRROR = y ]] ; then
		exitOnDbMirrorDbMirrorProperty "DB_MIRROR_NAME"
		exitOnDbMirrorDbMirrorProperty "DB_MIRROR_USER_NAME"
		exitOnDbMirrorDbMirrorProperty "DB_MIRROR_USER_PASSWORD"
		exitOnDbMirrorDbMirrorProperty "DB_MIRROR_HOSTNAME"
	fi

	showSuccess "\"DB_MIRROR\" configuration for \"$CONFIG\" validated !"
fi




© 2015 - 2024 Weber Informatics LLC | Privacy Policy