Fetch the nodeinfo-address from /.well-known/nodeinfo.

This commit is contained in:
tastytea 2019-06-24 15:15:41 +02:00
parent db81801597
commit bc603b884e
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 32 additions and 27 deletions

View File

@ -1,14 +1,18 @@
#!/bin/bash
# Print some basic info about fediverse instances. Install json_pp for prettier
# output.
# Print some basic info about fediverse instances.
# Version: 2019-06-24_3
# Version: 2019-06-24_4
if [ -z "${1}" ]; then
if [[ -z "${1}" ]]; then
echo "usage: ${0} DOMAIN" >&2
exit 1
fi
if ! command -v jq > /dev/null; then
echo "You need to install jq (https://stedolan.github.com/jq/)" >&2
exit 2
fi
function pretty()
{
local extract="${*}"
@ -28,11 +32,33 @@ function striphtml()
function main()
{
local instance="${1}"
local nodeinfo="https://${instance}/nodeinfo/2.0.json"
# shellcheck disable=SC2155
local nodeinfo=$(curl -s "https://${instance}/.well-known/nodeinfo" | jq -r '.links[-1].href' 2> /dev/null)
local mastoinfo="https://${instance}/api/v1/instance"
local misskeyinfo="https://${instance}/api/meta"
if curl -sIf "${nodeinfo}" | grep -iq 'Content-Type: application/json'; then
if curl -sIf -X POST "${misskeyinfo}" | grep -iq 'Content-Type: application/json'; then
echo "Misskey API found."
json=$(curl -s -X POST "${misskeyinfo}")
# shellcheck disable=SC2155
local email=$(grep -Eo '"maintainerEmail":"[^"]+"' <<<"${json}" | cut -d: -f2 | sed 's/"//g')
[[ -n "${email}" ]] && echo "E-Mail: ${email}"
# shellcheck disable=SC2155
local users=$(curl -s -X POST "https://${instance}/api/stats" | grep -Eo '"usersCount":[0-9]+' | cut -d: -f2)
[[ -n ${users} ]] && echo "Number of users: ${users}"
# NOTE: I'm not sure what the returned data means exactly and I couldn't find the API-documentation. So I commented it out for now.
# # shellcheck disable=SC2155
# local federation=$(curl -s -X POST "https://${instance}/api/federation/instances" | grep -Eo '"host":"[^"]+",' | sed 's/"host"://g')
# # shellcheck disable=SC2046
# [[ -n ${federation} ]] && echo -n "Federates with: " && pretty '"":['"${federation}"'""]'
# shellcheck disable=SC2155
local tos=$(grep -Eo '"ToSUrl":"[^"]+"' <<<"${json}" | cut -d: -f2,3 | sed 's/"//g')
[[ -n "${tos}" ]] && echo "ToS: ${tos}"
elif curl -sIf "${nodeinfo}" | grep -iq 'Content-Type: application/json'; then
echo "Nodeinfo found."
json=$(curl -s "${nodeinfo}")
local implementation=""
@ -89,27 +115,6 @@ function main()
if [[ "${implementation}" == "Mastodon" ]]; then
echo "Further info, maybe: https://${instance}/about/more"
fi
elif curl -sIf -X POST "${misskeyinfo}" | grep -iq 'Content-Type: application/json'; then
echo "Misskey API found."
json=$(curl -s -X POST "${misskeyinfo}")
# shellcheck disable=SC2155
local email=$(grep -Eo '"maintainerEmail":"[^"]+"' <<<"${json}" | cut -d: -f2 | sed 's/"//g')
[[ -n "${email}" ]] && echo "E-Mail: ${email}"
# shellcheck disable=SC2155
local users=$(curl -s -X POST "https://${instance}/api/stats" | grep -Eo '"usersCount":[0-9]+' | cut -d: -f2)
[[ -n ${users} ]] && echo "Number of users: ${users}"
# NOTE: I'm not sure what the returned data means exactly and I couldn't find the API-documentation. So I commented it out for now.
# # shellcheck disable=SC2155
# local federation=$(curl -s -X POST "https://${instance}/api/federation/instances" | grep -Eo '"host":"[^"]+",' | sed 's/"host"://g')
# # shellcheck disable=SC2046
# [[ -n ${federation} ]] && echo -n "Federates with: " && pretty '"":['"${federation}"'""]'
# shellcheck disable=SC2155
local tos=$(grep -Eo '"ToSUrl":"[^"]+"' <<<"${json}" | cut -d: -f2,3 | sed 's/"//g')
[[ -n "${tos}" ]] && echo "ToS: ${tos}"
else
echo "Could not detect type of server."
curl -I "https://${instance}/"