blob: 5f586affc4e6c76f2b2b811d7412c9fb5f8afdff (
plain) (
blame)
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
|
#!/usr/bin/env bash
self=urlcheck
tm=${URLCHECK_TIMEOUT:-8}
shopt -s extglob
declare -a copts
declare -i ex
head=$(mktemp) || exit
body=$(mktemp) || exit
cleanup() {
rm -f -- "$head" "$body"
}
trap cleanup EXIT
while read -r url ; do
[[ $url == 'http'* ]] || continue
if ! curl -fHLsS -D "$head" -m "$tm" -o "$body" "$url" ; then
printf '%s: %s raises error\n' \
"$self" "$url" >&2
continue
fi
while IFS=': ' read -r header value ; do
[[ $header == 'Location' ]] || continue
printf '%s: %s redirects to %s\n' \
"$self" "$url" "$value" >&2
break
done < "$head"
[[ $url == 'http:'* ]] || continue
securl=${url/http:/https:}
if curl -fLsS -m "$tm" -o /dev/null -- "$securl" 2>/dev/null ; then
printf '%s: %s has a working secure version at %s\n' \
"$self" "$url" "$securl" >&2
((ex++))
fi
done
exit "$((ex > 0))"
|