# Description: Exporter for machine metrics
# URL: https://github.com/prometheus/node_exporter
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: go
# Optional: python3-bcrypt

name=prometheus-node-exporter
version=1.6.0
release=2
source=(https://github.com/prometheus/node_exporter/archive/v$version/$name-$version.tar.gz
  prometheus-node-exporter.service config.yml
  gen-pass.py)

build() {
  cd node_exporter-$version
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"

  mkdir "$PKGMK_SOURCE_DIR/gopath" || true
  export GOPATH="$PKGMK_SOURCE_DIR/gopath"

  go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -o node_exporter .

  install -Dm755 node_exporter $PKG/usr/bin/node_exporter

  install -Dm755 $SRC/prometheus-node-exporter.service $PKG/etc/rc.d/$name
  prt-get isinst python3-bcrypt && install -Dm644 $SRC/gen-pass.py $PKG/usr/lib/$name/gen-pass.py
  install -Dm644 $SRC/config.yml $PKG/etc/node-exporter/config.yml
}
