Add url checker

This commit is contained in:
Ben Edgington
2022-03-18 16:37:13 +00:00
parent f9f9f32398
commit f8acc52c59

24
bin/util/urlcheck.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
# Check availability of external markdown links in the supplied document.
# Github severely rate limits unless you use your access creds.
github_secret=$(cat ../priv/github.txt)
for x in $(grep -Pho '\(\Khttp[^)]+' $1 | sed 's/#.*$//g' | sort -u)
do
echo $x;
# Include credentials for github.com
[[ "$x" =~ .*github.com* ]] && creds="-u $github_secret" || creds=""
# beaconcha.in doesn't like HEAD requests
[[ "$x" =~ .*beaconcha.in* ]] && head="" || head="--head"
res=$(curl $creds -Lo /dev/null --silent $head --write-out '%{http_code}\n' $x)
if [ "200" -ne "$res" ]
then
echo "*** $res ***"
fi
done