|
| 1 | +%global debug_package %{nil} |
| 2 | +%define _build_id_links none |
| 3 | +Summary: Export IPMI metrics to Prometheus local or remotly |
| 4 | +Name: ipmi_exporter |
| 5 | +%define _name prometheus-ipmi-exporter |
| 6 | +%define _name2 ipmi-exporter |
| 7 | +Version: 1.10.1 |
| 8 | +Release: 1%{?dist} |
| 9 | +License: MIT |
| 10 | +Requires: freeipmi |
| 11 | +BuildRequires: git systemd-rpm-macros |
| 12 | +BuildRequires: golang >= 1.23.0 |
| 13 | +%define _uri github.com/prometheus-community |
| 14 | +%define _archversion db67a63b0fe42c5d7551145b566669f5960e02ed |
| 15 | +%define _archuri https://gitlab.archlinux.org/archlinux/packaging/packages/%{_name}/-/raw/%{_archversion} |
| 16 | +Url: https://%{_uri}/%{name} |
| 17 | +Source0: %{url}/archive/refs/tags/v%{version}.tar.gz |
| 18 | +Source1: %{_archuri}/sudoers.conf |
| 19 | +Source2: %{_archuri}/sysusers.conf |
| 20 | +Source3: %{_archuri}/systemd.service |
| 21 | +Source4: %{_archuri}/config.yml |
| 22 | +Source5: %{_archuri}/config.env |
| 23 | + |
| 24 | +%description |
| 25 | +Prometheus IPMI Exporter |
| 26 | + |
| 27 | +%prep |
| 28 | +%setup -c -q |
| 29 | +export GOPATH="%{_builddir}/gopath" |
| 30 | +export GOBIN="${GOPATH}/bin" |
| 31 | +mkdir -p "${GOPATH}/src/%{_uri}" |
| 32 | +ln -snf "%{_builddir}/%{name}-%{version}/%{name}-%{version}" \ |
| 33 | +"${GOPATH}/src/%{_uri}/%{name}" |
| 34 | + |
| 35 | +%build |
| 36 | +export GOPATH="%{_builddir}/gopath" |
| 37 | +export GOBIN="${GOPATH}/bin" |
| 38 | +cd "${GOPATH}/src/%{_uri}/%{name}" |
| 39 | + |
| 40 | +eval "$(go env | grep -e "GOHOSTOS" -e "GOHOSTARCH")" |
| 41 | +GOOS="${GOHOSTOS}" GOARCH="${GOHOSTARCH}" BUILDTAGS="netgo static_build" \ |
| 42 | + go build -x \ |
| 43 | + -buildmode="pie" \ |
| 44 | + -trimpath \ |
| 45 | + -mod="readonly" \ |
| 46 | + -modcacherw \ |
| 47 | + -ldflags "-linkmode external \ |
| 48 | + -X github.com/prometheus/common/version.Version=%{version} \ |
| 49 | + -X github.com/prometheus/common/version.Revision=%{release} \ |
| 50 | + -X github.com/prometheus/common/version.Branch=tarball \ |
| 51 | + -X github.com/prometheus/common/version.BuildUser=$(whoami)@mockbuild \ |
| 52 | + -X github.com/prometheus/common/version.BuildDate=$(date +%%Y%%m%%d)" |
| 53 | + |
| 54 | +%install |
| 55 | +# remove arch-specific package name |
| 56 | +%{__sed} -i \ |
| 57 | + -e 's|'-/etc/prometheus/"%{_name2}".env'|'-/etc/conf.d/"%{name}"'|g' \ |
| 58 | + -e 's|'/usr/bin/"%{_name}"'|'/usr/bin/"%{name}"'|g' \ |
| 59 | + -e 's|'"%{_name2}".yml'|'"%{name}".yml'|g' \ |
| 60 | + "%SOURCE3" |
| 61 | + |
| 62 | +%{__sed} -i \ |
| 63 | + -e 's|'"%{_bindir}"'|'"%{_sbindir}"'|g' "%SOURCE1" |
| 64 | + |
| 65 | +install -Dm0755 "%{name}-%{version}/%{name}" -t "%{buildroot}%{_bindir}" |
| 66 | +install -Dm0644 "%SOURCE1" "%{buildroot}%{_sysconfdir}/sudoers.d/%{_name}" |
| 67 | +install -Dm0644 "%SOURCE2" "%{buildroot}%{_sysusersdir}/%{name}.conf" |
| 68 | +install -Dm0644 "%SOURCE3" "%{buildroot}%{_unitdir}/%{name}.service" |
| 69 | +install -Dm0644 "%SOURCE4" "%{buildroot}%{_sysconfdir}/prometheus/%{name}.yml" |
| 70 | +install -Dm0644 "%SOURCE5" "%{buildroot}%{_sysconfdir}/conf.d/%{name}" |
| 71 | + |
| 72 | +%pre |
| 73 | +%sysusers_create_package %{name} "%SOURCE2" |
| 74 | + |
| 75 | +%post |
| 76 | +%systemd_post %{name}.service |
| 77 | + |
| 78 | +%preun |
| 79 | +%systemd_preun %{name}.service |
| 80 | + |
| 81 | +%postun |
| 82 | +%systemd_postun_with_restart %{name}.service |
| 83 | + |
| 84 | +%files |
| 85 | +%license %{name}-%{version}/LICENSE |
| 86 | +%attr(0755,root,root) %{_bindir}/%{name} |
| 87 | +%defattr(0644,root,root,0755) |
| 88 | +%config(noreplace) %{_sysconfdir}/prometheus/%{name}.yml |
| 89 | +%config(noreplace) %{_sysconfdir}/conf.d/%{name} |
| 90 | +%{_sysconfdir}/sudoers.d/%{_name} |
| 91 | +%{_sysusersdir}/%{name}.conf |
| 92 | +%{_unitdir}/%{name}.service |
0 commit comments