#!/bin/sh

set -e

# Check for references to "wrong versions" of XML Security drafts

active_drafts="xmldsig-bestpractices|xmldsig-core1|xmldsig-simplify|xmlenc-core1|xmlsec-algorithms|xmlsec-generic-hybrid"
pubdate=$1 ; shift

for d ; do
	for g in "$d"/Overview.htm* ; do
		f="$g"
		break
	done
	
	test -f "$f" || { echo "Can't find $f." >&2 ; exit 1; }

	r1=PASS ; r2=PASS
	grep -nH '200[78]/xmlsec/[Dd]rafts' "$f" && r1=FAIL
	( grep -nH -e "$active_drafts" "$f" | grep -nH -v $pubdate ) && r2=WARN
	
	if test "$r1" = FAIL ; then
		echo "$f: ERROR - references editor's drafts." >&2
	fi
	if test "$r1" = WARN ; then
		echo "$f: WARNING - might refrence outdated WD." >&2
	fi
done
