#!/bin/sh

# script to automate releases

grep -q  '^TOP' .version
    res=$?
if test ! -f .version  || test $res != 0; then
    echo not in topleveldir
    exit 1
fi    

function setversion() {
eval `sed -n 's/^\([A-Z_]*\) *= *\(.*\)$/\1=\2/p' .version`
MJ=$TOPLEVEL_MAJOR_VERSION
MI=$TOPLEVEL_MINOR_VERSION
PA=$TOPLEVEL_PATCH_LEVEL 
MP=$TOPLEVEL_MY_PATCH_LEVEL
NEWVER=$MJ.$MI.$PA$MP
if [ -z $MP ]
then
    LASTVER=$MJ.$MI.`expr $PA - 1`
else
	LASTVER=$MJ.$MI.$PA
fi

echo
echo "Current  version ("`pwd`") is $NEWVER, Last version:  $LASTVER"
echo
}

heredir=`pwd`
make dist; 
setversion
LILYVER=$NEWVER

tarball=lilypond-$LILYVER.tar.gz
patch=patch-$LILYVER.gz
    
mv  $tarball ../releases

cd ../test
$heredir/bin/make_patch $LASTVER $NEWVER lilypond
gzip -f9 patch-$NEWVER
mv $patch ../patches/

RPMS=`find ~/rpms/ -name lilypond-$NEWVER'*'rpm`
rm *.rpm {lilypond,patch}-*.gz

if [ ! -z $RPMS ]; then
    ln $RPMS . 
fi
    
ln ../releases/$tarball .
ln ../patches/$patch .    


if [ ! -z $RPMS ]; then
    RPMS=lilypond-$LILYVER-1.i386.rpm lilypond-$LILYVER-1.src.rpm 
fi    
tar cf updeet $tarball $patch $RPMS
tar tfv updeet

