From 7d909c603b3aae0481d571a9956658439460c817 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 18 Jul 2019 18:36:35 +0200 Subject: [PATCH] instanceinfo.sh: Ignore certificate errors. --- instanceinfo.sh | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/instanceinfo.sh b/instanceinfo.sh index 2fbbf7f..7eaff37 100755 --- a/instanceinfo.sh +++ b/instanceinfo.sh @@ -8,11 +8,18 @@ if [[ -z "${1}" ]]; then exit 1 fi +if ! command -v curl > /dev/null; then + echo "You need to install curl (https://curl.haxx.se/)" >&2 + exit 2 +fi + if ! command -v jq > /dev/null; then echo "You need to install jq (https://stedolan.github.com/jq/)" >&2 exit 2 fi +mycurl="curl -sk" + function striphtml() { local extract="${*}" @@ -23,7 +30,7 @@ function parse_nodeinfo() { local instance="${1}" local nodeinfo="${2}" - json=$(curl -s "${nodeinfo}") + json=$(${mycurl} "${nodeinfo}") # shellcheck disable=SC2155 local implementation=$(jq -r ".software.name" <<<"${json}") @@ -82,7 +89,7 @@ function parse_mastodon() { local instance="${1}" local mastoinfo="${2}" - json=$(curl -s "${mastoinfo}") + json=$(${mycurl} "${mastoinfo}") local implementation="" if grep -Eq '"is_(pro|verified)"' <<<"${json}"; then @@ -131,7 +138,7 @@ function parse_misskey() { local instance="${1}" local misskeyinfo="${2}" - json=$(curl -s -X POST "${misskeyinfo}") + json=$(${mycurl} -X POST "${misskeyinfo}") # shellcheck disable=SC2155 local version=$(jq -r ".version" <<<"${json}") @@ -142,7 +149,7 @@ function parse_misskey() [[ -n "${email}" ]] && echo "E-Mail: ${email}" # shellcheck disable=SC2155 - local users=$(curl -s -X POST "https://${instance}/api/stats" | jq -r ".usersCount") + local users=$(${mycurl} -X POST "https://${instance}/api/stats" | jq -r ".usersCount") [[ -n ${users} ]] && echo "Number of users: ${users}" echo -n "Open registrations: " @@ -157,25 +164,25 @@ 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 nodeinfo=$(${mycurl} -L "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 + if ${mycurl} -ILf -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 + elif ${mycurl} -ILf "${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 + elif ${mycurl} -ILf "${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}/" + ${mycurl} -I "https://${instance}/" fi - if curl -sILf "${instance}" | grep -q 'Server: cloudflare'; then + if ${mycurl} -ILf "${instance}" | grep -q 'Server: cloudflare'; then echo "Uses CloudFlare." fi