forked from ginhom/dnscrypt-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolvers-check.sh
executable file
·45 lines (35 loc) · 1.09 KB
/
resolvers-check.sh
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
#! /bin/sh
RESOLVERS_LIST=dnscrypt-resolvers.csv
ONLINE_RESOLVERS_LIST=dnscrypt-online-resolvers.csv
DNSCRYPT_PROXY=dnscrypt-proxy
MARGIN=720
CSV_FILE="$(dirname $0)/${RESOLVERS_LIST}"
tmpfile=$(mktemp .${ONLINE_RESOLVERS_LIST}.XXXXXXXXXXXX) || exit 1
trap "rm -f ${tmpfile}" EXIT
if which csvlint > /dev/null; then
csvlint "$RESOLVERS_LIST" || echo "*** Invalid CSV file ***" >&2
fi
if [ $(cut -d, -f1 $RESOLVERS_LIST | sort | uniq -d | wc -l) -gt 0 ]; then
echo "Duplicate resolver name" >&2
exit 1
fi
if [ $(cut -d, -f2 $RESOLVERS_LIST | sort | uniq -d | wc -l) -gt 0 ]; then
echo "Duplicate resolver long name" >&2
exit 1
fi
exec < "$RESOLVERS_LIST"
exec > "$tmpfile"
read header
echo "$header" | egrep -q '^Name,' || echo "*** Invalid CSV file ***" >&2
echo "$header"
while read line; do
resolver_name=$(echo "$line" | cut -d, -f1)
eval "${DNSCRYPT_PROXY} -L ${CSV_FILE} -R ${resolver_name} -t ${MARGIN} -m 1"
if [ $? -eq 0 ]; then
echo "$line"
echo "+ ${resolver_name} - OK" >&2
else
echo "- ${resolver_name} - Failed" >&2
fi
done
mv -f "$tmpfile" "$ONLINE_RESOLVERS_LIST"