#!/bin/sh
#	This file is part of the Concurrent Versions System CVS.
#	Written by Dick Grune, Vrije Universiteit, Amsterdam.
#	$Header: HR,v 3.1 89/09/25 16:31:50 dick Exp $

#
#		H i g h e s t   R e l e a s e   N u m b e r
#	Writes the highest release number of the repository to standard output.
#	Applies to a repository or to the working directory.
#
Name=HR; export Name

# CVSBIN, CVSLIB and RCSBIN directories
CVSBIN=/home/top/dick/cvs
CVSLIB=/home/top/dick/cvs
RCSBIN=${RCSBIN-/usr/local/bin}
export CVSBIN CVSLIB RCSBIN

# avoid spurious identifications
PATH=${CVSPATH-/bin:/usr/bin}; export PATH

# determine the name of the repository
Repository=$1				# if present
. $CVSLIB/NR.aux

# set up names in Admin
Admin=$Repository/Admin
Highest=$Admin/HighestRelease

# we need the Admin directory
if	# $Admin exists
	[ -d $Admin ]
then	:
else	# $Admin must be made
	if	$ACT mkdir $Admin >/dev/null 2>/dev/null
	then	:
	else	echo $Name: could not make $Admin >&2
		exit 1
	fi
fi

# we need the highest release number file
if	# there is a highest release number file
	[ -r $Highest ]
then	:
else	# create it
	RCSFILES=`
		ls $Repository/*,v $Repository/Attic/*,v 2>/dev/null |
		grep -v "\*"
	`
	(
		echo 0			# in case the directory is empty
		for Rcs in $RCSFILES
		do
			$CVSLIB/VN.aux $Rcs
		done
	) |
	sed 's/\..*//' |
	sort -nru |
	sed '1q' >$Highest
fi

cat $Highest

