#!/bin/sh

export JAVA_HOME=/opt/j2sdk1.4.2

cd /home/jon/files/bodbuild/bodington_2_1

echo Packing up tomcat installation files into a Zip archive
rm -R /home/jon/files/bodbuild/bodington_2_1/tmpbuild

mkdir tmpbuild

echo Filtering standard Tomcat files to temp area
cp -R --preserve=timestamps jakarta-tomcat-5.0.19/* tmpbuild
RETVAL=$?
[ $RETVAL -ne 0 ] && exit 1

echo Filtering in bodington additional files from Bodington build directory
cp -R --preserve=timestamps tomcatadd/* tmpbuild
RETVAL=$?
[ $RETVAL -ne 0 ] && exit 1

echo Filtering in shibboleth additional files
cp -R --preserve=timestamps shibadd/* tmpbuild
RETVAL=$?
[ $RETVAL -ne 0 ] && exit 1

echo removing CVS directories from temp area
find tmpbuild -name CVS -exec rm -fR \{\} \;
[ $RETVAL -ne 0 ] && exit 1

echo removing CVS backup files from temp area
find tmpbuild -name '*.#*' -exec rm -f \{\} \;
[ $RETVAL -ne 0 ] && exit 1

echo removing .thingy files from temp area
find tmpbuild -name '.*' -exec rm -f \{\} \;
[ $RETVAL -ne 0 ] && exit 1


echo Adding Bodington files to the Zip archive from the temp area
cd tmpbuild
RETVAL=$?
[ $RETVAL -ne 0 ] && exit 1

$JAVA_HOME/bin/jar c0Mf ../src/bodington.zip .
RETVAL=$?
[ $RETVAL -ne 0 ] && exit 1

cd ..


echo Packing Install.class and bodington.zip into Install.jar with manifest
cd src
$JAVA_HOME/bin/jar c0mf ../install.mf ../install.jar org/bodington/installation/Install.class bodington.zip
RETVAL=$?
[ $RETVAL -ne 0 ] && exit 1

cd ..

echo Packing up web application into bodington.war
cd tmpbuild/webapps/bodington
$JAVA_HOME/bin/jar -cf ../../../bodington.war *
cd ../../..
echo completed build

echo removing temp build files
rm src/bodington.zip
rm -R /home/jon/files/bodbuild/bodington_2_1/tmpbuild
