#! /bin/sh
# set -x
# $Id: make_release.sf,v 1.79 2006/06/10 09:31:20 dannybackx Exp $
#
# This is a script to build a new release of LessTif, including updating the
# docs, website and uploading the source archives to ftp.hungry.com.
#
# It works for our new CVS repository on sourceforge.net (SF), but it should
# be straightforward to adjust it for any other CVS repository. 
#
# I've attempted to make it restartable through a shell script
#	./make_release.status which is created by running this script.
# An optimization that comes to mind is to have make_release.sf
# decide when to accept the stuff in there and when not, e.g. based
# on the version numbers you're trying to build.
# I've decided *against* such functionality. A script that runs stupid
# things for you is good, one that tries to outsmart you is a disaster.
#
#
# ********************  I N S T R U C T I O N S  *******************************
#
#
# Prerequisite is a working copy of the CVS tree which is already
# configured with "--enable-maintainer-mode".
# CVS must be configured in batch mode, i.e. no prompting for
# either read or write access!
# This script itself requires the following tools:
# (including standard un*x stuff, but the list may be useful on other systems)
#   - GNU automake, autoconf, libtool packages and m4
#   - Secure Shell clients: ssh and scp
#   - cvs
#   - bzip2, cat, chmod, cmp, cp, gzip, mv,
#     rm, sed, sleep, tail, tar, test
#   - (properly configured!) inews and mail clients
#     to submit the announcements
#
#
# 0) From a CVS working copy verify that "make check" and
#    "make distcheck" succeed!
#  
# 1) From your normal working copy do a "make changelog" from the toplevel.
#    This will regenerate the 'ChangeLog' file with all of the
#    changes from the previous release to the current release.
#    Involved in this process are scripts (e.g. 'scripts/parselog') which
#    require perl to be installed. In detail they may look for "/usr/bin/perl".
#    After a series of private test releases you may want to generate
#    a 'ChangeLog' WRT the latest official release. To do so
#    just execute the commandline given in the Makefile but 
#    specify the last even-pico (=official) release.
# 
# 2) Also change (increase) the *_VERSION numbers in the toplevel
#    'configure.in' file (also 'test/configure.in') and
#    edit the 'scripts/mail_announcement' file as you see fit
#
# 3) Commit your changes (all files created/modified as outlined above).
#    Make sure your local tree does not contain other changes which might
#    get committed by accident now!
#    (e.g. use "cvs commit configure.in test/configure.in ChangeLog")
# 
# The next steps involve many remote CVS & ssh operations.
# You need to have done a "cvs login" (using your core-team account)
# from the current account to enable CVS write access.
#
# 4) Create a new, empty directory - since this dir may contain
#    temporary stuff at the end of this job.
#    Also ensure that you have sufficient free disk space, since
#    we may need about 75MB currently!
#
# 5) Copy a recent version of the 'make_release.sf' script to this directory.
#    ('~ltiff/src/lesstif-current/scripts/make_release.sf' is a good
#     starting point if being on terror, otherwise pick up a copy from your
#     local CVS tree)
#
# 6) Execute "./make_release.sf"
#    and
#    Sit back, Relax, this will take a while.....
#    Rough guess is 30 min, but it strongly depends on the network
#    connections to the Sourceforge and hungry sites and
#    the performance of your machine as well.
#
# **************************** End of Instructions *****************************


# Initialize status variable
PASSED=yes

# Try to switch to an English language environment.
# This is required e.g. for 'date' commands issued below. 
# Note that using a non-english language version may cause
# invalid HTML being generated and some other bad things!
LANG=C
export LANG


RESTARTED=0
STATUS="make_release.status"

if test -f $STATUS
then
	RESTARTED=1
#
# Read the status from restart
#
	. $STATUS

	if test $RESTARTED -ne 0
	then
		echo "This is a restart run of $0, previous level was $RESTARTED."
		echo "Interrupt NOW to abort (4s)"
		sleep 4
	fi
fi

if test $RESTARTED -ge 1
then
	echo "Skip level 0 tests ..."
else

