#! /bin/sh
#_______________________________________________________________________________
#
# Bourne shell script : mkdistro
# ID : $Id: mkdistro,v 1.19 2000/10/29 08:44:56 lefevre Exp $
# Jean-Paul Le Fvre - August 2000
#_______________________________________________________________________________

src=$SOFT
admdir=$SOFT/JVS/adm
out=$SOFT/JVS/adm/liste~
red=/ker/src/redhat
dst=$red/SOURCES

if [ ! -f $src/JVS/lib/jvs.jar ]; then
    echo "Can't prepare distribution since jvs.jar is not there !"
    exit 1
fi

version=`java -cp $src/JVS/lib/jvs.jar org.demo.webwader.VersionInfo`

echo "Building a fresh distribution of the JVS version : $version !" | tee $out

s=webwader.spec
v=`fgrep -h "Version :" $s`
r=`fgrep -h "Release :" $s`
echo "File $s $v $r"

s=wadersrc.spec
v=`fgrep -h "Version :" $s`
r=`fgrep -h "Release :" $s`
echo "File $s  $v $r"

echo -n "Is it OK ? "
read answer
if [ "$answer" != "y" ]; then
    echo "Too bad ! "
    exit 1
fi

if [ -e $dst ]; then
    echo "Removing existing $dst files ..."
    /bin/rm -fr /tmp/JVS /tmp/webwader*
    /bin/rm -fr $dst/JVS $dst/src* $dst/webwader*
    /bin/rm -fr $red/BALLS/*
fi

cd $src

# Copy files except CVS, classes and temp.
echo "Copying to $dst ..."
find JVS -path "*CVS*" -prune -o -not \( -name "*.class" -o -name "*~" \) -print | cpio -pda $dst


# Remove any files generated by configure and the javadoc.
cd $dst/JVS
echo "Cleaning up ..."
rm -f  config.cache
export CLASSPATH=$dst/JVS/src
./configure >> $out 2>&1
make -s clean  >> $out 2>&1
rm -f  configure-full.in
rm -f  config.*
rm -fr doc/api/*

echo "Checking some files ..."
file=lib/jvs.jar
if [ ! -e $file ]; then
    echo "Missing file : $file !"
    exit 1
fi
file=bin/open_url.exe
if [ ! -e $file ]; then
    echo "Missing file : $file !"
    exit 1
fi
file=bin/activate.exe
if [ ! -e $file ]; then
    echo "Missing file : $file !"
    exit 1
fi
file=bin/print_url
if [ ! -e $file ]; then
    echo "Missing file : $file !"
    exit 1
fi

cd $dst
echo "Making the tarballs ..."
ball=webwader-$version
tar czf $red/BALLS/$ball.tgz JVS

zip -q -r $red/BALLS/$ball.zip JVS
echo " " >> $out
echo "Compressing the sources for nsi ..."
cd JVS
zip -q -r src.zip src
# Move zip upward temporarily.
mv src.zip ..

cd ..

echo "Preparing the rpm tarball ..."
tar czf $ball.tgz JVS

cd $admdir
echo "Building the binary RPM ..."
rpm -bb webwader.spec >> $out 2>&1
echo " " >> $out
echo "Building the source RPM ..."
rpm -ba wadersrc.spec  >> $out 2>&1

cd $dst
# Move zip back in JVS.
mv src.zip JVS
# Move JVS to my main partition to make it visible from Winsucks 98.
mv JVS /tmp
cp $red/BALLS/$ball.zip /tmp

cd $red
mv RPMS/noarch/webwader-*.noarch.rpm $red/BALLS/
mv SRPMS/webwader-*.src.rpm $red/BALLS/webwader-$version.src.rpm
echo 
du -sk $red/BALLS/*

echo "Done !"

#_______________________________________________________________________________


