#! /bin/sh - ######################## PREAMBLE ########################## err () { printf '\033[31m%s\033[m\n' "$*" >&2 } # TODO: Fallbacks with wget, nc, bash command -v curl >/dev/null 2>&1 || { echo "Need curl"; exit 1; } command -v timeout >/dev/null 2>&1 || { echo "Need timeout(1)"; exit 1; } curl () { output=$(timeout 5 curl -sfSL "$@") # strip trailing newline err=$? # save exit status printf '%s\n' "${output}" # add trailing newline [ $err = 0 ] && exit 0 # exit early, we got what we wanted while [ -n "$1" ] && [ "${1}" = "$(printf %s "$1" | tr -d .)" ] ; do shift; done # find domain [ -z "$1" ] && domain="" || domain="$1" # didn't find domain? [ $err = 124 ] && err "Timed out" # from timeout 5 err "$domain pastebin failed!" # generic error return $err # specifically for chris titus hastebin } trap 'rm -f "$file"' EXIT # clean up tmpfile file=$(mktemp --tmpdir pubtmpXXXXXXXXXXXXXXX) # must not contain dot . if [ -z "$1" ]; then cat >"$file" # `pub` or `