refcodes-batch.1.0.2.source-code.validate-media-folder-mirror-config.job Maven / Gradle / Ivy
#!/bin/bash
# -----------------------------------------------------------------------------
# Shows the according config:
# -----------------------------------------------------------------------------
function showMediaFolderMirrorConfiguration {
echo "The switch \"-j $JOB\" validates all \"MEDIA_FOLDER_MIRROR\" specific " >&2
echo "settings in the CONFIG file. Supported properties in the CONFIG file are: " >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
echo "MEDIA_FOLDER_MIRROR = (set to 'y' if we mirror our folder, else 'n') " >&2
echo "MEDIA_FOLDER_MIRROR_DO_NOT_TOUCH = (an rsync \"-exclude\" pattern to be untouched on the media mirror)" >&2
echo "MEDIA_FOLDER_MIRROR_DIR = (the mirror folder with the files to be mirrored from/to)" >&2
echo "MEDIA_FOLDER_MIRROR_MUSIC_SUB_DIR (the music folder on your media folder mirror)" >&2
echo "MEDIA_FOLDER_MIRROR_MUSIC_INCLUDE_FILE (the rsync include file for your music) " >&2
echo "MEDIA_FOLDER_MIRROR_PHOTO_SUB_DIR (the photo folder on your media folder mirror)" >&2
echo "MEDIA_FOLDER_MIRROR_PHOTO_INCLUDE_FILE (the rsync include file for your photos) " >&2
echo "MEDIA_FOLDER_MIRROR_EBOOK_SUB_DIR (the eBook folder on your media folder mirror)" >&2
echo "MEDIA_FOLDER_MIRROR_EBOOK_INCLUDE_FILE (the rsync include file for your ebooks) " >&2
echo "MEDIA_FOLDER_MIRROR_VIDEO_SUB_DIR (the video folder on your media folder mirror)" >&2
echo "MEDIA_FOLDER_MIRROR_VIDEO_INCLUDE_FILE (the rsync include file for your videos) " >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
if [[ $# -eq 1 ]] ; then
showError "$1"
fi
}
# ------------------------------------------------------------------------------
# Missing property:
# $1: The missing property's name (without prepended "$").
# ------------------------------------------------------------------------------
function exitOnMissingMediaFolderMirrorProperty {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingMediaFolderMirrorProperty\" 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
showMediaFolderMirrorConfiguration "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 exitOnWrongMediaFolderMirrorPropertyPath {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnWrongMediaFolderMirrorPropertyPath\" 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
showMediaFolderMirrorConfiguration "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 exitOnMissingMediaFolderMirrorPropertyPath {
if [ -z "$1" ] ; then
showError "Argument missing: The function \"exitOnMissingMediaFolderMirrorPropertyPath\" 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
showMediaFolderMirrorConfiguration "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_MIRROR\" configuration validation is activated ..." >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
fi
if [[ $HELP = y ]] ; then
showMediaFolderMirrorConfiguration
fi
if [[ $HELP = n ]] ; then
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER_MIRROR"
showProperty "MEDIA_FOLDER_MIRROR_DIR"
showProperty "MEDIA_FOLDER_MIRROR_DO_NOT_TOUCH"
MEDIA_FOLDER_MIRROR_DO_NOT_TOUCH_EXCLUDE=""
if [ ! -z "${MEDIA_FOLDER_MIRROR_DO_NOT_TOUCH}" ] ; then
MEDIA_FOLDER_MIRROR_DO_NOT_TOUCH_EXCLUDE="--exclude ${MEDIA_FOLDER_MIRROR_DO_NOT_TOUCH}"
fi
showProperty "MEDIA_FOLDER_MIRROR_DO_NOT_TOUCH_EXCLUDE"
fi
if [[ $MEDIA_FOLDER_MIRROR = y ]] ; then
if [ ! -z "${MEDIA_FOLDER_MIRROR_MUSIC_SUB_DIR}" ] ; then
MEDIA_FOLDER_MIRROR_MUSIC_DIR=${MEDIA_FOLDER_MIRROR_DIR}/${MEDIA_FOLDER_MIRROR_MUSIC_SUB_DIR}
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER_MIRROR_MUSIC_DIR"
fi
exitOnWrongMediaFolderMirrorPropertyPath "MEDIA_FOLDER_MIRROR_MUSIC_DIR"
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER_MIRROR_MUSIC_INCLUDE_FILE"
fi
exitOnWrongMediaFolderMirrorPropertyPath "MEDIA_FOLDER_MIRROR_MUSIC_INCLUDE_FILE"
fi
if [ ! -z "${MEDIA_FOLDER_MIRROR_PHOTO_SUB_DIR}" ] ; then
MEDIA_FOLDER_MIRROR_PHOTO_DIR=${MEDIA_FOLDER_MIRROR_DIR}/${MEDIA_FOLDER_MIRROR_PHOTO_SUB_DIR}
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER_MIRROR_PHOTO_DIR"
fi
exitOnWrongMediaFolderMirrorPropertyPath "MEDIA_FOLDER_MIRROR_PHOTO_DIR"
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER_MIRROR_PHOTO_INCLUDE_FILE"
fi
exitOnWrongMediaFolderMirrorPropertyPath "MEDIA_FOLDER_MIRROR_PHOTO_INCLUDE_FILE"
fi
if [ ! -z "${MEDIA_FOLDER_MIRROR_EBOOK_SUB_DIR}" ] ; then
MEDIA_FOLDER_MIRROR_EBOOK_DIR=${MEDIA_FOLDER_MIRROR_DIR}/${MEDIA_FOLDER_MIRROR_EBOOK_SUB_DIR}
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER_MIRROR_EBOOK_DIR"
fi
exitOnWrongMediaFolderMirrorPropertyPath "MEDIA_FOLDER_MIRROR_EBOOK_DIR"
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER_MIRROR_EBOOK_INCLUDE_FILE"
fi
exitOnWrongMediaFolderMirrorPropertyPath "MEDIA_FOLDER_MIRROR_EBOOK_INCLUDE_FILE"
fi
if [ ! -z "${MEDIA_FOLDER_MIRROR_VIDEO_SUB_DIR}" ] ; then
MEDIA_FOLDER_MIRROR_VIDEO_DIR=${MEDIA_FOLDER_MIRROR_DIR}/${MEDIA_FOLDER_MIRROR_VIDEO_SUB_DIR}
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER_MIRROR_VIDEO_DIR"
fi
exitOnWrongMediaFolderMirrorPropertyPath "MEDIA_FOLDER_MIRROR_VIDEO_DIR"
if [[ $VERBOSE = y ]] ; then
showProperty "MEDIA_FOLDER_MIRROR_VIDEO_INCLUDE_FILE"
fi
exitOnWrongMediaFolderMirrorPropertyPath "MEDIA_FOLDER_MIRROR_VIDEO_INCLUDE_FILE"
fi
fi
if [[ $VERBOSE = y ]] ; then
logSeparator
fi
showSuccess "\"MEDIA_FOLDER_MIRROR\" configuration for \"$CONFIG\" validated !"
fi