# Maintainer: nixfloyd <nixfloyd@gmail.com>
pkgname=prometheus-snmp-exporter
_pkgname=snmp_exporter
pkgver=0.26.0
pkgrel=3
pkgdesc="SNMP Exporter for Prometheus"
url="https://github.com/prometheus/snmp_exporter"
# riscv64: prometheus/procfs needs updating
arch="all !riscv64"
license="Apache-2.0"
makedepends="go net-snmp-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-openrc"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/prometheus/snmp_exporter/archive/v$pkgver.tar.gz
	snmp-exporter.initd
	snmp-exporter.confd
	"
builddir="$srcdir/$_pkgname-$pkgver"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go build -o bin/snmp_exporter
	go build -o bin/generator ./generator
}

check() {
	go test
}

package() {
	install -Dm755 bin/snmp_exporter \
		"$pkgdir"/usr/bin/snmp_exporter
	install -Dm755 bin/generator \
		"$pkgdir"/usr/bin/snmp_exporter-generator
	install -Dm644 snmp.yml \
		"$pkgdir"/etc/prometheus/snmp.yml
	install -Dm644 -t "$pkgdir"/usr/share/doc/prometheus-snmp-exporter/ \
		README.md
	install -Dm644 -t "$pkgdir"/usr/share/doc/prometheus-snmp-exporter/examples/ \
		generator/generator.yml
	install -Dm644 -t "$pkgdir"/usr/share/doc/prometheus-snmp-exporter/generator/ \
		generator/README.md
	install -m755 -D "$srcdir"/snmp-exporter.initd \
		"$pkgdir"/etc/init.d/snmp-exporter
	install -m644 -D "$srcdir"/snmp-exporter.confd \
		"$pkgdir"/etc/conf.d/snmp-exporter
}

sha512sums="
e2920483ce2c63e4e35c67bcb5714831088a27954cd7350b2b285517ebd6238f1d2447a4440daff698bb19c452d52e8ebe7165fee423417d55de138facd6abd1  prometheus-snmp-exporter-0.26.0.tar.gz
a11085f14e192ff277107dbbb12857a3043dbce1acadbbdf94a88d2b921745f9556cad3c0a81a0113349d322e02b1705831967af3ecc0f95259e759ade9ff5ad  snmp-exporter.initd
489cb298e215bd9647aa5293d456106eb26a73f5fbd9d42fab68de26d273ebb612dba01ba113ce58521b543a2f82a10ad86dc35056ef8d0438b39e77be61f67e  snmp-exporter.confd
"
