#!/bin/bash
# This deploy hook gets executed after dependencies are resolved and the
# build hook has been run but before the application has been started back
# up again.  This script gets executed directly, so it could be python, php,
# ruby, etc.
set -x

FUSEFABRIC=fuse-fabric-SNAPSHOT
FUSEFABRIC_TARGET=fuse-fabric-99-master-SNAPSHOT
TARBALL=$FUSEFABRIC.tar.gz
TMPAREA=$OPENSHIFT_RUNTIME_DIR/upload

if [ ! -f ${TMPAREA}/${TARBALL} ]
then
   echo "Create upload directory and download Fuse Fabric." 
   mkdir $TMPAREA
   wget -O ${TMPAREA}/${TARBALL} http://repo.fusesource.com/nexus/content/repositories/snapshots/org/fusesource/fabric/fuse-fabric/99-master-SNAPSHOT/fuse-fabric-99-master-20120824.142910-62.tar.gz
   cd ${TMPAREA}
   tar zxf ${TARBALL}
   mv ${FUSEFABRIC_TARGET} fabric  
fi	

if [ ! -d ${OPENSHIFT_RUNTIME_DIR}/fabric ]
then
    mkdir ${OPENSHIFT_RUNTIME_DIR}/fabric	
fi
	
echo "Copy Fuse Fabric distro to the OPENSHIT RUNTIME DIR"
cp -rf $TMPAREA/fabric $OPENSHIFT_RUNTIME_DIR 	
cp -rf $OPENSHIFT_REPO_DIR/diy/fabric $OPENSHIFT_RUNTIME_DIR

echo "Clean log files."
cd $OPENSHIFT_RUNTIME_DIR/fabric
rm -rf logs
ln -s $OPENSHIFT_LOG_DIR logs