KEY=signer.key
CERT=signer.crt
PASS=$(shell cat /local/swamid-signer-pass.txt)

all: update clean sign

update:
#	@svn up -q

keys: $(KEY) $(CERT)

sign: keys swamid nya swamid-compat nya-testing swamid-testing swamid-kalmar swamid-edugain-testing swamid-ki-sll

urn-mace-swami.se-swamid-test-1.0-metadata.mxml:
	@sed 's!http://md.swamid.se/md/swamid-1.0.xml!urn:mace:swami.se:swamid:test-1.0!g' < swamid-1.0.mxml > urn-mace-swami.se-swamid-test-1.0-metadata.mxml

swamid-compat: urn-mace-swami.se-swamid-test-1.0-metadata.mxml
	@saml-md-tool urn-mace-swami.se-swamid-test-1.0-metadata update --key=$(KEY) --cert=$(CERT) --pwd=$(PASS)
	@test -s urn-mace-swami.se-swamid-test-1.0-metadata-unsigned.xml && cp urn-mace-swami.se-swamid-test-1.0-metadata-unsigned.xml /local/saml-metadata/urn-mace-swami.se-swamid-test-1.0-metadata.xml
	@test -s urn-mace-swami.se-swamid-test-1.0-metadata.xml && cp urn-mace-swami.se-swamid-test-1.0-metadata.xml /local/saml-metadata/urn-mace-swami.se-swamid-test-1.0-metadata-signed.xml

swamid:
	@saml-md-tool swamid-1.0 update --key=$(KEY) --cert=$(CERT) --pwd=$(PASS)
	@test -s swamid-1.0.xml && cp swamid-1.0.xml /local/saml-metadata
	@test -s swamid-1.0-unsigned.xml && cp swamid-1.0-unsigned.xml /local/saml-metadata

nya:
	@saml-md-tool nya-1.0 update --key=$(KEY) --cert=$(CERT) --pwd=$(PASS)
	@test -s nya-1.0.xml && cp nya-1.0.xml /local/saml-metadata
	@test -s nya-1.0-unsigned.xml && cp nya-1.0-unsigned.xml /local/saml-metadata

nya-testing:
	@saml-md-tool nya-1.0-testing update --key=$(KEY) --cert=$(CERT) --pwd=$(PASS)
	@test -s nya-1.0-testing.xml && cp nya-1.0-testing.xml /local/saml-metadata

swamid-testing:
	@saml-md-tool swamid-1.0-testing update --key=$(KEY) --cert=$(CERT) --pwd=$(PASS)
	@test -s swamid-1.0-testing.xml && cp swamid-1.0-testing.xml /local/saml-metadata

swamid-edugain-testing:
	@saml-md-tool swamid-edugain-testing-1.0 update --key=$(KEY) --cert=$(CERT) --pwd=$(PASS)
	@test -s swamid-edugain-testing-1.0.xml && cp swamid-edugain-testing-1.0.xml /local/saml-metadata

swamid-kalmar:
	@saml-md-tool swamid-kalmar-1.0 update --key=$(KEY) --cert=$(CERT) --pwd=$(PASS)
	@test -s swamid-kalmar-1.0.xml && cp swamid-kalmar-1.0.xml /local/saml-metadata

swamid-ki-sll:
	@saml-md-tool swamid-ki-sll-1.0 update --key=$(KEY) --cert=$(CERT) --pwd=$(PASS)
	@test -s swamid-ki-sll-1.0.xml && cp swamid-ki-sll-1.0.xml /local/saml-metadata

test:
	@xmllint --xinclude --noout --schema schema/sstc-saml-schema-metadata-2.0.xsd swamid-1.0.mxml
	@xmllint --xinclude --noout --schema schema/sstc-saml-schema-metadata-2.0.xsd nya-1.0.mxml
	@xmllint --xinclude --noout --schema schema/sstc-saml-schema-metadata-2.0.xsd swamid-1.0-testing.mxml
	@xmllint --xinclude --noout --schema schema/sstc-saml-schema-metadata-2.0.xsd nya-1.0-testing.mxml
	@xmllint --xinclude --noout --schema schema/sstc-saml-schema-metadata-2.0.xsd swamid-kalmar-1.0.mxml
	@xmllint --xinclude --noout --schema schema/sstc-saml-schema-metadata-2.0.xsd swamid-ki-sll-1.0.mxml
	@xmllint --xinclude --noout --schema schema/sstc-saml-schema-metadata-2.0.xsd swamid-edugain-testing-1.0.mxml

clean:
	@rm -f *.xml