#!/bin/sh
set -e
: "${1:?Missing url}"
url_scheme=$(trurl -g '[scheme]' "$1")
url_host=$(trurl -g '[host]' "$1")
case "${url_scheme:?}" in
    telnets)
        set -- -z certrequired,secure,ssl ;; # force a cert and ssl
    telnet) set -- ;;
    *) echo "Unsupported scheme: $url_scheme" 1>&2; exit 1 ;;
esac
# The tested telnet clients know how to look in /etc/services for ports and
# curl (and thus trurl) doesn't have telnets support apparently
set -- "$@" "${url_host:?}" "${url_scheme}"
exec telnet "$@"
