Subject: [PATCH] Update rspamd to 2.2, change luajit to lua for arm compatibility and update other dependencies. Remove old patches and split rspamc, libs, and www interface files so rspamc can be installed on its own. Stop splitting fuzzy, controller, etc as just conf files. User should control with conf files in local.d and ovveride.d. Fixed some typos

From: Duncan Bellamy <[email-masked]>
Date: Sat, 25 Jan 2020 11:02:31 +0000

---
 community/rspamd/APKBUILD                     | 171 +++++++-----------
 community/rspamd/cmakelists.patch             |  10 -
 community/rspamd/conf-split-workers.patch     |  88 ---------
 community/rspamd/default-configs.patch        |  32 ----
 .../rspamd/lua-torch-fix-simd-detection.patch |  77 --------
 community/rspamd/rspamd.initd                 |   2 +-
 community/rspamd/rspamd.post-upgrade          |  12 --
 7 files changed, 64 insertions(+), 328 deletions(-)
 delete mode 100644 community/rspamd/cmakelists.patch
 delete mode 100644 community/rspamd/conf-split-workers.patch
 delete mode 100644 community/rspamd/default-configs.patch
 delete mode 100644 community/rspamd/lua-torch-fix-simd-detection.patch
 delete mode 100644 community/rspamd/rspamd.post-upgrade

diff --git a/community/rspamd/APKBUILD b/community/rspamd/APKBUILD
index fede7b5315..ca85fb53d5 100644
--- a/community/rspamd/APKBUILD
+++ b/community/rspamd/APKBUILD
@@ -3,161 +3,116 @@
 # Contributor: Nathan Angelacos <[email-masked]>
 # Contributor: TBK <[email-masked]>
 # Contributor: Jakub Jirutka <[email-masked]>
-pkgname=rspamd
-pkgver=1.9.4
-pkgrel=1
+# Contributor: Duncan Bellamy <[email-masked]>
+pkgname="rspamd"
+pkgver="2.2"
+pkgrel=0
 pkgdesc="Fast, free and open-source spam filtering system"
-url="https://rspamd.com/"
+url="https://rspamd.com"
 arch="all !s390x"
 license="Apache-2.0 BSD-1-Clause BSD-2-Clause BSD-3-Clause CC0 LGPL-2.1-or-later
 	LGPL-3.0-only MIT Zlib"
 pkgusers="rspamd"
 pkggroups="rspamd"
-makedepends="
-	cmake
-	curl-dev
-	file-dev
-	gd-dev
+makedepends="cmake
 	glib-dev
 	icu-dev
-	libevent-dev
 	openssl-dev
-	luajit-dev
-	pcre2-dev
-	perl
+	lua5.1-dev
 	ragel
 	sqlite-dev
-	"
-checkdepends="luarocks"
-install="$pkgname.pre-install $pkgname.post-upgrade"
-subpackages="
-	$pkgname-doc
-	$pkgname-client
+	libsodium-dev
+	libmagic
+	pcre2-dev
+"
+install="$pkgname.pre-install"
+subpackages="$pkgname-client
 	$pkgname-utils::noarch
-	$pkgname-controller::noarch
-	$pkgname-fuzzy::noarch
-	$pkgname-proxy::noarch
+	$pkgname-doc
+	$pkgname-libs
+	$pkgname-www::noarch
 	$pkgname-openrc
-	$pkgname-dbg
-	"
-source="$pkgname-$pkgver.tar.gz::https://github.com/vstakhov/$pkgname/archive/$pkgver.tar.gz
-	$pkgname.logrotated
-	$pkgname.initd
-	$pkgname.confd
-	cmakelists.patch
-	conf-split-workers.patch
-	default-configs.patch
-	lua-torch-fix-simd-detection.patch
+"
+
+source="$pkgname-$pkgver.tar.gz::https://github.com/vstakhov/rspamd/archive/$pkgver.tar.gz
+	rspamd.initd
+	rspamd.confd
+	rspamd.logrotated
 	"
