instanceinfo.sh: Refactored code into functions.
This commit is contained in:
parent
eb1af4b8ca
commit
a83cfa78ac
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
# Print some basic info about fediverse instances.
|
||||
|
||||
# Version: 2019-07-16_2
|
||||
# Version: 2019-07-18_1
|
||||
|
||||
if [[ -z "${1}" ]]; then
|
||||
echo "usage: ${0} DOMAIN" >&2
|
||||
|
@ -19,38 +19,10 @@ function striphtml()
|
|||
echo "${extract}" | sed 's/\\u003c/</g' | sed 's/\\u003e/>/g' | sed -E 's/<[^>]+>//g' | sed 's/\\r\\n/ /g' | sed -E 's/(^"|"$)//g'
|
||||
}
|
||||
|
||||
function main()
|
||||
function parse_nodeinfo()
|
||||
{
|
||||
local instance="${1}"
|
||||
# shellcheck disable=SC2155
|
||||
local nodeinfo=$(curl -sL "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 -sILf -X POST "${misskeyinfo}" | grep -iq 'Content-Type: application/json'; then
|
||||
echo "Misskey API found."
|
||||
json=$(curl -s -X POST "${misskeyinfo}")
|
||||
|
||||
# shellcheck disable=SC2155
|
||||
local version=$(jq -r ".version" <<<"${json}")
|
||||
echo "Misskey ${version} detected."
|
||||
|
||||
# shellcheck disable=SC2155
|
||||
local email=$(jq -r ".maintainerEmail" <<<"${json}")
|
||||
[[ -n "${email}" ]] && echo "E-Mail: ${email}"
|
||||
|
||||
# shellcheck disable=SC2155
|
||||
local users=$(curl -s -X POST "https://${instance}/api/stats" | jq -r ".usersCount")
|
||||
[[ -n ${users} ]] && echo "Number of users: ${users}"
|
||||
|
||||
echo -n "Open registrations: "
|
||||
jq -r ".features.registration" <<<"${json}"
|
||||
|
||||
# shellcheck disable=SC2155
|
||||
local tos=$(jq -r ".ToSUrl" <<<"${json}")
|
||||
[[ -n "${tos}" ]] && echo "ToS: ${tos}"
|
||||
elif curl -sILf "${nodeinfo}" | grep -iq 'Content-Type: application/json'; then
|
||||
echo "Nodeinfo found."
|
||||
local nodeinfo="${2}"
|
||||
json=$(curl -s "${nodeinfo}")
|
||||
|
||||
# shellcheck disable=SC2155
|
||||
|
@ -104,8 +76,12 @@ function main()
|
|||
elif [[ "${implementation}" == "peertube" ]]; then
|
||||
echo "Further info, maybe: https://${instance}/about/instance"
|
||||
fi
|
||||
elif curl -sILf "${mastoinfo}" | grep -iq 'Content-Type: application/json'; then
|
||||
echo "Mastodon API found."
|
||||
}
|
||||
|
||||
function parse_mastodon()
|
||||
{
|
||||
local instance="${1}"
|
||||
local mastoinfo="${2}"
|
||||
json=$(curl -s "${mastoinfo}")
|
||||
local implementation=""
|
||||
|
||||
|
@ -149,6 +125,51 @@ function main()
|
|||
elif [[ "${implementation}" == "Gab" ]]; then
|
||||
echo "Further info, maybe: https://${instance}/about"
|
||||
fi
|
||||
}
|
||||
|
||||
function parse_misskey()
|
||||
{
|
||||
local instance="${1}"
|
||||
local misskeyinfo="${2}"
|
||||
json=$(curl -s -X POST "${misskeyinfo}")
|
||||
|
||||
# shellcheck disable=SC2155
|
||||
local version=$(jq -r ".version" <<<"${json}")
|
||||
echo "Misskey ${version} detected."
|
||||
|
||||
# shellcheck disable=SC2155
|
||||
local email=$(jq -r ".maintainerEmail" <<<"${json}")
|
||||
[[ -n "${email}" ]] && echo "E-Mail: ${email}"
|
||||
|
||||
# shellcheck disable=SC2155
|
||||
local users=$(curl -s -X POST "https://${instance}/api/stats" | jq -r ".usersCount")
|
||||
[[ -n ${users} ]] && echo "Number of users: ${users}"
|
||||
|
||||
echo -n "Open registrations: "
|
||||
jq -r ".features.registration" <<<"${json}"
|
||||
|
||||
# shellcheck disable=SC2155
|
||||
local tos=$(jq -r ".ToSUrl" <<<"${json}")
|
||||
[[ -n "${tos}" ]] && echo "ToS: ${tos}"
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
local instance="${1}"
|
||||
# shellcheck disable=SC2155
|
||||
local nodeinfo=$(curl -sL "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 -sILf -X POST "${misskeyinfo}" | grep -iq 'Content-Type: application/json'; then
|
||||
echo "Misskey API found."
|
||||
parse_misskey "${instance}" "${misskeyinfo}"
|
||||
elif curl -sILf "${nodeinfo}" | grep -iq 'Content-Type: application/json'; then
|
||||
echo "Nodeinfo found."
|
||||
parse_nodeinfo "${instance}" "${nodeinfo}"
|
||||
elif curl -sILf "${mastoinfo}" | grep -iq 'Content-Type: application/json'; then
|
||||
echo "Mastodon API found."
|
||||
parse_mastodon "${instance}" "${mastoinfo}"
|
||||
else
|
||||
echo "Could not detect type of server."
|
||||
curl -I "https://${instance}/"
|
||||
|
|
Loading…
Reference in New Issue