From f2c8d6de1cc43eab32f8a17f60443c37dd6ef13d Mon Sep 17 00:00:00 2001 From: Björn Mattsson Date: Thu, 5 May 2022 15:54:54 +0200 Subject: Added functions to get enityID / Filename from metadata.swamid.se --- scripts/remove_entity.sh | 84 ++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 31 deletions(-) (limited to 'scripts/remove_entity.sh') diff --git a/scripts/remove_entity.sh b/scripts/remove_entity.sh index d9350c2b..ecf75bf4 100755 --- a/scripts/remove_entity.sh +++ b/scripts/remove_entity.sh @@ -1,42 +1,64 @@ #!/bin/bash if [ -z "$1" ]; then - echo "$0 " + echo "$0 " exit fi -echo "---------------------" -grep $1 *.mxml sp-with-simplesign -echo "---------------------" -echo -n "OK to remove ? [Y/n]" -read x -case $x in - "Y"|"y"|"") ;; - *) exit 1 ;; -esac - -echo -if [ `uname -s` == "Darwin" ]; then - MacOSX=true +metadataurl=$1 + +if [ -s "${metadataurl}" ]; then + entityidfn=$metadataurl else - MacOSX=false -fi -if (grep -q $1 sp-with-simplesign); then - if ( $MacOSX ) ; then - sed -i "" "/$1/d" sp-with-simplesign - else - sed -i "/$1/d" sp-with-simplesign - fi + case $metadataurl in + [0-9][0-9]*) + url="https://metadata.swamid.se/?rawXML=${metadataurl}" + ;; + esac + metadata=`curl -L -m 5 -s -k -f "${url}"` + + [ -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;.*://;;' | sed 's/[^a-zwA-ZW0-9_.-]/-/g' | sed 's/$/.xml/'` + [ -n "$entityidfn" ] || error "Failed to generate filename from entityid $entityid" fi -grep $1 *.mxml | sed 's/.*: /\1/' | while read file ; do - git rm $file -done +file="swamid-2.0/$entityidfn" + +if [ -r "$file" ]; then + echo "---------------------" + grep $entityidfn *.mxml sp-with-simplesign + echo "---------------------" + echo -n "OK to remove ? [Y/n]" + read x + case $x in + "Y"|"y"|"") ;; + *) exit 1 ;; + esac -grep $1 *.mxml | sed 's/\(.*\.mxml\): /\1/' | while read file ; do - if ( $MacOSX ) ; then - sed -i "" "/$1/d" $file + echo + if [ `uname -s` == "Darwin" ]; then + MacOSX=true else - sed -i "/$1/d" $file + MacOSX=false fi -done -git diff + if (grep -q $entityidfn sp-with-simplesign); then + if ( $MacOSX ) ; then + sed -i "" "/$entityidfn/d" sp-with-simplesign + else + sed -i "/$entityidfn/d" sp-with-simplesign + fi + fi + git rm $file + grep $file *.mxml | sed 's/\(.*\.mxml\): /\1/' | while read mxmlfile ; do + if ( $MacOSX ) ; then + sed -i "" "/$entityidfn/d" $mxmlfile + else + sed -i "/$entityidfn/d" $mxmlfile + fi + done + git diff +fi -- cgit v1.2.3