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

refcodes-batch.1.0.3.source-code.replicate-media-folder-to-media-player-folder-mirror.job Maven / Gradle / Ivy

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

if [[ $HELP = y ]] ; then
	echo "The switch \"-j $JOB\" rsyncs your local media folder structure.                " >&2
	echo "Local files are copied into the media player's folder structure, any            " >&2
	echo "media palyer files not exisiting are removed from the media palyer's folder     " >&2
	echo "structure.                                                                      " >&2
	logSeparator
fi

. $SCRIPT_DIR/validate-media-folder-config.job
. $SCRIPT_DIR/validate-media-player-folder-config.job
. $SCRIPT_DIR/validate-media-player-folder-mirror-config.job

if [[ $HELP = y ]] ; then
	exit $EXIT_SUCCESS
fi

exitOnConfigOff "MEDIA_FOLDER"
exitOnConfigOff "MEDIA_PLAYER_FOLDER"
exitOnConfigOff "MEDIA_PLAYER_FOLDER_MIRROR"

MEDIA_FOLDER_MUSIC_DIR=${MEDIA_FOLDER_DIR}/${MEDIA_FOLDER_MUSIC_SUB_DIR}
MEDIA_FOLDER_PHOTO_DIR=${MEDIA_FOLDER_DIR}/${MEDIA_FOLDER_PHOTO_SUB_DIR}
MEDIA_FOLDER_EBOOK_DIR=${MEDIA_FOLDER_DIR}/${MEDIA_FOLDER_EBOOK_SUB_DIR}
MEDIA_FOLDER_VIDEO_DIR=${MEDIA_FOLDER_DIR}/${MEDIA_FOLDER_VIDEO_SUB_DIR}
MEDIA_PLAYER_FOLDER_MUSIC_DIR=${MEDIA_PLAYER_FOLDER_DIR}/${MEDIA_PLAYER_FOLDER_MUSIC_SUB_DIR}
MEDIA_PLAYER_FOLDER_PHOTO_DIR=${MEDIA_PLAYER_FOLDER_DIR}/${MEDIA_PLAYER_FOLDER_PHOTO_SUB_DIR}
MEDIA_PLAYER_FOLDER_EBOOK_DIR=${MEDIA_PLAYER_FOLDER_DIR}/${MEDIA_PLAYER_FOLDER_EBOOK_SUB_DIR}
MEDIA_PLAYER_FOLDER_VIDEO_DIR=${MEDIA_PLAYER_FOLDER_DIR}/${MEDIA_PLAYER_FOLDER_VIDEO_SUB_DIR}

EXCLUDE=""
if [ ! -z "${MEDIA_PLAYER_FOLDER_DO_NOT_TOUCH}" ] ; then
	EXCLUDE="--exclude ${MEDIA_PLAYER_FOLDER_DO_NOT_TOUCH}"
fi
		
if [ ! -z "${MEDIA_FOLDER_MUSIC_SUB_DIR}" ] && [ ! -z "${MEDIA_PLAYER_FOLDER_MUSIC_SUB_DIR}" ] ; then
	if [[ $VERBOSE = y ]] ; then
		echo "Replicating media folder \"${MEDIA_FOLDER_MUSIC_DIR}\" to media player folder mirror \"${MEDIA_PLAYER_FOLDER_MUSIC_DIR}\" ..." >&2
		logSeparator
	fi
	
	# Try "--no-p" (no permissions) and "--no-g" (no group)
	rsync -avzh --modify-window=1 --delete ${EXCLUDE} --include-from="${MEDIA_PLAYER_FOLDER_MUSIC_INCLUDE_FILE}" "${MEDIA_FOLDER_MUSIC_DIR}/" "${MEDIA_PLAYER_FOLDER_MUSIC_DIR}"
	
	exitCode=$?
	if [[ $exitCode != 23 ]] && [[ $exitCode != 0 ]] ; then
		$(exit $exitCode)
		exitOnError "Unable to replicate folder \"${MEDIA_FOLDER_MUSIC_DIR}\" to folder mirror \"${MEDIA_PLAYER_FOLDER_MUSIC_DIR}\" !!!"
	fi
	logSeparator
fi