+_cmakedir="$srcdir"/$pkgname.build
 
 build() {
-	cmake . \
+	mkdir -p $_cmakedir
+	cd $_cmakedir
+
+	cmake \
 		-DCMAKE_INSTALL_PREFIX=/usr \
 		-DCONFDIR=/etc/$pkgname \
 		-DRUNDIR=/run/$pkgname \
-		-DRSPAMD_USER=$pkgusers \
-		-DRSPAMD_GROUP=$pkggroups \
-		-DENABLE_DB=ON \
-		-DENABLE_SQLITE=ON \
-		-DENABLE_HIREDIS=ON \
 		-DENABLE_REDIRECTOR=ON \
-		-DENABLE_URL_INCLUDE=ON \
 		-DENABLE_PCRE2=ON \
-		-DINSTALL_EXAMPLES=OFF
+		"$builddir"
 	make
 }
 
 check() {
-	make rspamd-test
+	cd $_cmakedir
+	make check
 }
 
 package() {
+	cd $_cmakedir
 	make DESTDIR="$pkgdir" install
-
 	cd "$pkgdir"
-
 	find usr/bin -type l -delete
-	mkdir -p ./usr/sbin
-	mv ./usr/bin/rspamd-$pkgver ./usr/sbin/rspamd
-	mv ./usr/bin/rspamadm-$pkgver ./usr/bin/rspamadm
 
-	mkdir -p ./usr/share/doc/$pkgname
-	mv ./usr/share/$pkgname/www/README.md \
-		./usr/share/$pkgname/www/plugins.txt \
-		./usr/share/doc/$pkgname/
-
-	install -Dm 644 "$srcdir"/$pkgname.logrotated ./etc/logrotate.d/$pkgname
-	install -Dm 755 "$srcdir"/$pkgname.initd ./etc/init.d/$pkgname
-	install -Dm 644 "$srcdir"/$pkgname.confd ./etc/conf.d/$pkgname
+	mv ./usr/bin/rspamd-$pkgver ./usr/bin/rspamd
+	mv ./usr/bin/rspamadm-$pkgver ./usr/bin/rspamadm
 
-	mkdir -p ./etc/$pkgname/local.d \
-		./etc/$pkgname/override.d
+	install -m755 -D "$startdir"/$pkgname.initd \
+		./etc/init.d/$pkgname
+	install -m644 -D "$startdir"/$pkgname.confd \
+		./etc/conf.d/$pkgname
+	install -Dm 644 "$startdir"/$pkgname.logrotated \
+		./etc/logrotate.d/$pkgname
 
 	install -dm 750 -o rspamd -g rspamd \
-		./var/lib/$pkgname \
-		./var/lib/$pkgname/dynamic
+		$subpkgdir/var/lib/$pkgname
 	install -dm 750 -o rspamd -g rspamd \
-		./var/log/$pkgname
+		$subpkgdir/var/log/$pkgname
 }
 
