#!/bin/sh

OPENSAML="lib/opensaml-2.6.3.jar" # for Shibboleth version 3.0.0, this must be: "webapp/WEB-INF/lib/opensaml-saml-impl-3.0.0.jar"
TEMPLATES="templates/saml2-post-artifact-binding.vm templates/saml1-post-binding.vm templates/saml2-post-simplesign-binding.vm templates/saml2-post-binding.vm"

# extract relevant template files :
# NOTE: this creates a subdirectory "templates" in the current directory where it places the files
jar xf $OPENSAML $TEMPLATES

for TEMPLATE in $TEMPLATES
do
	# add anchors to form action:
	sed -r -i 's/onload="(document\.forms\[0\]\.submit)/onload="document.forms[0].action+=window.location.hash;\1/g' $TEMPLATE
done

# backup old jar:
cp -a $OPENSAML $OPENSAML.$(date +%Y-%m-%d_%H-%M-%S)

# replace template files in jar:
jar uf $OPENSAML $TEMPLATES

# remove temporary files and templates folder:
rm $TEMPLATES
rmdir templates
