#
# Quick reference:  
# 
# pack-$NAME		: working area;
# pack-$NAME/BUILD	: place to use as DESTDIR
#
# This script is brought to you by "Slackware Jar Packaging Initiative" 
#
# Exit on most errors
set -e

NAME="junit"
CWD=${CWD:-`pwd`}
TMP=${TMP:-/tmp/txz}
VERSION=${VERSION:-4.7}
ARCH=${ARCH:-x86} 
TRY=${TRY:-1sjpi}
SOURCE=http://downloads.sourceforge.net/project/junit/junit/$VERSION/$NAME$VERSION.zip?use_mirror=garr

if [ ! -e $NAME$VERSION.zip ]; then
wget -c $SOURCE
fi


# MUST be root.
[ `whoami` != root ] && echo "You must be root. Exiting..." && exit 1

# cleaning 
rm -rf $TMP/pack-$NAME

# re-creating working area
mkdir -p $TMP/pack-$NAME/BUILD/install

# specific stuff (like upack under $TMP/pack-$NAME) goes there
unzip $NAME$VERSION.zip -d $TMP/pack-$NAME

mkdir -p $TMP/pack-$NAME/BUILD/{usr/{share/java,doc/$NAME-$VERSION}}

cp -R $TMP/pack-$NAME/$NAME$VERSION/{README.html,cpl-v10.html,doc,temp.hamcrest.source/LICENSE.txt} \
$CWD/$NAME.SlackBuild $TMP/pack-$NAME/BUILD/usr/doc/$NAME-$VERSION

cp $TMP/pack-$NAME/$NAME$VERSION/$NAME-$VERSION.jar \
$TMP/pack-$NAME/BUILD/usr/share/java/

cd $TMP/pack-$NAME/BUILD/usr/share/java
ln -sf $NAME-$VERSION.jar $NAME.jar

cp $CWD/slack-desc $TMP/pack-$NAME/BUILD/install

# building the package
cd $TMP/pack-$NAME/BUILD
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$TRY.txz