Skip to content

Instantly share code, notes, and snippets.

@spitemim
Last active January 16, 2022 00:54
Show Gist options
  • Save spitemim/051753b3e2256c511bc76c162dcfc0c0 to your computer and use it in GitHub Desktop.
Save spitemim/051753b3e2256c511bc76c162dcfc0c0 to your computer and use it in GitHub Desktop.
mhname - check availability of Minehut server names
#!/bin/sh
#
# usage:
# mhname [names...]
# or
# mhname < names-list.txt
#
# requires:
# jq, curl
#
# mhname's output looks like this:
# Is 'servername' taken: true
#
# If arguments are passed to mhname, it will check each one for availability as
# a server name. Otherwise, it reads a list of files from stdin and checks each
# one for availability.
#
# Written by spitemim.
# This code is public domain. Anyone can use it for anything for any reason.
check_name () {
name="$1"
exists="$(
curl -s "https://api.minehut.com/server/$name?byName=true" |
jq -c 'if .server then true else false end'
)"
printf "%s\n" "$exists"
}
if [ $# -gt 0 ]
then
for arg in "$@"
do
available="$(check_name "$arg")"
printf "Is '%s' taken: %s\n" "$arg" "$available"
done
return 0
fi
while read name
do
available="$(check_name "$name")"
printf "Is '%s' taken: %s\n" "$name" "$available"
done
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment