#!/bin/sh
#
#    Licensed to the Apache Software Foundation (ASF) under one
#    or more contributor license agreements.  See the NOTICE file
#    distributed with this work for additional information
#    regarding copyright ownership.  The ASF licenses this file
#    to you under the Apache License, Version 2.0 (the
#    "License"); you may not use this file except in compliance
#    with the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing,
#    software distributed under the License is distributed on an
#    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#    KIND, either express or implied.  See the License for the
#    specific language governing permissions and limitations
#    under the License.    
#
######################################################################
#
#  This script is used to build the JSPWiki nightly builds.
#  Assumptions: java and ant are available in the classpath. Also sha1 program is required.
#
#  Puts the resulting nightly src and bin build in your public_html/JSPWiki/nightly directory.
#

BUILDDIR=/tmp/jspwiki-nightly/
PUBLIC_HTML=$HOME/public_html/JSPWiki/

rm -rf ${BUILDDIR}
mkdir -p ${BUILDDIR}
cd ${BUILDDIR}
svn export http://svn.apache.org/repos/asf/incubator/jspwiki/trunk JSPWiki

cd JSPWiki
ant dist -Dbuild.properties=$HOME/Projects/jspwiki_nightly_build.properties

WIKIVER=`java -cp build/JSPWiki.jar org.apache.wiki.Release`

echo "Building release for JSPWiki $WIKIVER"

BUILDDATE=`date +%d%m%y`
DESTDIR=${PUBLIC_HTML}/nightly/
DESTBIN=jspwiki-${WIKIVER}-${BUILDDATE}-bin.zip
DESTSRC=jspwiki-${WIKIVER}-${BUILDDATE}-src.zip

mkdir -p ${DESTDIR}
rm -rf ${DESTDIR}/*
cp -a releases/JSPWiki-bin.zip ${DESTDIR}/${DESTBIN}
cp -a releases/JSPWiki-src.zip ${DESTDIR}/${DESTSRC}

cd ${DESTDIR}
ln -s ${DESTBIN} JSPWiki-latest.zip
sha1 < ${DESTBIN} > JSPWiki-bin-latest.sha1 
sha1 < ${DESTSRC} > JSPWiki-src-latest.sha1

jar xf ${DESTBIN}

mv JSPWiki/README JSPWiki/ReleaseNotes JSPWiki/ChangeLog . && rm -rf JSPWiki

chmod 755 *

rm -rf ${BUILDDIR}

