#!/bin/sh
set -euC

# nfsn-dns-dkim DOMAIN NAME SELECTOR KEY_TYPE KEY_PUB

# nfsn-dns-dkim "example.com" "" "k1" "rsa" "$key_pub"

# Arguments.

domain="$1" ; shift
name="$1" ; shift
selector="$1" ; shift
key_type="$1" ; shift
key_pub="$1" ; shift

# Process.

name="$selector._domainkey${name:+".$name"}"
data="v=DKIM1; k=$key_type; p=$key_pub"

# Update.

nfsn-dns-update "$domain" "$name" "TXT" '^v=DKIM1' "$data"