Subject: [alpine-aports] [PATCH] testing/go-dkim: new APKBUILD

From: Drew DeVault <[email-masked]>
Date: Mon, 11 Mar 2019 18:22:11 -0600

---
I'm not great at openrc scripts, feedback welcome.

 testing/go-dkim/APKBUILD             | 42 +++++++++++++++++++++++++
 testing/go-dkim/dkim-milter.confd    | 16 ++++++++++
 testing/go-dkim/dkim-milter.initd    | 46 ++++++++++++++++++++++++++++
 testing/go-dkim/go-dkim.post-install |  3 ++
 4 files changed, 107 insertions(+)
 create mode 100644 testing/go-dkim/APKBUILD
 create mode 100644 testing/go-dkim/dkim-milter.confd
 create mode 100644 testing/go-dkim/dkim-milter.initd
 create mode 100644 testing/go-dkim/go-dkim.post-install

diff --git a/testing/go-dkim/APKBUILD b/testing/go-dkim/APKBUILD
new file mode 100644
index 0000000000..0a79c64daf
--- /dev/null
+++ b/testing/go-dkim/APKBUILD
@@ -0,0 +1,42 @@
+# Maintainer: Drew DeVault <[email-masked]>
+pkgname=go-dkim
+pkgver=0.3.0
+pkgrel=0
+pkgdesc="DKIM verification tool & milter"
+url="https://github.com/emersion/go-dkim"
+arch="all"
+license="MIT"
+makedepends="go"
+source="
+	$pkgname-$pkgver.tar.gz::https://github.com/emersion/$pkgname/archive/v$pkgver.tar.gz
+	dkim-milter.initd
+	dkim-milter.confd
+	"
+install="$pkgname.post-install"
+subpackages="$pkgname-openrc"
+builddir="$srcdir/$pkgname-$pkgver"
+
+build() {
+	cd "$builddir"
+	go build -o dkim-milter cmd/dkim-milter/main.go
+	go build -o dkim-verify cmd/dkim-verify/main.go
+}
+
+check() {
+	cd "$builddir"
+	go test ./...
+}
+
+package() {
+	cd "$builddir"
+	install -Dm755 dkim-milter "$pkgdir"/usr/bin/dkim-milter
+	install -Dm755 dkim-verify "$pkgdir"/usr/bin/dkim-verify
+	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="bb25ae9e7f3d3db397132b8149a9014a4f76d036352df4a0184dfdf1481052373a4e6208023073b6401806dedeca2fcd560f1ccd738c6fd49b166ccb8471a198  go-dkim-0.3.0.tar.gz
+cbf39406c1f0d0eb6d1d213381d05a5eea5cf19fb6b19ed5e3ac9b2f64b8393ef3a3652a6aac34c5109e9c95930fca205db332b8e8a254811c6cd93e10df6a64  dkim-milter.initd
+24b3d0756e6a2ee741361c224f9064980802f72ca35f402ca0c185ee8dcbd0beaea68f5b9fd86f06c697674b4c752aea45945dd128e98ff97d44f229ba428101  dkim-milter.confd"
diff --git a/testing/go-dkim/dkim-milter.confd b/testing/go-dkim/dkim-milter.confd
new file mode 100644
index 0000000000..a5d9a95280
--- /dev/null
+++ b/testing/go-dkim/dkim-milter.confd
@@ -0,0 +1,16 @@
+# DKIM milter OpenRC configuration
+# 
+
+# Specify the identity of the DKIM server, to be added in the
+# Authentication-Results header. Defaults to hostname.
+#
+#identity="mail.example.org"
+
+# The user & group to run the dkim-milter daemon as.
+# 
+#dkim_user="dkim"
+#dkim_group="dkim"
+
+# The socket to listen for milter messages on.
+#
+#dkim_listen="unix:///tmp/dkim-milter.sock"
diff --git a/testing/go-dkim/dkim-milter.initd b/testing/go-dkim/dkim-milter.initd
new file mode 100644
index 0000000000..72b1faa0fc
--- /dev/null
+++ b/testing/go-dkim/dkim-milter.initd
@@ -0,0 +1,46 @@
+#!/sbin/openrc-run
+name=dkim-milter
+
+: ${user:=dkim}
+: ${group:=dkim}
+: ${identity:=$(hostname)}
+: ${socket:=/run/dkim-milter/milter.sock}
+: ${listen:=unix://$socket}
+
+command="/usr/bin/$name"
+command_background="yes"
+pidfile="/run/$name.pid"
+
+depend() {
+	need net
+	before mta
+	after firewall
+}
+
+start_pre() {
+	if [ "$listen" = "unix://$socket" ]
+	then
+		checkpath -d -o "$user:$group" "${socket%/*}"
+	fi
+}
+
+start() {
+	ebegin "Starting $name"
+	start-stop-daemon --start \
+		--background \
+		--umask 002 \
+		--user "$user" \
+		--group "$group" \
+		--exec "$command" \
+		--pidfile "$pidfile" \
+		-- -i "$identity" -l "$listen"
+	eend $?
+}
+
+stop() {
+	ebegin "Stopping $name"
+	start-stop-daemon --stop \
+		--exec "$command" \
+		--pidfile "$pidfile"
+	eend $?
+}
diff --git a/testing/go-dkim/go-dkim.post-install b/testing/go-dkim/go-dkim.post-install
new file mode 100644
index 0000000000..3b8dc74a50
--- /dev/null
+++ b/testing/go-dkim/go-dkim.post-install
@@ -0,0 +1,3 @@
+#!/bin/sh
+addgroup -S dkim || true
+adduser -SDH -s /sbin/nologin -g dkim dkim || true
-- 
2.21.0

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Leonardo <[email-masked]>
Date: Wed, 3 Apr 2019 14:55:58 +0200

Hi,

> I'm not great at openrc scripts, feedback welcome.

it looks good to me. You can avoid writing start() and stop() functions 
using "command_args" and "start_stop_daemon_args" to pass custom options.

>   create mode 100644 testing/go-dkim/go-dkim.post-install

It seems that the build is not reproducible, since it seems to download 
some dependencies during the build process:

go: downloading github.com/emersion/go-milter 
v0.0.0-20190311184326-c3095a41a6fe
go: downloading github.com/emersion/go-msgauth 
v0.0.0-20190307192406-8646172ce7a5
go: downloading golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2

Am I mistaken?

Thanks!

/eo

---