-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-redirects-for-hosting
executable file
·91 lines (82 loc) · 2.12 KB
/
check-redirects-for-hosting
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
set -e -f -u -o pipefail
check_single_rediect() {
local expected_url="$1" check_url="$2" sleep_time="$3"
for ((i = 0; i < 5; i++)); do
# HTTP/1 uses "Location:", HTTP/2 uses "location:", so do a
# case-insensitive check.
if curl --silent --show-error --head "${check_url}" 2> /dev/null \
| grep -i -q "^location: ${expected_url}"; then
return 0
fi
sleep "${sleep_time}"
done
return 1
}
check_redirects() {
local sleep_time="$1" expected_url="$2"
shift 2
local failures=0 url
for url in "$@"; do
if ! check_single_rediect "${expected_url}" "${url}" "${sleep_time}"; then
failures=$((failures + 1))
printf "Bad/missing redirect for %s, expected %s\\n" \
"${url}" "${expected_url}"
curl --head "${url}"
fi
done
return "${failures}"
}
main() {
if [[ ! -t 0 ]]; then
sleep $((RANDOM % 600))
sleep_time=30
else
sleep_time=1
fi
check_redirects \
"${sleep_time}" \
"https://www.arianetobin.ie" \
"http://ariane.ie" \
"https://ariane.ie" \
"http://www.ariane.ie" \
"https://www.ariane.ie" \
\
"http://arianetobin.ie" \
"https://arianetobin.ie" \
\
"http://arianetobin.com" \
"https://arianetobin.com" \
"http://www.arianetobin.com" \
"https://www.arianetobin.com" \
\
"http://metalatplay.com" \
"https://metalatplay.com" \
"http://www.metalatplay.com" \
"https://www.metalatplay.com" \
\
"http://metalatwork.com" \
"https://metalatwork.com" \
"http://www.metalatwork.com" \
"https://www.metalatwork.com" \
\
"http://nakedmetalsmith.com" \
"https://nakedmetalsmith.com" \
"http://www.nakedmetalsmith.com" \
"https://www.nakedmetalsmith.com" \
check_redirects \
"${sleep_time}" \
"https://dev.arianetobin.ie" \
"http://dev.arianetobin.ie"
check_redirects \
"${sleep_time}" \
"https://test.arianetobin.ie" \
"http://test.arianetobin.ie"
check_redirects \
"${sleep_time}" \
"https://www.johntobin.ie" \
"http://www.johntobin.ie" \
"http://johntobin.ie" \
"https://johntobin.ie"
}
main