refcodes-batch.1.0.2.source-code.validate-folder-config.job Maven / Gradle / Ivy
#!/bin/bash
# -----------------------------------------------------------------------------
# Shows the according config:
# -----------------------------------------------------------------------------
function showFolderConfiguration {
echo "The switch \"-j $JOB\" validates all \"FOLDER\" specific " >&2
echo "settings in the CONFIG file. Supported properties in the CONFIG file are: " >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
echo "FOLDER = (set to 'y' if we want to enable folder based jobs, else 'n') " >&2
echo "FOLDER_DIR = (the path of the folder for folder based jobs) " >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
if [[ $# -eq 1 ]] ; then
showError "$1"
fi
}
# ------------------------------------------------------------------------------
# Missing property:
# $1: The missing property's name (without prepended "$").
# ------------------------------------------------------------------------------
function exitOnMissingFolderProperty {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingFolderProperty\" 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
showFolderConfiguration "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 exitOnWrongFolderPropertyPath {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnWrongFolderPropertyPath\" 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
showFolderConfiguration "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 exitOnMissingFolderPropertyPath {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingFolderPropertyPath\" 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
showFolderConfiguration "Path or file \"$VALUE\" not found defined in property \"$1\" of the \"$CONFIG\" config !!!"
exit $EXIT_ERROR
fi
}
# -----------------------------------------------------------------------------
if [[ $VERBOSE = y ]] ; then
echo "\"FOLDER\" configuration validation is activated ..." >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $HELP = y ]] ; then
showFolderConfiguration
fi
if [[ $HELP = n ]] ; then
if [[ $VERBOSE = y ]] ; then
showProperty "FOLDER"
showProperty "FOLDER_DIR"
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $FOLDER = y ]] ; then
exitOnMissingFolderProperty "FOLDER_DIR"
exitOnWrongFolderPropertyPath "FOLDER_DIR"
exitOnMissingFolderPropertyPath "FOLDER_DIR"
fi
showSuccess "\"FOLDER\" configuration for \"$CONFIG\" validated !"
fi