diff options
author | Fredrik Åslund <fredrik.aslund@umu.se> | 2013-08-08 09:39:00 +0200 |
---|---|---|
committer | Fredrik Åslund <fredrik.aslund@umu.se> | 2013-08-08 09:39:00 +0200 |
commit | 071239ae401467f1199cbd82e70a756f1c4cce36 (patch) | |
tree | bb2149e2618b6126c6d9f54c0f4f57f906fa19be /scripts/get-metadata.sh | |
parent | 23848cde1c6adbd512918dce7bbcdc502975df31 (diff) |
get-sp-md script generalized for any metadata (including shib idp)
Diffstat (limited to 'scripts/get-metadata.sh')
-rwxr-xr-x | scripts/get-metadata.sh | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/scripts/get-metadata.sh b/scripts/get-metadata.sh new file mode 100755 index 00000000..f967872c --- /dev/null +++ b/scripts/get-metadata.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# +# Fetch Service Provider metadata and save into entityid filename +# + +error() +{ + echo "Error: $*" 1>&2 + exit 1 +} + +metadataurl=$1 +if [ -z "$metadataurl" ] ; then + cat <<EOF +Usage: `basename $0` <metadataurl> +Ex: `basename $0` https://shibsp.mysite.com/Shibboleth.sso/Metadata + `basename $0` https://shibidp.mysite.com/idp/profile/Metadata/SAML + `basename $0` file://some-downloaded-metadata.xml +EOF + exit 1 +fi + +metadata=`curl -s -k -f $metadataurl` +[ -n "$metadata" ] || error "Failed to fetch metadata from $metadataurl" + +entityid=`echo "$metadata" | sed -n 's/.*entityID="\([^"]*\)".*/\1/p'` +[ -n "$entityid" ] || error "Failed to find entityID in metadata" +[ "`echo "$entityid" | wc -l`" = "1" ] || error "Multiple entityid:s found: `echo $entityid`" + +entityidfn=`echo "$entityid" | sed 's;https*://;;' | tr 'A-Z' 'a-z' | sed 's;/$;;' | sed 's/[^a-z0-9_.-]/-/g' | sed 's/\.xml$//;s/$/.xml/'` +[ -n "$entityidfn" ] || error "Failed to generate filename from entityid $entityid" + +echo -n "Save metadata into $entityidfn [Y/n]? " +read x +case $x in + Y|y|"") + echo "$metadata" > $entityidfn + echo $entityidfn + ;; + *) + echo "Nothing done" + ;; +esac + |