refcodes-batch.0.3.0.source-code.validate-folder-mirror-config.job Maven / Gradle / Ivy
#!/bin/bash
# -----------------------------------------------------------------------------
# Shows the according config:
# -----------------------------------------------------------------------------
function showFolderMirrorConfiguration {
echo "The switch \"-j $JOB\" validates all \"FOLDER_MIRROR\" specific " >&2
echo "settings in the CONFIG file. Supported properties in the CONFIG file are: " >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
echo "FOLDER_MIRROR = (set to 'y' if we mirror our folder, else 'n') " >&2
echo "FOLDER_MIRROR_DIR = (the mirror folder with the files to be mirrored from/to) " >&2
echo "FOLDER_MIRROR_INCLUDES = (an explicit space separated list of folders to only include on the mirror)" >&2
echo "FOLDER_MIRROR_EXCLUDES = (space separated rsync \"-exclude\" pattern to be untouched on the mirror)" >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
if [[ $# -eq 1 ]] ; then
showError "$1"
fi
}
# ------------------------------------------------------------------------------
# Missing property:
# $1: The missing property's name (without prepended "$").
# ------------------------------------------------------------------------------
function exitOnMissingFolderMirrorProperty {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingFolderMirrorProperty\" 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
showFolderMirrorConfiguration "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 exitOnWrongFolderMirrorPropertyPath {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnWrongFolderMirrorPropertyPath\" 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
showFolderMirrorConfiguration "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 exitOnMissingFolderMirrorPropertyPath {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingFolderMirrorPropertyPath\" 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
showFolderMirrorConfiguration "Path or file \"$VALUE\" not found defined in property \"$1\" of the \"$CONFIG\" config !!!"
exit $EXIT_ERROR
fi
}
# -----------------------------------------------------------------------------
if [[ $VERBOSE = y ]] ; then
echo "\"FOLDER_MIRROR\" configuration validation is activated ..." >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $HELP = y ]] ; then
showFolderMirrorConfiguration
fi
if [[ $HELP = n ]] ; then
if [[ $VERBOSE = y ]] ; then
showProperty "FOLDER_MIRROR"
showProperty "FOLDER_MIRROR_DIR"
showProperty "FOLDER_MIRROR_INCLUDES"
showProperty "FOLDER_MIRROR_EXCLUDES"
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $FOLDER_MIRROR = y ]] ; then
exitOnMissingFolderMirrorProperty "FOLDER_MIRROR_DIR"
exitOnWrongFolderMirrorPropertyPath "FOLDER_MIRROR_DIR"
fi
showSuccess "\"FOLDER_MIRROR\" configuration for \"$CONFIG\" validated !"
fi