Subject: [PATCH] community/go-msgauth: new aport

From: Drew DeVault <[email-masked]>
Date: Mon, 23 Nov 2020 10:20:17 -0500

---
Putting straight into community because we're running this package in
production without issues.

 community/go-msgauth/APKBUILD               | 48 +++++++++++++++++++++
 community/go-msgauth/dkim-milter.confd      | 27 ++++++++++++
 community/go-msgauth/dkim-milter.initd      | 29 +++++++++++++
 community/go-msgauth/go-msgauth.pre-install |  4 ++
 4 files changed, 108 insertions(+)
 create mode 100644 community/go-msgauth/APKBUILD
 create mode 100644 community/go-msgauth/dkim-milter.confd
 create mode 100644 community/go-msgauth/dkim-milter.initd
 create mode 100644 community/go-msgauth/go-msgauth.pre-install

diff --git a/community/go-msgauth/APKBUILD b/community/go-msgauth/APKBUILD
new file mode 100644
index 0000000000..2985b8c358
--- /dev/null
+++ b/community/go-msgauth/APKBUILD
@@ -0,0 +1,48 @@
+# Maintainer: Drew DeVault <[email-masked]>
+pkgname=go-msgauth
+pkgver=0.6.2
+pkgrel=0
+pkgdesc="Go utilities for DKIM, DMARC, and Authentication-Results"
+url="https://github.com/emersion/go-msgauth"
+arch="all"
+license="MIT"
+install="$pkgname.pre-install"
+makedepends="go"
+source="
+	$pkgname-$pkgver.tar.gz::https://github.com/emersion/go-msgauth/archive/v$pkgver.tar.gz
+	dkim-milter.confd
+	dkim-milter.initd
+"
+subpackages="$pkgname-openrc"
+
+build() {
+	go mod vendor
+	for bin in dkim-milter dkim-verify dkim-keygen dmarc-lookup
+	do
+		go build \
+			-trimpath \
+			-mod=vendor \
+			-ldflags "-extldflags $LDFLAGS" \
+			./cmd/$bin
+	done
+}
+
+check() {
+	go test ./...
+}
+
+package() {
+	for bin in dkim-milter dkim-verify dkim-keygen dmarc-lookup
+	do
+		install -Dm755 $bin "$pkgdir"/usr/bin/$bin
+	done
+
+	install -Dm755 "$srcdir"/dkim-milter.initd \
+		"$pkgdir"/etc/init.d/dkim-milter
+	install -Dm644 "$srcdir"/dkim-milter.confd \
+		"$pkgdir"/etc/conf.d/dkim-milter
+}
+
+sha512sums="4376a0a6c2e636dad30febfa357f4a208492fa666478a7b58802f0774f665487bbe9348ff83ea3a436dbc943b12db91936091920d141d8c19e1d961413c80a84  go-msgauth-0.6.2.tar.gz
+5a213a85bab469b4ee6a144eac69ab452a791886d7faaa46da1f12a9f03248eea1bf1118f637cf282e6c49c9b432c57de2651fb3f33bc3e4ad9f40dde6490aa5  dkim-milter.confd
+8483e40792067db6e9e43563cc02d1c28f4fe74d10d43722a4dbce2e4ec6a4daa391f6aa1b428e76ddddbd2a2fa07bd5080a94d8264d1fd5a30c1659726f9de2  dkim-milter.initd"
diff --git a/community/go-msgauth/dkim-milter.confd b/community/go-msgauth/dkim-milter.confd
new file mode 100644
index 0000000000..4b7713abf8
--- /dev/null
+++ b/community/go-msgauth/dkim-milter.confd
@@ -0,0 +1,27 @@
+# Address to listen for milter connections on
+#
+# tcp://[ip]:[port]
+# or
+# unix://path/to/socket
+dkim_listen_address=tcp://127.0.0.1:8891
+
+# Space separated list of domains to sign for outgoing mails
+dkim_sign_domains=
+
+# Selector for DNS DKIM key (i.e. $dkim_selector._domainkey TXT)
+dkim_selector=
+
+# Path to DKIM key
+#
+# Generate key:
+# $ dkim-keygen -f /var/lib/dkim/example.key
+#
+# Then configure:
+# dkim_key=/var/lib/dkim/example.key
+dkim_key=
+
+# Name of this mail server, defaults to hostname
+dkim_host=
+
+output_log=/var/log/dkim-milter.log
+error_log=/var/log/dkim-milter.log
diff --git a/community/go-msgauth/dkim-milter.initd b/community/go-msgauth/dkim-milter.initd
new file mode 100644
index 0000000000..68c59811f4
--- /dev/null
+++ b/community/go-msgauth/dkim-milter.initd
@@ -0,0 +1,29 @@
+#!/sbin/openrc-run
+name="dkim-milter"
+description="Milter for DKIM signatures and verification"
+supervisor=supervise-daemon
+command=/usr/bin/dkim-milter
+_domains=
+for d in $dkim_sign_domains
+do
+	_domains="$_domains -d $d"
+done
+command_args="-l $dkim_listen_address -s $dkim_selector -k $dkim_key $_domains"
+if [ -n "$dkim_host" ]
+then
+	command_args="$command_args -i $dkim_host"
+fi
+command_user="dkim:dkim"
+
+start_pre() {
+	[ -n "$output_log" ] && checkpath -f "$output_log" \
+		-m 644 -o dkim:dkim
+	[ -n "$error_log" ] && checkpath -f "$error_log" \
+		-m 644 -o dkim:dkim
+	if [ -z "$dkim_sign_domains" ] || [ -z "$dkim_key" ] || [ -z "$dkim_selector" ]
+	then
+		eerror "$RC_SVCNAME is not configured to sign any domains"
+		eerror "Edit /etc/conf.d/$RC_SVCNAME before continuing"
+		eend 1
+	fi
+}
diff --git a/community/go-msgauth/go-msgauth.pre-install b/community/go-msgauth/go-msgauth.pre-install
new file mode 100644
index 0000000000..b65be01b1c
--- /dev/null
+++ b/community/go-msgauth/go-msgauth.pre-install
@@ -0,0 +1,4 @@
+#!/bin/sh
+grep '^dkim' /etc/group >/dev/null || addgroup -S dkim 2>/dev/null
+grep '^dkim' /etc/passwd >/dev/null || adduser -SDh/var/lib/dkim \
+	-s/sbin/nologin -Gdkim -gdkim dkim dkim 2>/dev/null
-- 
2.29.2