#!/bin/bash
#
# Make and upload linux RPMs for Lesstif
# jac July 2, 1998
#

usage(){
    echo "This will not work for anyone but core team members, so don't bother trying."
    echo ""
    echo "If you modify this script to try to get it to work, it will still fail,"
    echo "and generate a mail message which will go out to the whole lesstif list"
    echo "and waste everyone's time, because it'll be a bogus message, and will"
    echo "only serve to announce to the world that you're an idiot."
    echo ""
    echo "This script doesn't do what you think it does anyway, so if you"
    echo "thought you needed to run it, you're wrong."
    exit 1
}

if test "$LOGNAME" != "jon"
then
   usage;
fi

eval `grep "^MAJOR_VERSION=" configure.in`
eval `grep "^MINOR_VERSION=" configure.in`
eval `grep "^PICO_VERSION=" configure.in`
Release=$MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION

if test "$Release" = ".."
then
   usage;
fi

echo '######################################################################'
echo " Making rpms for release $Release for $0"
echo '######################################################################'

# get current source tree and put in /usr/src/redhat/SOURCES
ftp ftp.hungry.com <<-EOF
bin
hash
cd /usr/ftp/pub/hungry/lesstif/srcdist
dir
lcd /usr/src/redhat/SOURCES
get lesstif-$Release.tar.gz 
bye
EOF

# # Make the RPM's
rpm -ba scripts/RedHat/lesstif.spec
if [ $? -ne 0 ] 
then
   echo '######################################################################'
   echo ' Error building RPMs'
   echo '######################################################################'
   exit
fi

echo '######################################################################'
echo " Uploading rpms for release $Release for $0"
echo '######################################################################'

# Put the rpms on the ftp server
ftp ftp.hungry.com <<-EOF
bin
hash
prompt
cd /usr/ftp/pub/hungry/lesstif/bindist
lcd /usr/src/redhat/SRPMS
mput lesstif-*
lcd /usr/src/redhat/RPMS/i386
mput lesstif-*
bye
EOF

#
# temp: check if FTP ok?
#
#echo '######################################################################'
#echo "Did the file transfer go ok?  Send the announcement? (^C if no)"
#echo '######################################################################'
#read a

#
# Tell the world about it.
#
# FIXME: ftp apparently always returns 0.  How can I check to see if the
# files were really transferred?
#
if [ $? -eq 0 ] 
then 
mail -s "LessTif $Release Linux RPMs" lesstif@hungry.com <<-EOF 
The RPMs for LessTif $Release for Linux have just been uploaded to

       ftp.lesstif.org:/pub/hungry/lesstif/bindist/

Jon Christopher
Lesstif Releasemeister
EOF
	echo "rpm ftp okay"
else
	echo "rpm ftp problem"
fi

# clean up
/bin/rm -rf /usr/src/redhat/SOURCES/lesstif-$Release.tar.gz
/bin/rm -rf /usr/src/redhat/SRPMS/lesstif-*
/bin/rm -rf /usr/src/redhat/RPMS/i386/lesstif-*
/bin/rm -rf /usr/src/redhat/BUILD/lesstif-*

echo '######################################################################'
echo " Done making and uploading rpms for release $Release for $0"
echo '######################################################################'


