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

refcodes-batch.1.0.2.source-code.validate-media-player-folder-config.job Maven / Gradle / Ivy

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

# -----------------------------------------------------------------------------
# Shows the according config:
# -----------------------------------------------------------------------------
function showMediaPlayerFolderConfiguration {
	echo "The switch \"-j $JOB\" validates all \"MEDIA_PLAYER_FOLDER\" specific          " >&2
	echo "settings in the CONFIG file. Supported properties in the CONFIG file are:       " >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
	echo "MEDIA_PLAYER_FOLDER = (set to 'y' if we mirror our folder, else 'n')            " >&2
	echo "MEDIA_PLAYER_FOLDER_DIR = (the media player's folder with the media files)      " >&2
	echo "MEDIA_PLAYER_FOLDER_MUSIC_SUB_DIR (the music folder on your media player)       " >&2
	echo "MEDIA_PLAYER_FOLDER_MUSIC_INCLUDE_FILE (the rsync include file for your music)  " >&2
	echo "MEDIA_PLAYER_FOLDER_PHOTO_SUB_DIR (the photo folder on your media player)       " >&2
	echo "MEDIA_PLAYER_FOLDER_PHOTO_INCLUDE_FILE (the rsync include file for your photos) " >&2
	echo "MEDIA_PLAYER_FOLDER_EBOOK_SUB_DIR (the eBook folder on your media player)       " >&2
	echo "MEDIA_PLAYER_FOLDER_EBOOK_INCLUDE_FILE (the rsync include file for your ebooks) " >&2
	echo "MEDIA_PLAYER_FOLDER_VIDEO_SUB_DIR (the video folder on your media player)       " >&2
	echo "MEDIA_PLAYER_FOLDER_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 exitOnMissingMediaPlayerFolderProperty {
	if [ -z "$1" ] ; then
		showError "Argument missing: The function \"exitOnMissingMediaPlayerFolderProperty\" 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
		showMediaPlayerFolderConfiguration "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 exitOnWrongMediaPlayerFolderPropertyPath {
	if [ -z "$1" ] ; then
		showError "Argument missing: The function \"exitOnWrongMediaPlayerFolderPropertyPath\" 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
		showMediaPlayerFolderConfiguration "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 exitOnMissingMediaPlayerFolderPropertyPath {
	if [ -z "$1" ] ; then
		showError "Argument missing: The function \"exitOnMissingMediaPlayerFolderPropertyPath\" 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
		showMediaPlayerFolderConfiguration "Path or file \"$VALUE\" not found defined in property \"$1\" of the \"$CONFIG\" config !!!"
		exit $EXIT_ERROR
	fi
}

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

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

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

if [[ $HELP = n ]] ; then
	if [[ $VERBOSE = y ]] ; then
		showProperty "MEDIA_PLAYER_FOLDER"
		showProperty "MEDIA_PLAYER_FOLDER_DIR"
	fi
	
	if [[ $MEDIA_PLAYER_FOLDER = y ]] ; then
		if [ ! -z "${MEDIA_PLAYER_FOLDER_MUSIC_SUB_DIR}" ] ; then
			MEDIA_PLAYER_FOLDER_MUSIC_DIR=${MEDIA_PLAYER_FOLDER_DIR}/${MEDIA_PLAYER_FOLDER_MUSIC_SUB_DIR}
			if [[ $VERBOSE = y ]] ; then
				showProperty "MEDIA_PLAYER_FOLDER_MUSIC_DIR"
			fi
			exitOnMissingMediaPlayerFolderPropertyPath "MEDIA_PLAYER_FOLDER_MUSIC_DIR"
			if [[ $VERBOSE = y ]] ; then
				showProperty "MEDIA_PLAYER_FOLDER_MUSIC_INCLUDE_FILE"
			fi
			exitOnMissingMediaPlayerFolderPropertyPath "MEDIA_PLAYER_FOLDER_MUSIC_INCLUDE_FILE"
		fi
		if [ ! -z "${MEDIA_PLAYER_FOLDER_PHOTO_SUB_DIR}" ] ; then
			MEDIA_PLAYER_FOLDER_PHOTO_DIR=${MEDIA_PLAYER_FOLDER_DIR}/${MEDIA_PLAYER_FOLDER_PHOTO_SUB_DIR}
			if [[ $VERBOSE = y ]] ; then
				showProperty "MEDIA_PLAYER_FOLDER_PHOTO_DIR"
			fi
			exitOnMissingMediaPlayerFolderPropertyPath "MEDIA_PLAYER_FOLDER_PHOTO_DIR"
			if [[ $VERBOSE = y ]] ; then
				showProperty "MEDIA_PLAYER_FOLDER_PHOTO_INCLUDE_FILE"
			fi
			exitOnMissingMediaPlayerFolderPropertyPath "MEDIA_PLAYER_FOLDER_PHOTO_INCLUDE_FILE"
		fi
		if [ ! -z "${MEDIA_PLAYER_FOLDER_EBOOK_SUB_DIR}" ] ; then
			MEDIA_PLAYER_FOLDER_EBOOK_DIR=${MEDIA_PLAYER_FOLDER_DIR}/${MEDIA_PLAYER_FOLDER_EBOOK_SUB_DIR}
			if [[ $VERBOSE = y ]] ; then
				showProperty "MEDIA_PLAYER_FOLDER_EBOOK_DIR"
			fi
			exitOnMissingMediaPlayerFolderPropertyPath "MEDIA_PLAYER_FOLDER_EBOOK_DIR"
			if [[ $VERBOSE = y ]] ; then
				showProperty "MEDIA_PLAYER_FOLDER_EBOOK_INCLUDE_FILE"
			fi
			exitOnMissingMediaPlayerFolderPropertyPath "MEDIA_PLAYER_FOLDER_EBOOK_INCLUDE_FILE"
		fi
		if [ ! -z "${MEDIA_PLAYER_FOLDER_VIDEO_SUB_DIR}" ] ; then
			MEDIA_PLAYER_FOLDER_VIDEO_DIR=${MEDIA_PLAYER_FOLDER_DIR}/${MEDIA_PLAYER_FOLDER_VIDEO_SUB_DIR}
			if [[ $VERBOSE = y ]] ; then
				showProperty "MEDIA_PLAYER_FOLDER_VIDEO_DIR"
			fi
			exitOnMissingMediaPlayerFolderPropertyPath "MEDIA_PLAYER_FOLDER_VIDEO_DIR"
			if [[ $VERBOSE = y ]] ; then
				showProperty "MEDIA_PLAYER_FOLDER_VIDEO_INCLUDE_FILE"
			fi
			exitOnMissingMediaPlayerFolderPropertyPath "MEDIA_PLAYER_FOLDER_VIDEO_INCLUDE_FILE"
		fi
	fi
	
	if [[ $VERBOSE = y ]] ; then
		logSeparator
	fi	

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy