#!/bin/bash
# Check that the version in the (mostly Perl module) files is correct.

VERSION="$1"
shift

[ -n "$VERSION" ] || {
	echo "Use: ckversion VERSION"
	exit 1
} >&2

RET=0

RELNOTES="doc/src/docsrc/990relnotes.xml"
PATTERN=">Release $VERSION<"
fgrep "$PATTERN" $RELNOTES >/dev/null || { echo "Missing '$PATTERN' in $RELNOTES" >&2; RET=1; }
VER_UNDER=`echo "$VERSION" | tr . _`
PATTERN="id=\"sc_notes_$VER_UNDER\""
fgrep "$PATTERN" $RELNOTES >/dev/null || { echo "Missing '$PATTERN' in $RELNOTES" >&2; RET=1; }

for f in `find perl/Triceps/lib ! -path '*/.svn/*' -name '*.pm'`
do {
	v=`perl -MExtUtils::MakeMaker -le 'print MM->parse_version(shift)' "$f"`
	[ "v$VERSION" = "$v" ] || {
		RET=1
		echo "Bad version in $f: $v"
	}
} done
[ 0 -eq "$RET" ] || { echo "Expected version: v$VERSION" >&2; }

exit $RET