if test $RESTARTED -eq 0
then
# Check if we are in a clean directory
  if test -f mail_announcement || test -f ann_body  || test -f usenet_ann || test -f lesstif.docs
  then
	echo "Please run this script in an empty directory only. Exiting"
	exit 1
  fi
fi

      
# Check for availability of some utilities
# We check for those which may be non-standard 
# (or the user may want to select specific ones)

bzip2_=`which bzip2`
if test -x "$bzip2_"
then
	  BZIP2cmd="$bzip2_"
#          echo "bzip2cmd=$BZIP2cmd"
else
	echo "No bzip2 available. Exiting"
	exit 1
fi

CVS_=`which cvs`
if test -x "$CVS_"
then
# -Q flag is to avoid some "stupid" questions asked by cvs
	CVScmd="$CVS_ -Q -z9"
#	echo "CVScmd=$CVScmd"
else
	echo "No cvs client available. Exiting"
	exit 1
fi

# ftp batch interface (from ncftp 3.x package)
FTP_=`which ncftpput`
if  test -x "$FTP_"
then
	NCFTPPUTcmd=$FTP_
else
	NCFTPPUTcmd=""
	echo "No ncftpput available. Exiting"
	exit 1
fi

# GNU zip
GZIP_=`which gzip`
if test -x "$GZIP_"
then
	GZIPcmd="$GZIP_"
#	echo "GZIPcmd=$GZIPcmd"
else
	echo "No gzip available. Exiting"
	exit 1
fi

# Post messages to Usenet
INEWS_=`which inews`
if  test -x "$INEWS_"
then
	INEWScmd=$INEWS_
#	echo "INEWScmd=$INEWScmd"
else
	INEWScmd=""
	echo "No inews available. Continuing"
fi

# autoconf hardcodes in the path to m4 from the time it was 
# configured!!!! To override it we have to do this????
M4_=`which m4`
if test -x "$M4_"
then
	M4="$M4_"
	export M4
else
	echo "No M4 processor found. Exiting"
	exit 1
fi

# Simple/standard mail client
MAIL_=`which mail`
if  test -x "$MAIL_"
then
	MAILcmd=$MAIL_
#	echo "MAILcmd=$MAILcmd"
else
	MAILcmd=""
	echo "No mail available. Exiting"
	exit 1
fi

# secure copy from SSH package
SCP_=`which scp`
if  test -x "$SCP_"
then
	SCPcmd="$SCP_ -q -C"
#	echo "SCPcmd=$SCPcmd"
else
	echo "No scp available. Exiting"
	exit 1
fi

# Secure Shell
SSH_=`which ssh`
if  test -x "$SSH_"
then
	SSHcmd="$SSH_"
#	echo "SSHcmd=$SSHcmd"
else
	echo "No ssh available. Exiting"
	exit 1
fi

#
# Take record of current directory
#
HERE=`pwd`
#
# Do some sanity checks before we get too far.....
#
if [ -z ${USER} ]
then
    echo "Sorry I need \$USER set so I know who you are"
    exit 1
fi

# Translate common local usernames to those on the
# external sites

if test ${USER} = "mai"
then
    CVS_USER="amai"
    HUNGRY_USER="amai"
    SF_USER=$CVS_USER
else if test ${USER} = "danny"
then
    CVS_USER="dannybackx"
    HUNGRY_USER=$USER
    SF_USER=$CVS_USER    
else
    CVS_USER=$USER
    HUNGRY_USER=$USER
    SF_USER=$CVS_USER
fi
fi

fi	# Restart

# A friendly "Welcome"!
echo "Hello $USER on `uname -n`!"
echo "You are known as '$SF_USER' on SF, '$CVS_USER' on cvs and as '$HUNGRY_USER' on hungry."

if test $RESTARTED -lt 20
then
#
# An interactive check to prevent the user from erroneously
# executing this script!
#
  echo ""
  echo "Have you created a new ChangeLog, updated (test/)configure.in and scripts/mail_announcement? (y/n)"
  read answer

  if test $answer = "y"
  then
	echo "Ok, we go ahead!"
  else
	echo "We better stop here!"
	exit 1
  fi

