# Maintainer: Luke T. Shumaker <lukeshu@parabola.nu>
# Maintainer (AUR): lilydjwg <lilydjwg@gmail.com>
# Contributor (Arch:community): Gaetan Bisson <bisson@archlinux.org>
# Contributor (Arch:community): Gerhard Brauer <gerhard.brauer@web.de>
#
# Rationale: A key part of Parabola infrastructure

# Key timeline as of 2025-10-26:
#
# - 2020-09-03: collectd v5.12.0 released
# - 2020-10-20: [community] updated to v5.12.0
# - 2021-05-08: collectd moved from [community] to AUR
# - 2024-01-23: collectd v6.0.0.rc0 released
# - 2024-02-21: collectd v6.0.0.rc3 released
#
# There has been a steady trickle of commits on both the v5 and v6
# branches in Git, but I do not have any idea what projections are for
# those landing in a release of any kind, or what projections are for
# a v6 stable release.

pkgname=collectd
pkgver=5.12.0
pkgrel=20
pkgdesc='Daemon which collects system performance statistics periodically'
url='https://collectd.org/'
arch=('x86_64' 'i686' 'armv7h')
license=(
	'MIT' # primary license
	# The lists of files here are non-exhaustive; they are merely "existence proofs".
	'Apache-2.0'       # proto/prometheus.proto contrib/SpamAssasin/
	'BSD-2-clause'     # contrib/postgresql/
	'BSD-3-clause'     # src/madwifi.h src/utils/dns/dns.c
	'FSFAP'            # m4/ax_compare_version.m4
	'GPL-2.0-only'     # src/thermal.c
	'GPL-2.0-or-later' # src/cpufreq.c
	'GPL-3.0-or-later' # m4/ax_compiler_vendor.m4
	'ISC'              # src/write_stackdriver.c
	'LGPL-2.1-only'    # src/modbus.c src/barometer.c src/network.c
	'zlib'             # contrib/collectd_unix_sock.rb contrib/collectd_unixsock.py
)

optdepends=('curl: apache, ascent, curl, nginx, and write_http plugins'
            'libdbi: dbi plugin'
            'libesmtp: notify_email plugin'
            'libgcrypt: encryption and authentication for network plugin'
            'libmemcached: memcachec plugin'
            'mariadb-libs: mysql plugin'
            'systemd-libs: UdevNameAttr option'
            'iproute2: netlink plugin'
            'net-snmp: snmp plugin'
            'libnotify: notify_desktop plugin'
            'openipmi: ipmi plugin'
            'liboping: ping plugin'
            'libpcap: dns plugin'
            'perl: perl plugin'
            'postgresql-libs: postgresql plugin'
            'python: python plugin'
            'rrdtool: rrdtool and rrdcached plugins'
            'lm_sensors: lm_sensors and sensors plugins'
            'libvirt: libvirt plugin'
            'libxml2: ascent and libvirt plugins'
            'yajl: curl_json plugin'
            'libatasmart: smart plugin'
            'lvm2: lvm plugin'
            'protobuf-c: write_riemann plugin'
            'mosquitto: MQTT plugin'
            'libmicrohttpd: prometheus plugin'
            'librabbitmq-c: amqp plugin'
            'nut: nut plugin')

makedepends=("${optdepends[@]%%:*}")
depends=('libltdl' 'iptables' 'libnsl')

source=("https://storage.googleapis.com/collectd-tarballs/${pkgname}-${pkgver}.tar.bz2"
        https://github.com/collectd/collectd/commit/c268154ba489580dcce33552263cdea488b6eb4f.patch # 2022-06-03: use correct path for libgcrypt-config (#4008)
        https://github.com/collectd/collectd/commit/d409ffa2a64cac3fc2abe2bb86ec3a80cb34d0a6.patch # 2022-09-08: configure.ac, src/nut.c: detect int types required by NUT API we build against
        https://github.com/collectd/collectd/commit/623e95394e0e62e7f9ced2104b786d21e9c0bf53.patch # 2022-10-25: fix build with Python 3.11
        https://github.com/collectd/collectd/commit/e871771a05c302d5b09d85c21107a69343a508f7.patch # 2025-04-23: configure.ac: use pkg-config to find libgcrypt
        ansidecl.patch
        service.patch)
sha256sums=('5bae043042c19c31f77eb8464e56a01a5454e0b39fa07cf7ad0f1bfc9c3a09d6'
            'c95fa9f62a4e1b0c22ab148869ed5151390fed4804da087150ffed2645974d18'
            'ce30bf4a6cf1565d45656d5cd7e668542bada3f3cf6f4198df4eaf8fdcd97030'
            '777544cbf803af4d08ea228b29619f8f6e7a4777a85e0fb30693d8240db7246b'
            '6dbc67d97b3a5c76bfd3e507bcc71ee25b4ffaca463077d7af94f2d063af3cd4'
            '74088adbd378fd2942ab3b9a959fae110a38b9c411b82557df2b4d1276b61d20'
            'bb38d48a986d7550bf50f3fc3027f4a370a0883f63cbc8c6d5addecd9c5a784b')

backup=('etc/collectd.conf')

prepare() {
	cd ${pkgname}-${pkgver}

	patch -p1 -i ../c268154ba489580dcce33552263cdea488b6eb4f.patch
	patch -p1 -i ../d409ffa2a64cac3fc2abe2bb86ec3a80cb34d0a6.patch
	patch -p1 -i ../623e95394e0e62e7f9ced2104b786d21e9c0bf53.patch
	patch -p1 -i ../e871771a05c302d5b09d85c21107a69343a508f7.patch
	patch -p0 -i ../ansidecl.patch
	patch -p1 -i ../service.patch

	autoreconf
}

build() {
	cd ${pkgname}-${pkgver}
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--sbindir=/usr/bin \
		--disable-werror \
		--with-python=/usr/bin/python \
		--with-perl-bindings='INSTALLDIRS=vendor' \

	make all
}

package() {
	cd ${pkgname}-${pkgver}
	make DESTDIR="${pkgdir}" install
	rmdir "${pkgdir}/var/run" # FS#30201
	install -Dm644 contrib/systemd.collectd.service "${pkgdir}"/usr/lib/systemd/system/collectd.service
	install -Dm644 contrib/collectd2html.pl "${pkgdir}"/usr/share/collectd/collectd2html.pl
}
