logo

utils

~/.local/bin tools and git-hooks
commit: 7c77a9bde2dd22736c9e77e99fcdfffb4fbcf0e6
parent: 00dd426808dbbf4be920736287b2532edef1eb63
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun,  3 Mar 2019 03:25:03 +0100

{ap,nodeinfo}-fetch.sh: Add fediverse related commands

Diffstat:

Abin/ap-fetch.sh22++++++++++++++++++++++
Abin/nodeinfo-fetch.sh23+++++++++++++++++++++++
2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/bin/ap-fetch.sh b/bin/ap-fetch.sh @@ -0,0 +1,22 @@ +#!/bin/sh +url="$1" +accept_header='Accept: application/ld+json,application/activity+json,application/json' + +die() { + echo $@ + exit 1 +} + +if [[ -z "${url}" ]] +then + die "Usage: ${0} [url]" +fi + +curl -sSL -H "${accept_header}" ${url} -I | tee /dev/stderr | grep -q -e '^Content-Type: application/.*json' + +if [[ "$?" == 0 ]] +then + die "Doesn’t have “Content-Type: application/.*json” in the headers" +fi + +curl -sSL -H "${accept_header}" ${url} | jq . diff --git a/bin/nodeinfo-fetch.sh b/bin/nodeinfo-fetch.sh @@ -0,0 +1,23 @@ +#!/bin/sh +url="$1" +accept_header='Accept: application/json' +nodeinfo_url='' + +die() { + echo $@ + exit 1 +} + +if [[ -z "${url}" ]] +then + die "Usage: ${0} [instance_url]" +fi + +nodeinfo_url=$(curl -sSL -H "${accept_header}" "${url}/.well-known/nodeinfo" | jq '.links[].href' -r | sort | tail -1) + +if [[ -z "${nodeinfo_url}" ]] +then + die "Failed getting Nodeinfo endpoint" +fi + +curl -sSL -H "${accept_header}" ${nodeinfo_url} | jq .