#
# Save status in case of restart.
# Requires updates if you introduce any new variable which needs to be saved!!
#
echo "#! /bin/sh"                    >$STATUS
echo 'LANG="'$LANG'"'               >>$STATUS
echo 'PATH="'$PATH'"'               >>$STATUS
echo 'BZIP2cmd="'$BZIP2cmd'"'       >>$STATUS
echo 'CVScmd="'$CVScmd'"'           >>$STATUS
echo 'GZIPcmd="'$GZIPcmd'"'         >>$STATUS
echo 'INEWScmd="'$INEWScmd'"'       >>$STATUS
echo 'M4="'$M4'"'                   >>$STATUS
echo 'MAILcmd="'$MAILcmd'"'         >>$STATUS
echo 'SCPcmd="'$SCPcmd'"'           >>$STATUS
echo 'SSHcmd="'$SSHcmd'"'           >>$STATUS
echo 'USER="'$USER'"'               >>$STATUS
echo 'CVS_USER="'$CVS_USER'"'       >>$STATUS
echo 'HUNGRY_USER="'$HUNGRY_USER'"' >>$STATUS
echo 'SF_USER="'$SF_USER'"'         >>$STATUS
echo 'NCFTPPUTcmd="'$NCFTPPUTcmd'"' >>$STATUS
echo 'HERE="'$HERE'"'         >>$STATUS
# echo 'TAR="'$TAR'"' >>$STATUS

#
# Update progress
#
RESTARTED=20
echo 'RESTARTED='$RESTARTED >>$STATUS
fi

#
# This root should fail for anyone but core members, which is good!!!
#
CVSROOT=$CVS_USER@lesstif.cvs.sourceforge.net:/cvsroot/lesstif ; export CVSROOT
echo "Using CVSROOT=$CVSROOT"

if test $RESTARTED -lt 30
then
cd $HERE
echo "Doing some checks on behalf of ${USER}"

# Extract version numbers
if $CVScmd checkout -l lesstif/configure.in \
                       lesstif/scripts/make_release.sf \
                       lesstif/scripts/mail_announcement \
                       lesstif/scripts/ann_header
then
    if [ -f lesstif/configure.in ]
    then
	MAJOR_VERSION=`egrep "^define" lesstif/configure.in | egrep LESSTIF_MAJOR_VERSION | \
		awk -F'[' '{print $3;}' | awk -F']' '{print $1;}'`
	MINOR_VERSION=`egrep "^define" lesstif/configure.in | egrep LESSTIF_MINOR_VERSION | \
		awk -F'[' '{print $3;}' | awk -F']' '{print $1;}'`
        PICO_VERSION=`egrep "^define" lesstif/configure.in | egrep LESSTIF_PICO_VERSION | \
                awk -F'[' '{print $3;}' | awk -F']' '{print $1;}'`

	if [ 0 -ne `expr $PICO_VERSION % 2` ]
	then
#       Versions with odd PICO number are inofficial and/or
#       for testing purposes only
		echo "Doing an odd-numbered (test) release: $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION"
		EvenPico=no
	else
		echo "Doing a public release: $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION"
		EvenPico=yes	
	fi
    else
	echo "Can't co configure.in for a sanity check"
	PASSED=no
	exit 1
    fi
else
    echo "Can't co configure.in for sanity checks"
    PASSED=no
    exit 1
fi

# Check if using a recent version of this script
if [ -f lesstif/scripts/make_release.sf ]
then
    if ! cmp -s $0 lesstif/scripts/make_release.sf
    then
	cp lesstif/scripts/make_release.sf ./make_release.sf.new
	echo "You are trying to use an old copy of make_release.sf"
	echo "There is a new copy at ./make_release.sf.new"
	echo "You can overwrite your version by the new version with:"
	echo "mv ./make_release.sf.new $0"
	echo ""
	echo "Do you want to continue anyway (y/n)?"
	read answer
	if test $answer = "y"
	then
	    echo "Continuing"
	else
	    echo "We stop here!"
	    exit 1
	fi
    fi
