#! /bin/sh

. $JONAS_ROOT/bin/unix/config_env

SAMPLE_DIR=$JONAS_ROOT/examples/websample
CLASS_DIR=$JONAS_ROOT/examples/classes
JAR_DIR=$JONAS_ROOT/ejbjars
WEBAPPS=$JONAS_ROOT/webapps
JAVAC=javac

set -x

# compile bean classes and make the .jar file
cd $SAMPLE_DIR/beans/org/objectweb/secusb
$JAVAC -d $CLASS_DIR *.java
[ -d $CLASS_DIR/META-INF ] || mkdir -p $CLASS_DIR/META-INF
cp secusb.xml $CLASS_DIR/META-INF/ejb-jar.xml
cp jonas-secusb.xml $CLASS_DIR/META-INF/jonas-ejb-jar.xml
cd $CLASS_DIR
jar -cvf org/objectweb/secusb/secusb.jar META-INF/ejb-jar.xml META-INF/jonas-ejb-jar.xml org/objectweb/secusb/*.class

# deploy the bean and install it
cd $SAMPLE_DIR
GenIC -d $CLASS_DIR -javac $JAVAC -keepgenerated -secpropag $CLASS_DIR/org/objectweb/secusb/secusb.jar
cp $CLASS_DIR/org/objectweb/secusb/secusb.jar $JAR_DIR

# compile servlet
cd $SAMPLE_DIR/src/org/objectweb/websample
$JAVAC -d $CLASS_DIR *.java

# make the .war file
[ -d $WEBAPPS/websample/WEB-INF/classes ] || mkdir -p $WEBAPPS/websample/WEB-INF/classes
[ -d $WEBAPPS/websample/WEB-INF/lib ] || mkdir -p $WEBAPPS/websample/WEB-INF/lib
cd $CLASS_DIR
find org/objectweb/websample -name "*.class" -print | cpio -pmvdu $WEBAPPS/websample/WEB-INF/classes
cd $SAMPLE_DIR
cp etc/web.xml $WEBAPPS/websample/WEB-INF
find lib -name "*.jar" -print | cpio -pmdvu $WEBAPPS/websample/WEB-INF
cp $JAR_DIR/secusb.jar $WEBAPPS/websample/WEB-INF/lib
cd web; find . ! -name *~ ! -name Makefile -print | cpio -pmdvu $WEBAPPS/websample
cd $WEBAPPS/websample; jar cvf $WEBAPPS/websample.war .

# install the .war file on tomcat
echo "You must install now your application in the tomcat webapps directory, for example:"
echo "rm -rf <TOMCAT_HOME>/webapps/websample"
echo "cp $WEBAPPS/websample.war <TOMCAT_HOME>/webapps"
cd $HERE

echo "cp apps-websample.xml <TOMCAT_HOME>/conf"
