#!/bin/sh
#
# $Id: putanope,v 1.14 2003/12/02 23:02:28 joris Exp $
#

CTRL="version.log"
MODULE="anope-dev"
TMP="/tmp/putanope.$$"
TMP2="/tmp/putanope2.$$"

# We need an editor for the log entry
if [ "$EDITOR" == "" ]; then
	EDITOR="vi"
fi

# Use default target, or provided?
if [ "$1" == "" ]; then
	DST="$MODULE"
else
	DST="$1"
fi

# Find where to run the rest of the script from.
if [ ! -d $DST ]; then
	cd ..
	if [ ! -d $DST ]; then
		cd ..
		if [ ! -d $DST ]; then
			echo "*** Directory $DST does not exist, what's going on?"
			echo ""
			exit 1
		fi
	fi
fi

# CVSROOT dosnt need to be set, just read it form the CVS file :-)
CVSROOT=`cat ${DST}/CVS/Root`

cd $DST

# source control file
. $CTRL

# Version arithmetics
CVER="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_BUILD}"
let minor="$(echo $VERSION_BUILD)"
let new="$minor + 1"
NVER="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${new}"

# Greet the developer
echo ""
echo "*** Using CVSROOT: $CVSROOT"
echo "*** Using module : $MODULE"
echo "*** Current ver  : $CVER"
echo "*** Updated ver  : $NVER"
echo ""
echo "*** Make sure you have updated Changes, Changes.conf, and"
echo "*** Changes.lang acordingly before you proceed."
echo -n "*** Ready to continue? (RETURN if so, CTRL-C otherwise) "
read FOO

cat > $TMP2 <<EOF
# Anope commit utility. Please use this template for your commits. 
# Add Mantis bugs separated by spaces. The note part is free form.
BUILD : $NVER
BUGS  : 
NOTES : 
EOF

$EDITOR $TMP2

echo "*** Ready to commit, please verify:"
echo ""
grep -v "^#" $TMP2
echo ""
echo -n "*** Perform commit? (RETURN if so, CTRL-C otherwise) "
read FOO

echo "*** Running indent..."
for source in *.c
do
	indent -kr -nut $source
done

# Clean up indent backup files
rm -f *~

echo "*** Bumping the version number..."
sed "s/VERSION_BUILD=\"$VERSION_BUILD\"/VERSION_BUILD=\"$new\"/" $CTRL > $TMP
cat $TMP > $CTRL

TS="$(date '+%F %R')"
grep -v "^#" $TMP2 > $TMP
echo "VTAG  : cvs checkout -D \"$TS\" $MODULE" >> $TMP

cd ..

cvs -d$CVSROOT commit -F $TMP $DST

rm -f $TMP $TMP2

echo "*** Done!"

exit 0