else
    echo "Can't find make_release.sf"
    PASSED=no
    exit 1
fi

#
# Update progress
#
RESTARTED=30
echo 'RESTARTED='$RESTARTED >>$STATUS
echo 'MAJOR_VERSION='$MAJOR_VERSION >>$STATUS
echo 'MINOR_VERSION='$MINOR_VERSION >>$STATUS
echo 'PICO_VERSION='$PICO_VERSION >>$STATUS
echo 'EvenPico="'$EvenPico'"' >>$STATUS
echo 'PASSED="'$PASSED'"'     >>$STATUS

#
# End of "RESTARTED -lt 30" processing
#
fi

if test $RESTARTED -lt 40
then
cd $HERE

# Pick up the mail announcement text
if [ -f lesstif/scripts/mail_announcement ]
then
    if ! cp lesstif/scripts/mail_announcement .
    then
	echo "Can't copy mail_announcement into current directory"
	PASSED=no
	exit 1
    else
        chmod 660 mail_announcement
    fi
else
    echo "Can't find mail_announcement"
    PASSED=no
    exit 1
fi

# Get header for Usenet posting
if [ -f lesstif/scripts/ann_header ]
then
    if ! cp lesstif/scripts/ann_header .
    then
	echo "Can't copy announcement header into current directory"
	PASSED=no
	exit 1
    else
        chmod 660 ann_header
    fi
else
    echo "Can't find ann_header"
    PASSED=no
    exit 1
fi



# Names of the source archives to be created
# The compressed ones will be uploaded
TARarchive="lesstif-$MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION.tar"
TGZarchive="$TARarchive.gz"
TB2archive="$TARarchive.bz2"
# TZIParchive="$TARarchive.zip"
# Path to lesstif ftp dir on ftp.hungry.com
FTPPATH="/var/ftp/pub/hungry/lesstif/srcdist"

# echo "Check for specific release on terror (and write access)"
# touch test
# if ! ($SCPcmd test $HUNGRY_USER@terror.hungry.com:$FTPPATH \
#       && $SSHcmd -l $HUNGRY_USER terror.hungry.com chgrp lesstifdev $FTPPATH/test \
#       && $SSHcmd -l $HUNGRY_USER terror.hungry.com rm $FTPPATH/test)
# then
#    echo "Can't scp into srcdist directory"
#    PASSED=no
#    exit 1
# else
#    if $SSHcmd -l $HUNGRY_USER terror.hungry.com test -f "$FTPPATH/$TGZarchive"
#    then
#       echo "release is already present on terror"
#       echo "Try to use the following command to get rid of it:"
#       echo "ssh terror.hungry.com rm $FTPPATH/$TGZarchive"
#       passed=no
#       exit 1
#     fi
# fi
# rm -f test

#
# Update progress
#
RESTARTED=40
echo 'RESTARTED='$RESTARTED       >>$STATUS
echo 'TARarchive="'$TARarchive'"' >>$STATUS
echo 'TGZarchive="'$TGZarchive'"' >>$STATUS
echo 'TB2archive="'$TB2archive'"' >>$STATUS
echo 'FTPPATH="'$FTPPATH'"'       >>$STATUS
echo 'PASSED="'$PASSED'"'     >>$STATUS

#
# End of "RESTARTED -lt 40" processing
#
fi


if test $RESTARTED -lt 50
then
cd $HERE

#
# Clean up the mess from the checks
#
#rm -rf ./lesstif
rm -f lesstif/configure.in \
	lesstif/scripts/make_release.sf \
	lesstif/scripts/mail_announcement \
	lesstif/scripts/ann_header

# The commands so far are 'safe' - you can run this part simply
# for debugging purposes.
# Commands below involve CVS modifications and sending messages

#
# Warn other core-team members!
#
echo "Sending a warning to LessTif core team"
$MAILcmd -s "New LessTif release $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION is being built!" \
     lesstif-core@lists.sourceforge.net </dev/null >/dev/null
echo "Wait two minutes until message has been delivered ..."
sleep 120
echo "Continuing ..."

