#!/bin/bash
#
# $Id: putanope,v 1.11 2003/10/17 20:00:00 dane Exp $
#

MODULE="anope-dev"
TMP="/tmp/putanope.$$"
BAR=""
TAG=""

if [ "$1" == "" ]; then
	DST="$MODULE"
else
	DST="$1"
fi

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 ./anope-dev/CVS/Root`
echo $CVSROOT

cd $DST

echo "*** Checking in $MODULE"
echo "*** Verifying the version number..."

CVER="$(grep VERSION version.sh | head -1)"
eval $CVER
MAJOR="$(echo $VERSION | awk -F"-rc" '{print $1}')"
let minor="$(echo $VERSION | awk -F"-rc" '{print $2}')"
let new="$minor + 1"

echo "*** Current version: $MAJOR-rc$minor New version: $MAJOR-rc$new"
echo -n "*** Is this correct? (RETURN if so, CTRL-C otherwise) "
read FOO

echo "*** Running indent..."

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

echo ""
echo "*** Make sure you have updated Changes, Changes.conf, and"
echo "*** Changes.lang acordingly before commiting."
echo -n "*** Ready to commit? (RETURN if so, CTRL-C otherwise) "
read FOO


BAR="anope-$MAJOR-rc$new"
TAG=`echo $BAR | sed "s/\./-/g"`
echo ""
echo "*** Enter revision tag, use NONE for no tag"
echo -n "*** (RETURN for default [$TAG]): "
read BAR

if [ "$BAR" != "" ] ; then
	TAG=$BAR
fi

echo "*** Bumping the version number..."
sed "s/$MAJOR-rc$minor/$MAJOR-rc$new/" version.sh > $TMP
cat $TMP > version.sh
rm -f $TMP

cd ..

cvs -d$CVSROOT commit $DST
if [ "$BAR" != "NONE" ] ; then
	cd $DST
	cvs -d$CVSROOT tag $TAG
fi

echo "*** Done!"

exit 0
