opendkim: Initial version of role

This commit is contained in:
Timo Makinen 2024-03-02 19:00:44 +00:00
parent 6c661f75b8
commit 546f091e91
4 changed files with 120 additions and 0 deletions

View file

@ -0,0 +1,28 @@
TARGETS := $(shell { \
if [ $$(date +%m) -lt 6 ]; then \
echo "$$(date +%Y)0101.key $$(date +%Y)0601.key" ; \
else \
echo "$$(date +%Y)0601.key $$(($$(date +%Y) + 1))0101.key" ; \
fi \
})
all: $(TARGETS)
%.key:
@set -eu ; \
openssl genrsa -out "$@" 2048 ; \
chgrp opendkim "$@" ; \
chmod 0640 "$@" ; \
echo ; \
data="$$(printf "v=DKIM1; k=rsa; p=%s" \
"$$(openssl rsa -in "$@" -pubout -outform der 2>/dev/null | openssl base64 -A)")" ; \
pos=0 ; \
printf "%s._domainkey\tIN\tTXT\t" "$$(echo "$@" | cut -d. -f1)" ; \
while true ; do \
printf "\"%s\"" \
"$$(echo "$$data" | cut -c $$((pos + 1))-$$((pos + 254)))" ; \
pos="$$((pos + 254))" ; \
[ $${#data} -gt $$pos ] || break ; \
printf " " ; \
done ; \
echo