#
# Now prepare the docs, update HTML documents, etc.
#
# set +e
# umask 002

echo " "
echo "Creating LessTif Release, Version $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION"
echo " "
echo "Updating CURRENT_NOTES.html, ReleaseNotes.html"
echo " "


# Check for test releases
if [ $EvenPico = "yes" ]
then
  echo "Updating docs for release $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION"
else
  echo "We don't update the docs for an odd-PICO (i.e. testing) release"
fi
	
echo "Updating the WWW docs"
FILES="lesstif/ReleaseNotes.html \
       lesstif/CURRENT_NOTES.html \
       lesstif/doc/www.lesstif.org/index.html \
       lesstif/doc/www.lesstif.org/download.html \
       lesstif/doc/www.lesstif.org/versions.html"

if $CVScmd checkout -l $FILES
then
    echo "	checkout OK"
else
    echo "	checkout FAILED"
    exit 1
fi
#
# Update progress
#
RESTARTED=50
echo 'RESTARTED='$RESTARTED >>$STATUS

#
# End of "RESTARTED -lt 50" processing
#
fi

if test $RESTARTED -lt 60
then
cd $HERE
#
# Update ReleaseNotes.html from CURRENT_NOTES.html
#
SOURCE='lesstif/doc/www.lesstif.org'
if (cd $SOURCE/../.. && \
    echo "<h2>Release $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION (`date '+%B %e, %Y'` ${USER})</h2>" >> CURRENT_NOTES_$$ && \
    tail +6 CURRENT_NOTES.html >> CURRENT_NOTES_$$ && \
    sed -e "/<\!-- make_release -->/r CURRENT_NOTES_$$" ReleaseNotes.html >$$ && \
    rm CURRENT_NOTES_$$ && \
    mv $$ ReleaseNotes.html)
then
    echo "	ReleaseNotes.html OK"
else
    rm -f $$
    echo "	Creating ReleaseNotes.html FAILED"
    exit 1
fi

#
# Create new CURRENT_NOTES.html TEMPLATE
#
if cat <<-EOF >$$ && mv $$ $SOURCE/../../CURRENT_NOTES.html
<html>
<!-- Do not change the first five lines of this file,
     the automatic documentation update depends on them -->
<h2>Relevant notes since Release $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION</h2>
<!-- Ok to change after this line -->
<hr size=5>
<ul>
<li> Nothing to report yet. <!-- Replace this line -->
</ul>
<hr size=5>
EOF

then
    echo "	CURRENT_NOTES.html OK"
else
    rm -f $$
    echo "	Creating CURRENT_NOTES.html FAILED"
    exit 1
fi

