# Contributor: Nathan Johnson <nathan@nathanjohnson.info>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=rabbitmq-server
pkgver=3.13.7
pkgrel=0
pkgdesc="open source multi-protocol messaging broker"
url="https://www.rabbitmq.com/"
arch="noarch"
license="MPL-2.0"
depends="erlang"
makedepends="
	elixir
	erlang-dev
	gawk
	grep
	libxslt
	py3-simplejson
	python3
	rsync
	socat
	xmlto
	zip
	"
install="$pkgname.pre-install $pkgname.post-deinstall"
pkgusers="rabbitmq"
pkggroups="rabbitmq"
subpackages="$pkgname-doc $pkgname-openrc"
source="https://github.com/rabbitmq/rabbitmq-server/releases/download/v$pkgver/rabbitmq-server-$pkgver.tar.xz
	rabbitmq-server.initd
	rabbitmq-server.logrotate
	"
options="!check" # test suite broken

# secfixes:
#   3.9.1-r0:
#     - CVE-2021-32719
#   3.7.17-r0:
#     - CVE-2015-9251
#     - CVE-2017-16012
#     - CVE-2019-11358

prepare() {
	default_prepare
	sed -e 's|@RABBITMQ_USER@|rabbitmq|g' \
		-e 's|@RABBITMQ_GROUP@|rabbitmq|g' \
		-e 's|@STDOUT_STDERR_REDIRECTION@||' \
		-i scripts/rabbitmq-script-wrapper
}

build() {
	make dist manpages PYTHON=python3
}

package() {
	make install install-bin install-man \
		DESTDIR="$pkgdir" \
		PREFIX=/usr \
		RMQ_ROOTDIR="/usr/lib/rabbitmq" \
		MANDIR=/usr/share/man \
		PYTHON=python3

	install -dm755 -o rabbitmq -g rabbitmq "$pkgdir"/var/lib/rabbitmq
	install -dm750 -o rabbitmq -g rabbitmq "$pkgdir"/var/lib/rabbitmq/mnesia
	install -dm755 -o rabbitmq -g rabbitmq "$pkgdir"/var/log/rabbitmq

	# Copy all necessary lib files etc.
	install -Dvpm755 scripts/rabbitmq-server.ocf \
		"$pkgdir"/usr/lib/ocf/resource.d/rabbitmq/rabbitmq-server
	install -Dvpm644 "$srcdir"/rabbitmq-server.logrotate \
		"$pkgdir"/etc/logrotate.d/rabbitmq-server
	install -Dvm755 "$srcdir"/rabbitmq-server.initd \
		"$pkgdir"/etc/init.d/rabbitmq-server

	install -Dvm755 scripts/rabbitmq-script-wrapper \
		"$pkgdir"/usr/sbin/rabbitmqctl
	local script; for script in rabbitmq-server rabbitmq-plugins; do
		ln -s rabbitmqctl "$pkgdir"/usr/sbin/$script
	done

	install -Dvm644 LICENSE* -t "$pkgdir"/usr/share/licenses/$pkgname/
	install -Dvm644 -t "$pkgdir"/usr/share/doc/$pkgname/examples/ \
		deps/rabbit/docs/advanced.config.example \
		deps/rabbit/docs/rabbitmq.conf.example \
		deps/rabbit/docs/set_rabbitmq_policy.sh.example
}

sha512sums="
4403ae7432310781a3144a22a3892f6a4df67f85c8f1f346d43b2147c7a48d11cedb9055a930cbf3a0dc984458384da843333f4a524309302e64afd320ab7ec9  rabbitmq-server-3.13.7.tar.xz
52413e264ae13a607262f17068ea9b9e65cc23e348d4baf45635473893758ee4571fe1b47989b1c0e69d82ec653e013955719465d37474d3e3e29c21808403f5  rabbitmq-server.initd
b8655cb048ab3b32001d4e6920bb5366696f3a5da75c053605e9b270e771c548e36858dca8338813d34376534515bba00af5e6dd7b4b1754a0e64a8fb756e3f3  rabbitmq-server.logrotate
"
