#!/bin/bash
# Version("2.2.0.0")
# InformationalVersion("2.2.0.0")
# rSync AppServer sounds folder with local soundsV2 folder

SHARES_ROOT=/home/soundsv2share
LOCAL_ROOT=/home/soundsv2

function process_rsync {

	# Rsync sound files
	
	if [[ $QUERY_STRING == "" ]]
	then
		/usr/bin/rsync -r $SHARES_ROOT/ $LOCAL_ROOT
	else
#		for f in `ls -A -F $SHARES_ROOT/ | grep "/"`
#		do
#				if [ -d $SHARES_ROOT/$f$QUERY_STRING ]
#				then
#						/usr/bin/rsync -r $SHARES_ROOT/$f$QUERY_STRING/ $LOCAL_ROOT/$QUERY_STRING
#				fi
#		done
		/usr/bin/rsync -r $SHARES_ROOT/$QUERY_STRING/ $LOCAL_ROOT/$QUERY_STRING
	fi

	# Send 200 OK back to appserver
	echo -e "HTTP/1.1 200 OK\r"
	echo -e "Content-Type: text/plain\r"
	echo -e "\r"
	echo -e "\r"		

	exit 0
}


# Main Routine

process_rsync
exit 0