-client() {
-	pkgdesc="$pkgdesc (console client)"
+libs() {
+	pkgdesc="$pkgdesc (libraries)"
+	cd "$pkgdir"/usr/lib/$pkgname
+	mkdir -p "$subpkgdir"/usr/lib/$pkgname
+	mv *.so "$subpkgdir"/usr/lib/$pkgname
+}
 
-	cd "$pkgdir"
+www() {
+	pkgdesc="$pkgdesc (server web interface files)"
+	mkdir -p "$subpkgdir"/usr/share/$pkgname
+	cd "$pkgdir"/usr/share/$pkgname/
+	mv www "$subpkgdir"/usr/share/$pkgname/
+}
+
+client() {
+	pkgdesc="$pkgdesc (rspamd client rspamc)"
 	mkdir -p "$subpkgdir"/usr/bin
-	mv ./usr/bin/rspamc-$pkgver "$subpkgdir"/usr/bin/rspamc
+	mv "$pkgdir"/usr/bin/rspamc-$pkgver $subpkgdir/usr/bin/rspamc
 }
 
 utils() {
 	pkgdesc="$pkgdesc (utilities)"
-	depends="perl"
+	depeneds="perl"
 
 	cd "$pkgdir"
 	mkdir -p "$subpkgdir"/usr/bin
-	mv ./usr/bin/${pkgname}_stats "$subpkgdir"/usr/bin/${pkgname}-stats
-	_mv ./usr/bin/${pkgname}-redirector "$subpkgdir"/usr/bin/
-}
-
-fuzzy() {
-	pkgdesc="$pkgdesc (local fuzzy storage)"
-	license="Apache-2.0"
-	depends="$pkgname"
-
-	cd "$pkgdir"
-	_mv ./etc/$pkgname/worker-fuzzy.* "$subpkgdir"/etc/$pkgname/
-	_mv ./etc/$pkgname/modules.d/fuzzy_* "$subpkgdir"/etc/$pkgname/modules.d/
-}
-
-controller() {
-	pkgdesc="$pkgdesc (controller web interface)"
-	license="MIT"
-	depends="$pkgname"
-
-	cd "$pkgdir"
-	_mv ./usr/share/$pkgname/www "$subpkgdir"/usr/share/$pkgname/
-	_mv ./etc/$pkgname/worker-controller.* "$subpkgdir"/etc/$pkgname/
-}
-
-proxy() {
-	pkgdesc="$pkgdesc (milter support)"
-	license="Apache-2.0"
-	depends="$pkgname"
-
-	cd "$pkgdir"
-	_mv ./etc/$pkgname/worker-proxy.* "$subpkgdir"/etc/$pkgname/
-}
-
-_mv() {
-	local dest; for dest; do true; done  # get last argument
-	mkdir -p "$dest"
-	mv "$@"
+	mv ./usr/bin/"$pkgname"_stats "$subpkgdir"/usr/bin/"$pkgname"-stats
+	mv ./usr/bin/"$pkgname"-redirector "$subpkgdir"/usr/bin/
 }
 
-sha512sums="3acecec6adb91580ac2ad96419fdc9588b120ec5a3b4a44135fc5a3e7c15f2dbc99963a8337f9effb9423846489545a55d89d1849c5ba62d8cd91dc67c32d8dc  rspamd-1.9.4.tar.gz
-2efe28575c40d1fba84b189bb872860e744400db80dce2f6330be6c6287fb3f46e6511284729b957488bf40bcb9b0952e26df9934f5f138334bd2766075c45cb  rspamd.logrotated
-7add88e4bf3508d2a148241cd8db97851a33a7128be75f2a072a029b32b565e9de0299ad614fbda7f70ed54d1b6e2faa305eff3e443e90451abf59dedc1af576  rspamd.initd
+sha512sums="e62367b9d663a005686e3eef216a7913c6050125e96582e2a58ef459e14512c1bcf09108050ff8ef524ba5e7a3c78559805353a25510654d8764f985757b32fe  rspamd-2.2.tar.gz
+141c845cee32384b3ca02e066f133211612c4c36740cbd7d658245a070223366325f5890d45d28bbd2fcfa3712ec460bf4de779bad2183ab8e0cf635d25e985f  rspamd.initd
 a2003ef0c9d64a44480f59302864a2dfedcbe3a0047fcbb655408bc8aae9014b6ad0ddc6b64d4abeeb21bea0f86678afd30589ac8eed83e07ad7f87710e93702  rspamd.confd
-accbe762e542df65e28301048672d4a0cf3a1c7e9a04c38ab3010f0ed9df9ad1122129727580408a69939f25c4dbea3b2b7aa0d452722125fac9eb0043bb2579  cmakelists.patch
-a8aefee649bf6630339d1d3f2bb20c25ca70b21a8eaa92951e926d0fd4525f1d4ac4cc7ea66ac2b15323cf02c93c759ddf7181502f0d71b21384ced9d88c008e  conf-split-workers.patch
-bca1b1361524e1c582f2d6f9d754766c63f60a856b9f0d858e17dfebb40f2046db3a759eb3dffc5075460c3d3b64224092e043f07bcd8331daa97babc61ea973  default-configs.patch
-2987f122653680207b97a9f93978192384804f93a8fa040085e53a801c77364e8bd7ceb0fabca62a9c7316ff32bcf3dee8f0d1b8cd2c29459c6272a19e8e293b  lua-torch-fix-simd-detection.patch"
+2efe28575c40d1fba84b189bb872860e744400db80dce2f6330be6c6287fb3f46e6511284729b957488bf40bcb9b0952e26df9934f5f138334bd2766075c45cb  rspamd.logrotated"
diff --git a/community/rspamd/cmakelists.patch b/community/rspamd/cmakelists.patch
deleted file mode 100644
index 8b9c7fe84d..0000000000
--- a/community/rspamd/cmakelists.patch
+++ /dev/null
@@ -1,10 +0,0 @@
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -589,7 +589,6 @@
- 	LIST(APPEND CMAKE_REQUIRED_LIBRARIES rt)
- 	LIST(APPEND CMAKE_REQUIRED_LIBRARIES dl)
- 	LIST(APPEND CMAKE_REQUIRED_LIBRARIES resolv)
--	LIST(APPEND CMAKE_REQUIRED_LIBRARIES nsl)
- 	LIST(APPEND CMAKE_REQUIRED_LIBRARIES socket)
- 	LIST(APPEND CMAKE_REQUIRED_LIBRARIES umem)
- 	# Ugly hack, but FindOpenSSL on Solaris does not link with libcrypto
diff --git a/community/rspamd/conf-split-workers.patch b/community/rspamd/conf-split-workers.patch
deleted file mode 100644
index 505d2c72e0..0000000000
--- a/community/rspamd/conf-split-workers.patch
+++ /dev/null
@@ -1,88 +0,0 @@
-Since we split workers into subpackages, we have to split the main config
-that defines workers to be loaded.
-
-NOTE: This is intentionally done in patch file instead of modifying the config
-with sed and generating the worker configs to avoid silent breakages when
-upgrading the aport!
-
---- a/conf/rspamd.conf
-+++ b/conf/rspamd.conf
-@@ -35,33 +35,4 @@
-     .include(try=true; priority=10) "$LOCAL_CONFDIR/override.d/logging.inc"
- }
- 
--worker "normal" {
--    bind_socket = "localhost:11333";
--    .include "$CONFDIR/worker-normal.inc"
--    .include(try=true; priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/worker-normal.inc"
--    .include(try=true; priority=10) "$LOCAL_CONFDIR/override.d/worker-normal.inc"
--}
--
--worker "controller" {
--    bind_socket = "localhost:11334";
--    .include "$CONFDIR/worker-controller.inc"
--    .include(try=true; priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/worker-controller.inc"
--    .include(try=true; priority=10) "$LOCAL_CONFDIR/override.d/worker-controller.inc"
--}
--
--worker "rspamd_proxy" {
--    bind_socket = "localhost:11332";
--    .include "$CONFDIR/worker-proxy.inc"
--    .include(try=true; priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/worker-proxy.inc"
--    .include(try=true; priority=10) "$LOCAL_CONFDIR/override.d/worker-proxy.inc"
--}
--
--# Local fuzzy storage is disabled by default
--
--worker "fuzzy" {
--    bind_socket = "localhost:11335";
--    count = -1; # Disable by default
--    .include "$CONFDIR/worker-fuzzy.inc"
--    .include(try=true; priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/worker-fuzzy.inc"
--    .include(try=true; priority=10) "$LOCAL_CONFDIR/override.d/worker-fuzzy.inc"
--}
-+.include(glob=true) "$CONFDIR/worker-*.conf"
---- /dev/null
-+++ b/conf/worker-normal.conf
-@@ -0,0 +1,8 @@
-+# Included from top-level .conf file
-+
-+worker "normal" {
-+    bind_socket = "localhost:11333";
-+    .include "$CONFDIR/worker-normal.inc"
-+    .include(try=true; priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/worker-normal.inc"
-+    .include(try=true; priority=10) "$LOCAL_CONFDIR/override.d/worker-normal.inc"
-+}
---- /dev/null
-+++ b/conf/worker-controller.conf
-@@ -0,0 +1,8 @@
-+# Included from top-level .conf file
-+
-+worker "controller" {
-+    bind_socket = "localhost:11334";
-+    .include "$CONFDIR/worker-controller.inc"
-+    .include(try=true; priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/worker-controller.inc"
-+    .include(try=true; priority=10) "$LOCAL_CONFDIR/override.d/worker-controller.inc"
-+}
---- /dev/null
-+++ b/conf/worker-proxy.conf
-@@ -0,0 +1,8 @@
-+# Included from top-level .conf file
-+
-+worker "rspamd_proxy" {
-+    bind_socket = "localhost:11332";
-+    .include "$CONFDIR/worker-proxy.inc"
-+    .include(try=true; priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/worker-proxy.inc"
-+    .include(try=true; priority=10) "$LOCAL_CONFDIR/override.d/worker-proxy.inc"
-+}
---- /dev/null
-+++ b/conf/worker-fuzzy.conf
-@@ -0,0 +1,8 @@
-+# Included from top-level .conf file
-+
-+worker "fuzzy" {
-+    bind_socket = "localhost:11335";
-+    .include "$CONFDIR/worker-fuzzy.inc"
-+    .include(try=true; priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/worker-fuzzy.inc"
-+    .include(try=true; priority=10) "$LOCAL_CONFDIR/override.d/worker-fuzzy.inc"
-+}
diff --git a/community/rspamd/default-configs.patch b/community/rspamd/default-configs.patch
deleted file mode 100644
index fd428c78ca..0000000000
--- a/community/rspamd/default-configs.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-Distro-specific adjustments of the default configs.
-
---- a/conf/options.inc
-+++ b/conf/options.inc
-@@ -8,7 +8,7 @@
- map_watch_interval = 5min;
- # Multiplier for watch interval for files
- map_file_watch_multiplier = 0.1;
--dynamic_conf = "$DBDIR/rspamd_dynamic";
-+dynamic_conf = "$DBDIR/dynamic";
- history_file = "$DBDIR/rspamd.history";
- check_all_filters = false;
- dns {
-@@ -25,7 +25,7 @@
- 	"X-MimeOLE",
- ];
- 
--control_socket = "$DBDIR/rspamd.sock mode=0600";
-+control_socket = "$RUNDIR/rspamd.sock mode=0600";
- history_rows = 200;
- explicit_modules = ["settings", "bayes_expiry"];
- 
---- a/conf/rspamd.conf
-+++ b/conf/rspamd.conf
-@@ -18,7 +18,6 @@
- .include "$CONFDIR/common.conf"
- 
- options {
--    pidfile = "$RUNDIR/rspamd.pid";
-     .include "$CONFDIR/options.inc"
-     .include(try=true; priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/options.inc"
-     .include(try=true; priority=10) "$LOCAL_CONFDIR/override.d/options.inc"
diff --git a/community/rspamd/lua-torch-fix-simd-detection.patch b/community/rspamd/lua-torch-fix-simd-detection.patch
deleted file mode 100644
index f3df6f87de..0000000000
--- a/community/rspamd/lua-torch-fix-simd-detection.patch
+++ /dev/null
@@ -1,77 +0,0 @@
---- a/contrib/lua-torch/torch7/lib/TH/generic/simd/simd.h
-+++ b/contrib/lua-torch/torch7/lib/TH/generic/simd/simd.h
-@@ -45,7 +45,7 @@
-   SIMDExtension_NEON    = 0x1,
- #elif defined(__PPC64__)
-   SIMDExtension_VSX     = 0x1,
--#else
-+#elif defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64)
-   SIMDExtension_AVX2    = 0x1,
-   SIMDExtension_AVX     = 0x2,
-   SIMDExtension_SSE     = 0x4,
-@@ -53,31 +53,17 @@
-   SIMDExtension_DEFAULT = 0x0
- };
- 
-+#if (defined(__arm__) || defined(__aarch64__)) && defined(__NEON__)
- 
--#if defined(__arm__) || defined(__aarch64__) // incl. armel, armhf, arm64
--
-- #if defined(__NEON__)
--
- static inline uint32_t detectHostSIMDExtensions()
- {
-   return SIMDExtension_NEON;
- }
- 
-- #else //ARM without NEON
-+#elif defined(__PPC64__) && defined(__VSX__)
- 
- static inline uint32_t detectHostSIMDExtensions()
- {
--  return SIMDExtension_DEFAULT;
--}
--
-- #endif
--
--#elif defined(__PPC64__)
--
-- #if defined(__VSX__)
--
--static inline uint32_t detectHostSIMDExtensions()
--{
-   uint32_t hostSimdExts = SIMDExtension_DEFAULT;
-   char *evar;
- 
-@@ -87,16 +73,8 @@
-   return hostSimdExts;
- }
- 
-- #else //PPC64 without VSX
-+#elif defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64)
- 
--static inline uint32_t detectHostSIMDExtensions()
--{
--  return SIMDExtension_DEFAULT;
--}
--
-- #endif
--
--#else   // x86
- static inline void cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
- {
- #if defined(_MSC_VER)
-@@ -158,6 +136,13 @@
-   }
- 
-   return hostSimdExts;
-+}
-+
-+#else
-+
-+static inline uint32_t detectHostSIMDExtensions()
-+{
-+  return SIMDExtension_DEFAULT;
- }
- 
- #endif // end SIMD extension detection code
diff --git a/community/rspamd/rspamd.initd b/community/rspamd/rspamd.initd
index 21fd105e8d..ae0e9733a5 100644
--- a/community/rspamd/rspamd.initd
+++ b/community/rspamd/rspamd.initd
@@ -13,7 +13,7 @@ description_reopen="Reopen log files"
 : ${cfgfile:=${RSPAMD_CONFIG:-/etc/rspamd/rspamd.conf}}
 : ${startuplog:=${RSPAMD_STARTUPLOG:-/dev/null}}
 
-command="/usr/sbin/rspamd"
+command="/usr/bin/rspamd"
 command_args="--config $cfgfile --no-fork ${command_args:-}"
 command_background="yes"
 pidfile="/run/rspamd/$RC_SVCNAME.pid"
diff --git a/community/rspamd/rspamd.post-upgrade b/community/rspamd/rspamd.post-upgrade
deleted file mode 100644
index cf3e277ddf..0000000000
--- a/community/rspamd/rspamd.post-upgrade
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-
-ver_new="$1"
-ver_old="$2"
-
-if [ "$(apk version -t "$ver_old" '1.7.8-r1')" = '<' ]; then
-	if [ "$(stat -c %U:%G /var/log/rspamd)" = 'root:rspamd' ]; then
-		chown rspamd:rspamd /var/log/rspamd
-	fi
-fi
-
-exit 0
-- 
2.24.1