# Generated by go2rpm 1.8.2
%bcond_without check
%global debug_package %{nil}
%global shortname prometheus-snmp-exporter

# https://github.com/prometheus/snmp_exporter
%global goipath         github.com/prometheus/snmp_exporter
Version:                0.26.0

%gometa -f

%global common_description SNMP Exporter for Prometheus.

%global golicenses      LICENSE NOTICE
%global godocs          CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md\\\
                        MAINTAINERS.md README.md SECURITY.md\\\
                        generator/FORMAT.generator.md\\\
                        generator/README.generator.md

Name:           %{goname}
Release:        %autorelease
Summary:        SNMP Exporter for Prometheus

License:        Apache-2.0
URL:            %{gourl}
Source0:        %{gosource}
Source1:        %{shortname}.conf
Source2:        %{shortname}.service
Source3:        %{shortname}.sysusers

Patch0:         prometheus-snmp-exporter-generator-paths.patch

BuildRequires:  net-snmp-devel
BuildRequires:  systemd-rpm-macros

Requires:  net-snmp-libs

Requires(pre): shadow-utils

%description
%{common_description}

%gopkg

%prep
%goprep
%autopatch -p1
mv generator/FORMAT.md generator/FORMAT.generator.md
mv generator/README.md generator/README.generator.md

%generate_buildrequires
%go_generate_buildrequires

%build
%gobuild -o %{gobuilddir}/bin/snmp_exporter %{goipath}
for cmd in generator; do
  %gobuild -o %{gobuilddir}/bin/$(basename $cmd) %{goipath}/$cmd
done

%install
%gopkginstall
install -m 0755 -vd                     %{buildroot}%{_bindir}
install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/
mv %{buildroot}%{_bindir}/snmp_exporter %{buildroot}%{_bindir}/%{shortname}
mv %{buildroot}%{_bindir}/generator     %{buildroot}%{_bindir}/prometheus-snmp-generator

install -Dpm 0644 snmp.yml %{buildroot}%{_sysconfdir}/prometheus/snmp.yml
install -Dpm 0644 generator/generator.yml %{buildroot}%{_sysconfdir}/prometheus/snmp-generator.yml
install -Dpm 0644 %{S:1} %{buildroot}%{_sysconfdir}/default/%{shortname}
install -Dpm 0644 %{S:2} %{buildroot}%{_unitdir}/%{shortname}.service
install -Dpm 0644 %{S:3} %{buildroot}%{_sysusersdir}/%{shortname}.conf


%if %{with check}
%check
%gocheck -d collector
%endif

%pre
%sysusers_create_compat %{S:3}

%post
%systemd_post %{shortname}.service

%preun
%systemd_preun %{shortname}.service

%postun
%systemd_postun_with_restart %{shortname}.service

%files
%config(noreplace) %{_sysconfdir}/default/%{shortname}
%config(noreplace) %{_sysconfdir}/prometheus/snmp.yml
%config(noreplace) %{_sysconfdir}/prometheus/snmp-generator.yml
%doc CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md MAINTAINERS.md README.md
%doc SECURITY.md generator/FORMAT.generator.md generator/README.generator.md
%license LICENSE NOTICE
%{_bindir}/%{shortname}
%{_bindir}/prometheus-snmp-generator
%{_sysusersdir}/%{shortname}.conf
%{_unitdir}/%{shortname}.service

%gopkgfiles

%changelog
%autochangelog