Skip to content

Commit 6777cac

Browse files
committed
Added checker script for external links
Signed-off-by: mrgarris0n <gergely.karacsonyi@gmail.com>
1 parent 98a4809 commit 6777cac

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

_tools/linkcheck

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
check_link_file()
4+
{
5+
if ! [ -f "${EXTERNAL_LINK_FILE}" ]; then
6+
echo "The specified file $EXTERNAL_LINK_FILE does not exist. Exiting..."
7+
exit 1
8+
fi
9+
}
10+
11+
12+
check_urls()
13+
{
14+
echo "Checking validity of external links..."
15+
16+
local URLS+=($(grep 'url:' $EXTERNAL_LINK_FILE | tail -n+1 | awk '{ print $2}'))
17+
18+
if [ ${#URLS[@]} == 0 ]; then
19+
echo "No links found in $EXTERNAL_LINK_FILE, please check."
20+
exit 1
21+
fi
22+
23+
for url in "${URLS[@]}";
24+
do
25+
response=$(curl -o /dev/null -s -w "%{http_code}\n" $url)
26+
27+
if [[ "$response" == "000" || "$response" > "399" ]]; then
28+
echo "($response) $url is not a live url, please check in $EXTERNAL_LINK_FILE."
29+
INVALID=$((INVALID+1))
30+
fi
31+
32+
sleep .5
33+
done
34+
35+
if [[ "$INVALID" == 0 ]]; then
36+
echo "Every link is alive and OK."
37+
else
38+
echo "$INVALID invalid links found."
39+
fi
40+
}
41+
42+
43+
if ! [ "$#" -eq 1 ]; then
44+
echo "Usage: $0 <external link file>"
45+
exit 1
46+
fi
47+
48+
EXTERNAL_LINK_FILE="${1}"
49+
INVALID=0
50+
51+
check_link_file
52+
check_urls
53+
54+
exit 0

0 commit comments

Comments
 (0)