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

refcodes-batch.1.0.2.source-code.validate-dump-dir-config.job Maven / Gradle / Ivy

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

# -----------------------------------------------------------------------------
# Shows the according config:
# -----------------------------------------------------------------------------
function showDumpDirConfiguration {
	echo "The switch \"-j $JOB\" validates all \"DUMP\" specific                            " >&2
	echo "settings in the CONFIG file. Supported properties in the CONFIG file are:         " >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
	echo "DUMP = (set to 'y' if we want to enable dump based jobs, else 'n')                " >&2
	echo "DUMP_DIR = (the path of the folder for dump based jobs)                           " >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
	if [[ $# -eq 1 ]] ; then
		showError "$1"
	fi
}

# ------------------------------------------------------------------------------
# Missing property: 
# $1: The missing property's name (without prepended "$").
# ------------------------------------------------------------------------------
function exitOnMissingDumpDirProperty {
	if [ -z "$1" ] ; then
		showError "Argument missing: The function \"exitOnMissingDumpDirProperty\" 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
		showDumpDirConfiguration "Missing or empty property \"$1\" !!!"
		exit $EXIT_ERROR
	fi
}

# ------------------------------------------------------------------------------
# File defined in $CONFIG_FILE has wrong format, i.e. it ends with a slsh "/":
# $1 The property name (without prepended "$") with the (wrongly formatted) path.
# ------------------------------------------------------------------------------
function exitOnWrongDumpDirPropertyPath {
	if [ -z "$1" ] ; then
		showError "Argument missing: The function \"exitOnWrongDumpDirPropertyPath\" expects an argument !!!" >&2
		exit $EXIT_BUG
	fi

	# $VALUE is the value of the variable passed as $1:
	eval "VALUE=\$$1"
	# if [[ "$VALUE" =~ "/" ]] ; then
	if [[ ${VALUE: -1} == "/" ]] ; then
		showDumpDirConfiguration "Path or file \"$VALUE\" in property \"$1\" of the \"$CONFIG\" config ends unexpectedly with a slash \"/\" !!!"
		exit $EXIT_ERROR
	fi
}

# ------------------------------------------------------------------------------
# File defined in $CONFIG_FILE non exisiting:
# $1 The property name (without prepended "$") with the (non exisitent) path.
# ------------------------------------------------------------------------------
function exitOnMissingDumpDirPropertyPath {
	if [ -z "$1" ] ; then
		showError "Argument missing: The function \"exitOnMissingDumpDirPropertyPath\" 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
		showDumpDirConfiguration "Path or file \"$VALUE\" not found defined in property \"$1\" of the \"$CONFIG\" config !!!"
		exit $EXIT_ERROR
	fi
}

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

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

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

if [[ $HELP = n ]] ; then
	if [[ $VERBOSE = y ]] ; then
		showProperty "DUMP"
		showProperty "DUMP_DIR"
		# echo "--------------------------------------------------------------------------------" >&2
		logSeparator
	fi

	if [[ $DUMP = y ]] ; then
		exitOnMissingDumpDirProperty "DUMP_DIR"
		exitOnWrongDumpDirPropertyPath "DUMP_DIR"
		exitOnMissingDumpDirPropertyPath "DUMP_DIR"
	fi

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy