#! /bin/sh

cd ../../..
WORK_DIR=`pwd`
echo "working directory $WORK_DIR"

# pass this as argument
DEPLOYMENT_DIR=$WORK_DIR/../deployment	
echo "deployment directory $DEPLOYMENT_DIR"

 if [ -d "$DEPLOYMENT_DIR" ]
  then
   echo "folder $DEPLOYMENT_DIR exists. deleting it for clean deployment"   
   rm -rf  $DEPLOYMENT_DIR
fi

mkdir $DEPLOYMENT_DIR


# Multiple proejct example: PROJECT_LIST=(Project1 Project2 Project2)
PROJECT_LIST=(RunProjectBatchFile)

for PROJECT_NAME in  ${PROJECT_LIST[@]}
do 

	echo "Project Name >> $PROJECT_NAME"
		
	mkdir $DEPLOYMENT_DIR/$PROJECT_NAME
	mkdir $DEPLOYMENT_DIR/$PROJECT_NAME/lib
	mkdir $DEPLOYMENT_DIR/$PROJECT_NAME/scripts/
	mkdir $DEPLOYMENT_DIR/$PROJECT_NAME/runWindow/
	mkdir $DEPLOYMENT_DIR/$PROJECT_NAME/logs
	mkdir $DEPLOYMENT_DIR/$PROJECT_NAME/config
	
	echo "copying jar into $DEPLOYMENT_DIR/$PROJECT_NAME/lib/ ..."
	cp $PROJECT_NAME/target/lib/* $DEPLOYMENT_DIR/$PROJECT_NAME/lib/
	cp $PROJECT_NAME/target/*.jar $DEPLOYMENT_DIR/$PROJECT_NAME/lib/
	
	echo "copying scripts into $DEPLOYMENT_DIR/$PROJECT_NAME/scripts/ ..."
	cp $PROJECT_NAME/scripts/deployment/* $DEPLOYMENT_DIR/$PROJECT_NAME/scripts/
	
	echo "copying xml and properties file to $DEPLOYMENT_DIR/$PROJECT_NAME/config/ ..."
	cp $PROJECT_NAME/src/main/config/* $DEPLOYMENT_DIR/$PROJECT_NAME/config/
	cp $PROJECT_NAME/src/main/resources/* $DEPLOYMENT_DIR/$PROJECT_NAME/config/
	
	echo "copying runtime window file to  $DEPLOYMENT_DIR/$PROJECT_NAME/runWindow/"
	cp $PROJECT_NAME/scripts/runWindow/* $DEPLOYMENT_DIR/$PROJECT_NAME/runWindow/	
	
	echo "copying runtime file to  $DEPLOYMENT_DIR/$PROJECT_NAME/runWindow/"
	#Other folder copy example: cp Parent/scripts/runtime/* $DEPLOYMENT_DIR/$PROJECT_NAME/scripts/
	
done;


echo "copying windows task file to $DEPLOYMENT_DIR/window_task/"
mkdir $DEPLOYMENT_DIR/window_task/
# Window take copy example: cp -r Parent/scripts/window_task/* $DEPLOYMENT_DIR/window_task/

echo "exiting after completion of deployment"
exit 0
