Subject: [alpine-aports] [PATCH] community/opendkim: fix running depends, close #6122

From: Valery Kartel <[email-masked]>
Date: Mon, 12 Dec 2016 18:21:30 +0200

--
non-daemon binaries with perl dependency moved to -utils
fixes in installation, config and daemon starting
made running out of box
---
 community/opendkim/APKBUILD                        | 51 ++++++++++++----------
 .../opendkim/{opendkim.conf => opendkim.confd}     |  0
 community/opendkim/opendkim.initd                  |  8 ++--
 community/opendkim/opendkim.post-install           | 26 +++++++++++
 community/opendkim/opendkim.pre-install            |  3 +-
 5 files changed, 60 insertions(+), 28 deletions(-)
 rename community/opendkim/{opendkim.conf => opendkim.confd} (100%)
 create mode 100644 community/opendkim/opendkim.post-install

diff --git a/community/opendkim/APKBUILD b/community/opendkim/APKBUILD
index 01d8f6e059..fdd6014259 100644
--- a/community/opendkim/APKBUILD
+++ b/community/opendkim/APKBUILD
@@ -3,20 +3,20 @@
 # Maintainer: Valery Kartel <[email-masked]>
 pkgname=opendkim
 pkgver=2.10.3
-pkgrel=4
+pkgrel=5
 pkgdesc="DKIM signing and verifying filter for MTAs"
 url="http://www.opendkim.org"
 arch="all"
 license="custom"
+depends="libressl"
 makedepends="libressl-dev libmilter-dev"
 pkgusers="opendkim"
 pkggroups="opendkim"
-subpackages="$pkgname-dev $pkgname-doc $pkgname-libs $pkgname-dbg"
-install="$pkgname.pre-install"
+subpackages="$pkgname-dev $pkgname-doc $pkgname-libs $pkgname-dbg $pkgname-utils"
+install="$pkgname.pre-install $pkgname.post-install"
 source="http://downloads.sourceforge.net/project/$pkgname/$pkgname-$pkgver.tar.gz
