From 9ef614485c08ad4d2dfcedbfe6f91efdce253bf3 Mon Sep 17 00:00:00 2001 From: Fredrik Domeij Date: Thu, 15 Feb 2024 11:40:30 +0100 Subject: metadata/scripts/get-metadata.sh shellcheck --- metadata/scripts/get-metadata.sh | 57 ++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/metadata/scripts/get-metadata.sh b/metadata/scripts/get-metadata.sh index 13148a03..78d9d717 100755 --- a/metadata/scripts/get-metadata.sh +++ b/metadata/scripts/get-metadata.sh @@ -12,21 +12,21 @@ error() metadataurl=$1 if [ -z "$metadataurl" ] ; then cat < -Ex: `basename $0` https://metadata.swamid.se/?showEntity=5271 - `basename $0` 5271 - `basename $0` https://shibsp.mysite.com/Shibboleth.sso/Metadata - `basename $0` https://shibidp.mysite.com/idp/profile/Metadata/SAML - `basename $0` some-downloaded-metadata.xml - `basename $0` reep: - `basename $0` (tries to pull from standard locations) +Usage: $0 +Ex: $0 https://metadata.swamid.se/?showEntity=5271 + $0 5271 + $0 https://shibsp.mysite.com/Shibboleth.sso/Metadata + $0 https://shibidp.mysite.com/idp/profile/Metadata/SAML + $0 some-downloaded-metadata.xml + $0 reep: + $0 (tries to pull from standard locations) EOF exit 1 fi xmldir=swamid-2.0 if [ -s "${metadataurl}" ]; then - metadata=`cat "$metadataurl"` + metadata=$(cat "$metadataurl") else case $metadataurl in [0-9][0-9]*) @@ -43,7 +43,7 @@ else urls="$metadataurl" ;; reep://*) - id=`echo -n "$metadataurl" | sed 's/^reep://' | sha1sum | awk '{print $1}'` + id=$(echo -n "$metadataurl" | sed 's/^reep://' | sha1sum | awk '{print $1}') metadataurl="http://md.reep.refeds.org/entities/%7Bsha1%7D$id" urls="$metadataurl" ;; @@ -55,53 +55,54 @@ else ;; esac for i in ${urls}; do - metadata=`curl -L -m 5 -s -k -f "${i}"` + metadata=$(curl -L -m 5 -s -k -f "${i}") [ -n "${metadata}" ] && break done fi [ -n "$metadata" ] || error "Failed to fetch metadata from $metadataurl" -script_cwd=`dirname "$0"` -if test -d $xmldir ; then +script_cwd=$(dirname "$0") +if test -d "$xmldir" ; then echo "Moving into $xmldir/" - cd $xmldir + cd "$xmldir" || exit 1 echo "$script_cwd" | grep -q ^/ || script_cwd=../$script_cwd fi -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`" +# shellcheck disable=SC2046,SC2086 +[ $(echo "$entityid" | wc -l) = 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" -OLDFILE=$(find ../swamid-testing ../swamid-2.0 ../swamid-edugain -name $entityidfn | grep -v $xmldir) +OLDFILE=$(find ../swamid-testing ../swamid-2.0 ../swamid-edugain -name "$entityidfn" | grep -v "$xmldir") if [ -n "$OLDFILE" ]; then echo "Moving $OLDFILE into $xmldir" - git mv $OLDFILE $entityidfn + git mv "$OLDFILE" "$entityidfn" fi [ -r "$entityidfn" ] && new=false || new=true -if $new ; then +if "$new" ; then echo -n "Save metadata into $entityidfn [Y/n]? " else regdate=$(sed -n 's;.*RegistrationInfo.*registrationInstant="\([^"]*\)".*;\1;p' < "$entityidfn" | head -n 1) echo -n "Replace $entityidfn with metadata [Y/n]? " fi -[ -n "$regdate" ] || regdate=$(perl $script_cwd/../scripts/now_date.pl) +[ -n "$regdate" ] || regdate=$(perl "$script_cwd/../scripts/now_date.pl") -read x +read -r x case $x in Y|y|"") - echo "$metadata" > $entityidfn - tmp=`mktemp` - xsltproc --stringparam regDate "$regdate" $script_cwd/../xslt/add-rpi.xsl ${entityidfn} > ${tmp} && mv ${tmp} ${entityidfn} - xsltproc $script_cwd/../xslt/clean-entitydescriptor.xsl ${entityidfn} > ${tmp} && mv ${tmp} ${entityidfn} + echo "$metadata" > "$entityidfn" + tmp=$(mktemp) + xsltproc --stringparam regDate "$regdate" "$script_cwd/../xslt/add-rpi.xsl" "${entityidfn}" > "${tmp}" && mv "${tmp}" "${entityidfn}" + xsltproc "$script_cwd/../xslt/clean-entitydescriptor.xsl" "${entityidfn}" > "${tmp}" && mv "${tmp}" "${entityidfn}" if $new ; then echo -n "Add ${xmldir}/$entityidfn to git [Y/n]? " - read x + read -r x case $x in Y|y|"") - git add $entityidfn + git add "$entityidfn" ;; *) echo "Not added" -- cgit v1.2.3