-
Notifications
You must be signed in to change notification settings - Fork 0
/
athandle
executable file
·42 lines (38 loc) · 875 Bytes
/
athandle
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
#!/bin/sh
dig2at() {
for q in "$@"; do
shift
set -- "$@" "_atproto.$q"
done
dig +noall +answer TXT "$@" | sed -E 's/^_atproto\.([^[:space:]]*)\.[[:space:]][^[:space:]]*[[:space:]]IN[[:space:]]TXT[[:space:]]"did=([^"]*)".*$/\1\t\2/'
# The status code here is not relevant since the final status code will be determined after
# falling back on the well-known URI.
}
wellknown() {
printf '%s\t' "$1"
ret=0
# The extra `echo` ensures that the output ends with a line feed
result="$(curl -qfLs --compressed "https://$1/.well-known/atproto-did")" || ret=$?
echo "$result"
return "$ret"
}
main() {
status=0
dig2at "$@" | {
read -r resolved
for q in "$@"; do
shift
case "$resolved" in
"$q$(printf '\t')"*)
echo "$resolved"
read -r resolved
;;
*)
wellknown "$q" || status=$?
;;
esac
done
return "$status"
}
}
main "$@"