if [ ! -z "${MEDIA_FOLDER_PHOTO_SUB_DIR}" ] && [ ! -z "${MEDIA_PLAYER_FOLDER_PHOTO_SUB_DIR}" ] ; then
	if [[ $VERBOSE = y ]] ; then
		echo "Replicating media folder \"${MEDIA_FOLDER_PHOTO_DIR}\" to media player folder mirror \"${MEDIA_PLAYER_FOLDER_PHOTO_DIR}\" ..." >&2
		logSeparator
	fi
	
	# Try "--no-p" (no permissions) and "--no-g" (no group)
	rsync -avzh --modify-window=1 --delete ${EXCLUDE} --include-from="${MEDIA_PLAYER_FOLDER_PHOTO_INCLUDE_FILE}" "${MEDIA_FOLDER_PHOTO_DIR}/" "${MEDIA_PLAYER_FOLDER_PHOTO_DIR}"
	
	exitCode=$?
	if [[ $exitCode != 23 ]] && [[ $exitCode != 0 ]] ; then
		$(exit $exitCode)
		exitOnError "Unable to replicate folder \"${MEDIA_FOLDER_PHOTO_DIR}\" to folder mirror \"${MEDIA_PLAYER_FOLDER_PHOTO_DIR}\" !!!"
	fi
	logSeparator
fi

if [ ! -z "${MEDIA_FOLDER_EBOOK_SUB_DIR}" ] && [ ! -z "${MEDIA_PLAYER_FOLDER_EBOOK_SUB_DIR}" ] ; then
	if [[ $VERBOSE = y ]] ; then
		echo "Replicating media folder \"${MEDIA_FOLDER_EBOOK_DIR}\" to media player folder mirror \"${MEDIA_PLAYER_FOLDER_EBOOK_DIR}\" ..." >&2
		logSeparator
	fi
	
	# Try "--no-p" (no permissions) and "--no-g" (no group)
	rsync -avzh --modify-window=1 --delete ${EXCLUDE} --include-from="${MEDIA_PLAYER_FOLDER_EBOOK_INCLUDE_FILE}" "${MEDIA_FOLDER_EBOOK_DIR}/" "${MEDIA_PLAYER_FOLDER_EBOOK_DIR}"
	
	exitCode=$?
	if [[ $exitCode != 23 ]] && [[ $exitCode != 0 ]] ; then
		$(exit $exitCode)
		exitOnError "Unable to replicate folder \"${MEDIA_FOLDER_EBOOK_DIR}\" to folder mirror \"${MEDIA_PLAYER_FOLDER_EBOOK_DIR}\" !!!"
	fi
	logSeparator
fi

if [ ! -z "${MEDIA_FOLDER_VIDEO_SUB_DIR}" ] && [ ! -z "${MEDIA_PLAYER_FOLDER_VIDEO_SUB_DIR}" ] ; then
	if [[ $VERBOSE = y ]] ; then
		echo "Replicating media folder \"${MEDIA_FOLDER_VIDEO_DIR}\" to media player folder mirror \"${MEDIA_PLAYER_FOLDER_VIDEO_DIR}\" ..." >&2
		logSeparator
	fi
	
	# Try "--no-p" (no permissions) and "--no-g" (no group)
	rsync -avzh --modify-window=1 --delete ${EXCLUDE} --include-from="${MEDIA_PLAYER_FOLDER_VIDEO_INCLUDE_FILE}" "${MEDIA_FOLDER_VIDEO_DIR}/" "${MEDIA_PLAYER_FOLDER_VIDEO_DIR}"
	
	exitCode=$?
	if [[ $exitCode != 23 ]] && [[ $exitCode != 0 ]] ; then
		$(exit $exitCode)
		exitOnError "Unable to replicate folder \"${MEDIA_FOLDER_VIDEO_DIR}\" to folder mirror \"${MEDIA_PLAYER_FOLDER_VIDEO_DIR}\" !!!"
	fi
	logSeparator
fi

showSuccess "Replicated folder \"$MEDIA_FOLDER_DIR\" to folder mirror \"$MEDIA_PLAYER_FOLDER_DIR\" !"




© 2015 - 2025 Weber Informatics LLC | Privacy Policy