-	opendkim.conf
-	opendkim.initd"
-builddir="$srcdir/$pkgname-$pkgver"
+	$pkgname.initd"
+builddir="$srcdir"/$pkgname-$pkgver
 
 build() {
 	cd "$builddir"
@@ -24,34 +24,39 @@ build() {
 		--build=$CBUILD \
 		--host=$CHOST \
 		--prefix=/usr \
+		--sysconfdir=/etc/$pkgname \
 		|| return 1
 	make || return 1
 }
 
 package() {
 	cd "$builddir"
-
 	make DESTDIR="$pkgdir" install || return 1
+	install -Dm644 "$pkgdir"/usr/share/doc/$pkgname/$pkgname.conf.simple \
+		"$pkgdir"/etc/$pkgname/$pkgname.conf || return 1
+	install -d "$pkgdir"/var/db/dkim
+	install -d "$pkgdir"/usr/share/licenses/$pkgname;
+	mv "$pkgdir"/usr/share/doc/$pkgname/LICENSE* \
+		"$pkgdir"/usr/share/licenses/$pkgname
+	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
+}
 
-	install -Dm644 "$pkgdir"/usr/share/doc/opendkim/opendkim.conf.sample \
-		"$pkgdir"/etc/opendkim/opendkim.conf.sample || return 1
-	install -Dm644 LICENSE \
-		"$pkgdir"/usr/share/licenses/$pkgname/LICENSE || return 1
-	install -Dm644 LICENSE.Sendmail \
-		"$pkgdir"/usr/share/licenses/$pkgname/LICENSE.Sendmail || return 1
+utils() {
+	pkgdesc="$pkgdesc (key and zone utilities)"
+	depends="$depends perl"
+	install -d "$subpkgdir"/usr/bin
+	mv "$pkgdir"/usr/sbin/$pkgname-* "$subpkgdir"/usr/bin
+	rm -fr "$pkgdir"/usr/lib
+}
 
-	install -m755 -D "$srcdir"/$pkgname.initd \
-		"$pkgdir"/etc/init.d/$pkgname || return 1
-	install -m644 -D "$srcdir"/$pkgname.conf \
-		"$pkgdir"/etc/conf.d/$pkgname
+libs() {
+	depends=
+	default_libs
 }
 
 md5sums="916e691cdd16cfabd1cd6efe745323f9  opendkim-2.10.3.tar.gz
-a4fadd2a9de27bfbc83173db4db9a7f5  opendkim.conf
-72e7beb15c2dcc0fef5f06edb0f285f1  opendkim.initd"
+bc8b71925ea947d82cb0cde991aee0a1  opendkim.initd"
 sha256sums="43a0ba57bf942095fe159d0748d8933c6b1dd1117caf0273fa9a0003215e681b  opendkim-2.10.3.tar.gz
-b030ab34d324d75b353a1d3ee1483da497ad2be76dec0ddba6c25547d833dca0  opendkim.conf
-bfed96e5a9e8e68ee2c66feed9a37270967eaf62a554367658c517f3bec87b5c  opendkim.initd"
+cf366c6715b3aaa87587aefae599e51c74c77aabdcc58b2782e9922b582b8145  opendkim.initd"
 sha512sums="97923e533d072c07ae4d16a46cbed95ee799aa50f19468d8bc6d1dc534025a8616c3b4b68b5842bc899b509349a2c9a67312d574a726b048c0ea46dd4fcc45d8  opendkim-2.10.3.tar.gz
-8a9ae1d6879ee20493f1fdd69ca750ca6cca8cdecea37a4b87dd67cd843491ea9e1dc2f3a2636acd1d22e961f9f61763beb898e4c58b534e3a1c9c8b1d6a3b69  opendkim.conf
-421888b3c41e97512139d30fdb55dcfa03c3c1596c67107c7e5d5a31edafff869b774d37d40f644ed967f507f15179202fc6351df4692904f25f5ad8a955652f  opendkim.initd"
+156c32e55a131307dbeafdbe512b5157734b0785b0561a734cd1a0bd8368243cfcc66805a91905d7b46545384b1c5565207686865af792a36669bf74b9c21c71  opendkim.initd"
diff --git a/community/opendkim/opendkim.conf b/community/opendkim/opendkim.confd
similarity index 100%
rename from community/opendkim/opendkim.conf
rename to community/opendkim/opendkim.confd
diff --git a/community/opendkim/opendkim.initd b/community/opendkim/opendkim.initd
index 843798f5ad..4b7d6170ee 100644
--- a/community/opendkim/opendkim.initd
+++ b/community/opendkim/opendkim.initd
@@ -1,10 +1,12 @@
 #!/sbin/openrc-run
 
+owner=opendkim
 pidfile=/run/opendkim/opendkim.pid
-
+cfgfile=/etc/opendkim/opendkim.conf
 command=/usr/sbin/opendkim
-command_args="-f ${EXTRA_OPTS}"
+command_args="-f -u $owner"
 command_background=yes
+required_files="$cfgfile"
 
 depend() {
 	need net
@@ -12,5 +14,5 @@ depend() {
 }
 
 start_pre() {
-	checkpath -d -o opendkim:opendkim -m755 /run/opendkim
+	checkpath -dm755 -o $owner ${pidfile%/*}
 }
diff --git a/community/opendkim/opendkim.post-install b/community/opendkim/opendkim.post-install
new file mode 100644
index 0000000000..050e612da4
--- /dev/null
+++ b/community/opendkim/opendkim.post-install
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+selector=$(grep ^Selector /etc/opendkim/opendkim.conf | awk '{print $2}')
+keyfile=$(grep ^KeyFile /etc/opendkim/opendkim.conf | awk '{print $2}')
+domain=$(grep ^Domain /etc/opendkim/opendkim.conf | awk '{print $2}')
+
+keydir=${keyfile%/*}
+keyfile=${keyfile##*/}
+keyname=${keyfile%.private}
+
+if [  ! -f $keydir/$keyname.txt ]; then
+	[ ! -d $keydir ] && mkdir -p $keydir
+	openssl genrsa -out $keydir/$keyfile 1024 > /dev/null 2>&1
+	openssl rsa -in $keydir/$keyfile -pubout \
+		-out $keydir/$keyname.public -outform PEM > /dev/null 2>&1
+	chmod 640 $keydir/$keyfile
+	if [ "$domain" ]; then
+		echo -en "$selector._domainkey IN TXT (\n\"v=DKIM1; k=rsa;\"\n\"p=" > $keydir/$keyname.txt
+		grep -v ^- $keydir/$keyname.public | tr -d '\n' >> $keydir/$keyname.txt
+		echo -e "\"\n) ; ----- DKIM key $selector for $domain" >> $keydir/$keyname.txt
+		rm $keydir/$keyname.public
+	fi
+	chown -R root:opendkim $keydir
+fi
+
+exit 0
diff --git a/community/opendkim/opendkim.pre-install b/community/opendkim/opendkim.pre-install
index 25d3fd7538..4e30582fc2 100644
--- a/community/opendkim/opendkim.pre-install
+++ b/community/opendkim/opendkim.pre-install
@@ -1,7 +1,6 @@
 #!/bin/sh
 
 addgroup -S opendkim 2>/dev/null
-adduser -S -D -H -s /bin/false -G opendkim -g opendkim opendkim 2>/dev/null
+adduser -SDH -h /run/opendkim -s /sbin/nologin -G opendkim -g opendkim opendkim 2>/dev/null
 
 exit 0
-
-- 
2.11.0

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