#
# Update versions.html
#
cd $HERE
if (cd $SOURCE && sed -e "/<TR><TD> Version $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION <\/TD><TD>/d" -e "/<\!-- <TR><TD> Version/i\\
<TR><TD> Version $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION </TD><TD> `date '+%B %e, %Y'` </TD></TR>
" versions.html >$$ && \
    mv $$ versions.html)
then
    echo "	versions.html OK"
else
    rm -f $$
    echo "	versions.html FAILED"
    exit 1
fi

#
# Update download.html
#
cd $HERE
if (cd $SOURCE && sed -e "/<\!-- make_release start -->/,/<\!-- make_release end -->/{s/^[0-9]*\.[0-9][0-9]*\..*$/$MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION/g
/available since/c\\
It has been available since `date '+%B %e, %Y'`.
}" download.html >$$ && mv $$ download.html)
then
    echo "	download.html OK"
else
    rm -f $$
    echo "	download.html FAILED"
    exit 1
fi

#
# Home page (index.html) update 
#
cd $HERE
if (cd $SOURCE && 
    sed -e "/<\!-- make_release start -->/,/<\!-- make_release end -->/{s/^[0-9]*\.[0-9][0-9]*\..*$/$MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION/g
/as of/c\\
as of `date '+%B %e, %Y'`.
}" index.html >$$ && mv $$ index.html)
then
    echo "	index.html OK"
else
    rm -f $$
    echo "	index.html FAILED"
    exit 1
fi

if [ $EvenPico = "yes" ]
then
  if $CVScmd commit -m "Web docs update" lesstif
  then
      echo "	commit OK"
  else
      echo "	commit FAILED"
      exit 1
  fi
  # Remove tree
  rm -rf ./lesstif
else
  echo "We do not commit updates for an odd-PICO release!"
  # Keep tree for debugging purposes
  mv lesstif lesstif.docs
fi

if $CVScmd release -d lesstif
then
  echo "	release OK"
else
  echo "	release FAILED"
  exit 1
fi


# Tagging the CVS tree
echo "Tagging the tree with: release_${MAJOR_VERSION}_${MINOR_VERSION}_${PICO_VERSION}"
cd $HERE
if $CVScmd rtag -F release_${MAJOR_VERSION}_${MINOR_VERSION}_${PICO_VERSION} lesstif
then
    echo "Done."
else
    echo "Failed"
    exit 1
fi
echo

#
# Update progress
#
RESTARTED=60
echo 'RESTARTED='$RESTARTED >>$STATUS

#
# End of "RESTARTED -lt 60" processing
#
fi

if test $RESTARTED -lt 70
then
cd $HERE

#
# Now get a local working copy from CVS and prepare it for release
#

# Checking out is a time-consuming task ...
if test -f lesstif/CVS/Tag
then
	echo "Continuing to check out release_${MAJOR_VERSION}_${MINOR_VERSION}_${PICO_VERSION}"
	cd lesstif
	if $CVScmd -d$CVSROOT update -r release_${MAJOR_VERSION}_${MINOR_VERSION}_${PICO_VERSION} lesstif -d -P
	then
	    echo "Done."
	else
	    echo "Failed"
	    exit 1
	fi
	cd ..
else
	echo "Checking out tag: release_${MAJOR_VERSION}_${MINOR_VERSION}_${PICO_VERSION}"
	if $CVScmd -d$CVSROOT checkout -r release_${MAJOR_VERSION}_${MINOR_VERSION}_${PICO_VERSION} lesstif
	then
	    echo "Done."
	else
	    echo "Failed"
	    exit 1
	fi
fi
echo

#
# Update progress
#
RESTARTED=70
echo 'RESTARTED='$RESTARTED >>$STATUS

#
# End of "RESTARTED -lt 70" processing
#
fi

if test $RESTARTED -lt 80
then
# A default configure run has to succeed on the system used for this!
echo "Running CVSMake, configuring and making a distribution"
cd $HERE
if (cd lesstif && ./CVSMake && ./configure && make dist)
then
    echo "Done."
else
    echo "Failed"
    exit 1
fi
echo

#
# Update progress
#
RESTARTED=80
echo 'RESTARTED='$RESTARTED >>$STATUS

#
# End of "RESTARTED -lt 80" processing
#
fi

if test $RESTARTED -lt 81
then
#
# Build another version of the package
#

#(cd lesstif && $GZIPcmd -d -c $TGZarchive > $TARarchive)
#if ! (cd lesstif && $BZIP2cmd -9zc $TARarchive > $TB2archive)
# Don't waste resources by first extracting to a tar archive again.
# 
if ! (cd lesstif &&  $GZIPcmd -dc $TGZarchive | $BZIP2cmd -9zc > $TB2archive )
then
  echo "Can not create bzip2 archive. Exiting"
  exit 1
fi

#
# Update progress
#
RESTARTED=81
echo 'RESTARTED='$RESTARTED >>$STATUS

#
# End of "RESTARTED -lt 81" processing
#
fi

#
# Phase 82 : create an autopackage
#
if test $RESTARTED -lt 82
then
cd $HERE
#
# Is the command available ?
#
	MAKEINSTALLER_=`which makeinstaller`
	if  test -x "$MAKEINSTALLER_"
	then
		MIcmd="$MAKEINSTALLER_ -c"
		if (cd $HERE/lesstif && $MIcmd)
		then
		    UPLOADFILES="$UPLOADFILES $lesstif-$MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION.x86.package"
		    echo "	autopackage creation OK"
		else
		    echo "	autopackage creation FAILED"
		    exit 1
		fi
	else
		echo "No autopackage makeinstaller available. Skipping this phase."
	fi
fi
#
# Update progress
#
RESTARTED=82
echo 'RESTARTED='$RESTARTED >>$STATUS
echo 'PASSED="'$PASSED'"'     >>$STATUS
echo 'UPLOADFILES="'$UPLOADFILES'"'     >>$STATUS

#
# End of "RESTARTED -lt 82" processing
#

#
# Phase 83 : create RPMs
#
if test $RESTARTED -lt 83
then
#
# Is the command available ?
#
	RPM_=`which rpmbuild`
	if  test -x "$RPM_"
	then
		cd $HERE/lesstif
		RPMcmd="rpmbuild -ba scripts/RedHat/lesstif.spec"
		if (rm -f /usr/src/RPM/SOURCES/lesstif-$MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION.tar.gz  \
			&& ln -s $HERE/lesstif/lesstif-$MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION.tar.gz /usr/src/RPM/SOURCES  \
			&& cd $HERE/lesstif \
			&& $RPMcmd)
		then
			for i in /usr/src/RPM/RPMS/*/lesstif-$MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION*.rpm /usr/src/RPM/SRPMS/lesstif-$MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION*.src.rpm
			do
			    UPLOADFILES="$UPLOADFILES $i"
			done
		    echo "	RPM creation OK"
		else
		    echo "	RPM creation FAILED"
		    exit 1
		fi
	else
		echo "No rpmbuild available. Skipping this phase."
	fi
fi
#
# Update progress
#
RESTARTED=83
echo 'RESTARTED='$RESTARTED >>$STATUS
echo 'PASSED="'$PASSED'"'     >>$STATUS
echo 'UPLOADFILES="'$UPLOADFILES'"'     >>$STATUS

#
# End of "RESTARTED -lt 83" processing
#

if test $RESTARTED -lt 90
then
#
# Now transfer things to the right place
#

echo "Transfer source archives to SF's upload directory"

cd lesstif
#
# Send files ...
#
for i in $TGZarchive $TB2archive $UPLOADFILES
do
	$NCFTPPUTcmd -p $SF_USER@users.sourceforge.net upload.sourceforge.net /incoming $i
# Send a reminder to the uploader to process the uploads
	echo "Please register $i at SF.net"
done
cd ..

#
# Update progress
#
RESTARTED=90
echo 'RESTARTED='$RESTARTED >>$STATUS
echo 'PASSED="'$PASSED'"'     >>$STATUS

#
# End of "RESTARTED -lt 90" processing
#
fi

# #
# # Phase 81 : create an autopackage
# #
# if test $RESTARTED -lt 81
# then
# 
# fi
# #
# # Update progress
# #
# RESTARTED=81
# echo 'RESTARTED='$RESTARTED >>$STATUS
# echo 'PASSED="'$PASSED'"'     >>$STATUS
# 
# #
# # End of "RESTARTED -lt 81" processing
# #
# 

#
# Tell the world
#
echo

# Preparing the announcements

# Make sure that _NO_ moderated newsgroups are included in the
# groups list!! This will cause the message to be delayed at best -
# but dropped in more realistic scenarios ...
# Especially *.announce groups are likely to be moderated and therefore
# should be avoided.

if test $RESTARTED -lt 99
then

sed -e "s/MAJOR_VERSION/$MAJOR_VERSION/" \
    -e "s/MINOR_VERSION/$MINOR_VERSION/" \
    -e "s/PICO_VERSION/$PICO_VERSION/"     <./mail_announcement >ann_body

# Automatically list the correct versions of the auto* tools being used
# in the announcement:
lesstif/scripts/LTsysinfo >>ann_body

sed -e "s/MAJOR_VERSION/$MAJOR_VERSION/" \
    -e "s/MINOR_VERSION/$MINOR_VERSION/" \
    -e "s/PICO_VERSION/$PICO_VERSION/"     <./ann_header >usenet_ann

cat   ann_body >>usenet_ann
chmod 660 ann_body
chmod 660 usenet_ann


if [ $PASSED = "yes" ]
then
# Don't "cd lesstif", this will leave us in the wrong dir for the ./mail_...

#   We need to do the update -A before we edit the PICO_VERSION to get rid
#   of the "sticky tags". Otherwise any new commits will fail.
    echo "Updating local tree"
    cd lesstif && $CVScmd update -A ; cd ..

    echo "Bumping up version numbers"
    if [ $EvenPico = "yes" ]
    then

	sed -e "s/^PICO_VERSION=[0-9]*/PICO_VERSION=`expr $PICO_VERSION + 1`/" \
	    -e "s/^LAST_MAJOR_VERSION=[0-9]*/LAST_MAJOR_VERSION=$MAJOR_VERSION/" \
	    -e "s/^LAST_MINOR_VERSION=[0-9]*/LAST_MINOR_VERSION=$MINOR_VERSION/" \
	    -e "s/^LAST_PICO_VERSION=[0-9]*/LAST_PICO_VERSION=$PICO_VERSION/" \
	     lesstif/configure.in >$$ \
          && mv $$ lesstif/configure.in \
	  && (cd lesstif && $CVScmd commit -m "PICO_VERSION update by make_release" configure.in)

  	sed -e "s/^PICO_VERSION=[0-9]*/PICO_VERSION=`expr $PICO_VERSION + 1`/" lesstif/test/configure.in >$$ \
          && mv $$ lesstif/test/configure.in \
	  && (cd lesstif/test && $CVScmd commit -m "PICO_VERSION update by make_release" configure.in)

        echo "Doing some announcements"

       #
       # send to newsgroups
       #

       if test "x$INEWScmd" = "x"
       then
          echo "No usenet announcement will be made! (no inews command found)"
       else
          echo "Posting to Usenet"
          $INEWScmd -h <usenet_ann
       fi

       #
       # mail to some folks
       #

         echo "Mail to some folks"
       # Whom not to mail:
       #  - netbsd announce: netbsd people are NOT interested as they told us
       #  - freshmeat.net : must be done with the web interface, but they're working
	#	on integration with SourceForge.net
	#

       # The interested ones ...
       # LessTif list
        $MAILcmd -s "LessTif Release $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION is out" lesstif-discuss@lists.sourceforge.net < ann_body
       # freshmeat
	# $MAILcmd -s "LessTif Release $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION (appindex 895870289) is out" scoop@freshmeat.net < ann_body
       # linux announce
        $MAILcmd -s "LessTif Release $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION is out" linux-announce@news.ornl.gov < ann_body

    else
       # odd PICO

	sed -e "s/^PICO_VERSION=[0-9]*/PICO_VERSION=`expr $PICO_VERSION + 2`/" lesstif/configure.in >$$ \
          && mv $$ lesstif/configure.in \
	  && (cd lesstif && $CVScmd commit -m "PICO_VERSION update by make_release" configure.in)

	sed -e "s/^PICO_VERSION=[0-9]*/PICO_VERSION=`expr $PICO_VERSION + 2`/" lesstif/test/configure.in >$$ \
          && mv $$ lesstif/test/configure.in \
	  && (cd lesstif/test && $CVScmd commit -m "PICO_VERSION update by make_release" configure.in)

	echo "Test releases are only announced to the core developers"
        
	echo "Sending email to core team"
        $MAILcmd -s "LessTif Release $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION is out" lesstif-core@lists.sourceforge.net < ann_body
    fi 
       # end of  if PICO even/odd

else
# i.e. $PASSED != "yes"

    echo "Something failed, no been announcement has been made!"
    exit 1
fi

#
# Update progress
#
RESTARTED=99
echo 'RESTARTED='$RESTARTED >>$STATUS

#
# End of "RESTARTED -lt 99" processing
#
fi

# Now we could clean up, but for debugging purposes it's advantageous 
# to keep the ./lesstif directory and the other files around
# 
# rm -f mail_announcement usenet_ann ann_body
# rm -rf ./lesstif

echo "Done!"
exit 0
