## START: Set by rpmautospec
## (rpmautospec version 0.3.5)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 1;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

# Generated by go2rpm 1.10.0
%bcond_without check
%global shortname prometheus-node-exporter

# https://github.com/prometheus/node_exporter
%global goipath         github.com/prometheus/node_exporter
Version:                1.6.1

%gometa -f


%global common_description %{expand:
Prometheus exporter for hardware and OS metrics exposed by *NIX kernels, written
in Go with pluggable metric collectors.}

%global golicenses      LICENSE NOTICE
%global godocs          docs examples CHANGELOG.md CODE_OF_CONDUCT.md\\\
                        CONTRIBUTING.md MAINTAINERS.md SECURITY.md README.md

Name:           %{goname}
Release:        %autorelease
Summary:        Exporter for machine metrics

License:        Apache-2.0
URL:            %{gourl}
Source:         %{gosource}
Source:         %{shortname}.sysusers
Source:         %{shortname}.service
Source:         %{shortname}.conf
Source:         %{shortname}.logrotate
# Replace defaults paths for config files
Patch:         defaults-paths.patch

BuildRequires:  systemd-rpm-macros
Requires(pre): shadow-utils

%description %{common_description}

%gopkg

%prep
%goprep
%autopatch -p1

# Don't build runit collector
rm -rf collector/runit.go

%generate_buildrequires
%go_generate_buildrequires

%build
export BUILDTAGS="netgo osusergo static_build"
export LDFLAGS="-X github.com/prometheus/common/version.Version=%{version}  \
         -X github.com/prometheus/common/version.Revision=%{release} \
         -X github.com/prometheus/common/version.Branch=tarball      \
         -X github.com/prometheus/common/version.BuildDate=$(date -u -d@$SOURCE_DATE_EPOCH +%%Y%%m%%d)"
%gobuild -o %{gobuilddir}/bin/node_exporter %{goipath}

%install
%gopkginstall
install -m 0755 -vd                     %{buildroot}%{_bindir}
install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/
mv %{buildroot}%{_bindir}/node_exporter %{buildroot}%{_bindir}/%{shortname}
pushd %{buildroot}%{_bindir}
ln -s %{shortname} node_exporter
popd

install -Dpm0644 %{S:1} %{buildroot}%{_sysusersdir}/%{shortname}.conf
install -Dpm0644 %{S:2} %{buildroot}%{_unitdir}/%{shortname}.service
pushd %{buildroot}%{_unitdir}
ln -s %{shortname}.service node_exporter.service
popd
install -Dpm0644 %{S:3} %{buildroot}%{_sysconfdir}/default/%{shortname}
install -Dpm0644 example-rules.yml %{buildroot}%{_datadir}/prometheus/node-exporter/example-rules.yml
install -Dpm0644 %{S:4} %{buildroot}%{_sysconfdir}/logrotate.d/%{shortname}
mkdir -vp %{buildroot}%{_sharedstatedir}/prometheus/node-exporter

# Build man pages.
mkdir -vp %{buildroot}/%{_mandir}/man1/
%{buildroot}%{_bindir}/%{shortname} --help-man > \
    %{buildroot}/%{_mandir}/man1/%{shortname}.1
sed -i '/^  /d; /^.SH "NAME"/,+1c.SH "NAME"\nprometheus-node-exporter \\- The Prometheus Node-Exporter' \
    %{buildroot}/%{_mandir}/man1/%{shortname}.1

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

%pre
%sysusers_create_compat %{SOURCE1}

%post
%systemd_post %{shortname}.service

%preun
%systemd_preun %{shortname}.service

%postun
%systemd_postun_with_restart %{shortname}.service

%files
%license LICENSE NOTICE
%doc docs examples CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md
%doc MAINTAINERS.md SECURITY.md README.md
%{_bindir}/*
%config(noreplace) %{_sysconfdir}/default/%{shortname}
%config(noreplace) %{_sysconfdir}/logrotate.d/%{shortname}
%{_sysusersdir}/%{shortname}.conf
%{_unitdir}/%{shortname}.service
%{_unitdir}/node_exporter.service
%{_mandir}/man1/%{shortname}.1*
%{_datadir}/prometheus/node-exporter/example-rules.yml
%dir %attr(0755,prometheus,prometheus) %{_sharedstatedir}/prometheus
%dir %attr(0755,prometheus,prometheus) %{_sharedstatedir}/prometheus/node-exporter

%gopkgfiles

%changelog
* Thu Nov 09 2023 Mikel Olasagasti Uranga <mikel@olasagasti.info> - 1.6.1-1
- Update to 1.6.1 - Closes rhbz#2210487 rhbz#2178447 rhbz#2163209

* Thu Jul 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 1.5.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Wed May 17 2023 Mark E. Fuller <mark.e.fuller@gmx.de> - 1.5.0-1
- bump to v1.5.0, close rhbz#2112130

* Thu Jan 19 2023 Fedora Release Engineering <releng@fedoraproject.org> - 1.3.1-13
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Wed Aug 10 2022 Maxwell G <gotmax@e.email> - 1.3.1-12
- Rebuild to fix FTBFS

* Thu Jul 21 2022 Fedora Release Engineering <releng@fedoraproject.org> - 1.3.1-11
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Tue Jul 19 2022 Maxwell G <gotmax@e.email> - 1.3.1-10
- Rebuild for
  CVE-2022-{1705,32148,30631,30633,28131,30635,30632,30630,1962} in golang

* Thu Jun 23 2022 Maxwell G <gotmax@e.email> - 1.3.1-9
- Rebuild to mitigate CVE-2022-21698 (rhbz#2067400).

* Sat Jun 18 2022 Robert-André Mauchin <zebob.m@gmail.com> - 1.3.1-8
- Rebuilt for CVE-2022-1996, CVE-2022-24675, CVE-2022-28327,
  CVE-2022-27191, CVE-2022-29526, CVE-2022-30629

* Sat Apr 16 2022 Fabio Alessandro Locati <me@fale.io> - 1.3.1-7
- Rebuilt for CVE-2022-27191

* Fri Jan 28 2022 Robert-André Mauchin <zebob.m@gmail.com> - 1.3.1-6
- Symlink for older service name

* Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> - 1.3.1-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Sun Jan 16 2022 Robert-André Mauchin <zebob.m@gmail.com> - 1.3.1-4
- Add logrotate file

* Sat Jan 15 2022 Robert-André Mauchin <zebob.m@gmail.com> - 1.3.1-3
- Add LDFLAGS

* Fri Jan 14 2022 Robert-André Mauchin <zebob.m@gmail.com> - 1.3.1-2
- Fix home directory permissions

* Fri Jan 14 2022 Robert-André Mauchin <zebob.m@gmail.com> - 1.3.1-1
- Update to 1.3.1 Close: rhbz#2024811 Close: rhbz#2039257

* Thu Aug 12 2021 Robert-André Mauchin <zebob.m@gmail.com> - 1.2.2-1
- Update to 1.2.2 Close: rhbz#1945422

* Thu Jul 22 2021 Fedora Release Engineering <releng@fedoraproject.org> - 1.1.1-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

* Sun Mar 28 18:14:35 CEST 2021 Robert-André Mauchin <zebob.m@gmail.com> - 1.1.1-2
- Fix binary location

* Wed Feb 17 22:48:22 CET 2021 Robert-André Mauchin <zebob.m@gmail.com> - 1.1.1-1
- Initial package