#! /usr/bin/env nix-shell
#! nix-shell -p dig -p dash -i dash --impure
# shellcheck shell=dash

get_dns_types() {
    cat <<EOF
    A
    AAAA
    CAA
    CNAME
    DNAME
    MX
    NS
    SOA
    SRV
    TXT
    PTR
    DNSKEY
    DS
    SSHFP
    TLSA
    OPENPGPKEY
    SVCB
    HTTPS
EOF
}

check_type() {
    domain="$1"
    type="$2"

    if [ "$(dig +short -t "$type" "$domain" | wc -c)" -ne 0 ]; then
        dig +short -t "$type" "$domain" | while IFS="$(printf "\n")" read -r output; do
            printf "(%s) %s [%s]\n" "$type" "$output" "$domain"
        done
    else
        printf "(%s) <Not set> [%s]\n" "$type" "$domain"
    fi
}

get_dns() {
    original_domain="$1"

    get_dns_types | while read -r type; do
        check_type "$original_domain" "$type"
    done

    # DKIM
    check_type "mail._domainkey.$original_domain" "TXT"

    # DMARC
    check_type "_dmarc.$original_domain" "TXT"
}

get_dns "$1"