refcodes-batch.0.3.0.source-code.validate-media-folder-config.job Maven / Gradle / Ivy
#!/bin/bash
# -----------------------------------------------------------------------------
# Shows the according config:
# -----------------------------------------------------------------------------
function showMediaFolderConfiguration {
echo "The switch \"-j $JOB\" validates all \"MEDIA_FOLDER\" specific " >&2
echo "settings in the CONFIG file. Supported properties in the CONFIG file are: " >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
echo "MEDIA_FOLDER = (set to 'y' if we mirror our folder, else 'n') " >&2
echo "MEDIA_FOLDER_MUSIC_SUB_DIR (the music folder on your local drive) " >&2
echo "MEDIA_FOLDER_PHOTO_SUB_DIR (the photo folder on your local drive) " >&2
echo "MEDIA_FOLDER_EBOOK_SUB_DIR (the eBook folder on your local drive) " >&2
echo "MEDIA_FOLDER_VIDEO_SUB_DIR (the video folder on your local drive) " >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
if [[ $# -eq 1 ]] ; then
showError "$1"
fi
}
# ------------------------------------------------------------------------------
# Missing property:
# $1: The missing property's name (without prepended "$").
# ------------------------------------------------------------------------------
function exitOnMissingMediaFolderProperty {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingMediaFolderProperty\" 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
showMediaFolderConfiguration "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 exitOnWrongMediaFolderPropertyPath {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnWrongMediaFolderPropertyPath\" 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
showMediaFolderConfiguration "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 exitOnMissingMediaFolderPropertyPath {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingMediaFolderPropertyPath\" 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
showMediaFolderConfiguration "Path or file \"$VALUE\" not found defined in property \"$1\" of the \"$CONFIG\" config !!!"
exit $EXIT_ERROR
fi
}
# -----------------------------------------------------------------------------
if [[ $VERBOSE = y ]] ; then
echo "\"MEDIA_FOLDER\" configuration validation is activated ..." >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $HELP = y ]] ; then
showMediaFolderConfiguration
fi
if [[ $HELP = n ]] ; then
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER"
fi
if [[ $MEDIA_FOLDER = y ]] ; then
if [ ! -z "${MEDIA_FOLDER_MUSIC_SUB_DIR}" ] ; then
MEDIA_FOLDER_MUSIC_DIR=${MEDIA_FOLDER_DIR}/${MEDIA_FOLDER_MUSIC_SUB_DIR}
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER_MUSIC_DIR"
fi
exitOnMissingMediaFolderPropertyPath "MEDIA_FOLDER_MUSIC_DIR"
fi
if [ ! -z "${MEDIA_FOLDER_PHOTO_SUB_DIR}" ] ; then
MEDIA_FOLDER_PHOTO_DIR=${MEDIA_FOLDER_DIR}/${MEDIA_FOLDER_PHOTO_SUB_DIR}
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER_PHOTO_DIR"
fi
exitOnMissingMediaFolderPropertyPath "MEDIA_FOLDER_PHOTO_DIR"
fi
if [ ! -z "${MEDIA_FOLDER_EBOOK_SUB_DIR}" ] ; then
MEDIA_FOLDER_EBOOK_DIR=${MEDIA_FOLDER_DIR}/${MEDIA_FOLDER_EBOOK_SUB_DIR}
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER_EBOOK_DIR"
fi
exitOnMissingMediaFolderPropertyPath "MEDIA_FOLDER_EBOOK_DIR"
fi
if [ ! -z "${MEDIA_FOLDER_VIDEO_SUB_DIR}" ] ; then
MEDIA_FOLDER_VIDEO_DIR=${MEDIA_FOLDER_DIR}/${MEDIA_FOLDER_VIDEO_SUB_DIR}
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER_VIDEO_DIR"
fi
exitOnMissingMediaFolderPropertyPath "MEDIA_FOLDER_VIDEO_DIR"
fi
fi
if [[ $VERBOSE = y ]] ; then
logSeparator
fi
showSuccess "\"MEDIA_FOLDER\" configuration for \"$CONFIG\" validated !"
fi