From b430f924b0f17b148074ed1fcd95468c1bbd8106 Mon Sep 17 00:00:00 2001 From: Johan Wassberg Date: Tue, 1 Nov 2022 12:34:34 +0100 Subject: `shell-check` now runs quiet --- scripts/remove_entity.sh | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'scripts/remove_entity.sh') diff --git a/scripts/remove_entity.sh b/scripts/remove_entity.sh index 11bd6852..ae55a51e 100755 --- a/scripts/remove_entity.sh +++ b/scripts/remove_entity.sh @@ -14,54 +14,55 @@ fi metadataurl=$1 if [ -s "${metadataurl}" ]; then - entityidfn=$(basename $metadataurl) + entityidfn=$(basename "$metadataurl") else case $metadataurl in [0-9][0-9]*) url="https://metadata.swamid.se/?rawXML=${metadataurl}" ;; https://metadata.swamid.se/?showEntity=*) - url=$(echo "$metadataurl" | sed 's;showEntity;rawXML;') + #url=$(echo "$metadataurl" | sed 's;showEntity;rawXML;') + url=${metadataurl//showEntity/rawXML} ;; esac - metadata=`curl -L -m 5 -s -k -f "${url}"` + 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'` + 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`" + [ "$(echo "$entityid" | wc -l | sed 's/ //g')" = "1" ] || error "Multiple entityid:s found: $entityid" - entityidfn=`echo "$entityid" | sed 's;.*://;;' | sed 's/[^a-zwA-ZW0-9_.-]/-/g' | sed 's/$/.xml/'` + 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 file="swamid-2.0/$entityidfn" if [ -r "$file" ]; then echo "---------------------" - grep "/$entityidfn" *.mxml sp-with-simplesign + grep "/$entityidfn" ./*.mxml sp-with-simplesign echo "---------------------" echo -n "OK to remove ? [Y/n]" - read x + read -r x case $x in "Y"|"y"|"") ;; *) exit 1 ;; esac echo - if (grep -q $entityidfn sp-with-simplesign); then + if (grep -q "$entityidfn" sp-with-simplesign); then sed -i.bak "/\/$entityidfn/d" sp-with-simplesign if [ -f sp-with-simplesign.bak ]; then rm sp-with-simplesign.bak fi fi - git rm $file + git rm "$file" - grep $file *.mxml | sed 's/\(.*\.mxml\): /\1/' | while read mxmlfile ; do - sed -i.bak "/\/$entityidfn/d" $mxmlfile - if [ -f $mxmlfile.bak ]; then - rm $mxmlfile.bak + grep "$file" ./*.mxml | sed 's/\(.*\.mxml\): /\1/' | while read -r mxmlfile ; do + sed -i.bak "/\/$entityidfn/d" "$mxmlfile" + if [ -f "$mxmlfile".bak ]; then + rm "$mxmlfile".bak fi done git diff -- cgit v1.2.3