%bcond_without check
%if 0%{?rhel} <= 7 && ! 0%{?fedora} && ! 0%{?centos}
%define gobuild(o:) scl enable go-toolset-1.19 -- go build -mod vendor -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${GO_LDFLAGS:-} ${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld'" -a -v %{?**};
%endif
%if 0%{?rhel} <= 7 && ! 0%{?fedora} && 0%{?centos}
%define gobuild(o:) go build -mod vendor -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${GO_LDFLAGS:-} ${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld'" -a -v %{?**};
%endif
%global goipath github.com/RedHatInsights/host-metering
%global forgeurl https://github.com/RedHatInsights/host-metering/
%global autorelease 4
%global gomodulesmode GO111MODULE=on
%global godocs README.md
%global go_arches x86_64 s390x ppc64le
# macros needed by SELinux
%global selinuxtype targeted
%global moduletype contrib
%global modulename host-metering
Name: host-metering
Version: 1.2.0
Release: %{autorelease}%{?dist}
Summary: None
License: Apache-2.0
URL: https://github.com/RedHatInsights/host-metering/
ExclusiveArch: %{go_arches}
Source: https://github.com/RedHatInsights/host-metering/releases/download/v%{version}/host-metering-%{version}.tar.gz
# RHEL specific patches
Patch0001: 0001-use-production-write-url.patch
Patch0002: 0002-feat-enable-host-metering.service-on-rpm-installatio.patch
%if 0%{?rhel} <= 7 && ! 0%{?fedora} && ! 0%{?centos}
BuildRequires: go-toolset-1.19
%else
BuildRequires: golang >= 1.19
BuildRequires: systemd-rpm-macros
%endif
BuildRequires: git
BuildRequires: policycoreutils
BuildRequires: selinux-policy
BuildRequires: selinux-policy-devel
Requires: %{name}-selinux = %{version}-%{release}
%description
Host metering service
%package selinux
Summary: SELinux policy module for host-metering
BuildArch: noarch
%{?selinux_requires}
Requires: %{name} = %{version}-%{release}
%description selinux
This package installs and sets up the SELinux policy security module for host-metering.
%prep
%setup -q -b 0
# for possible downstream patches
%autopatch -p1
%build
pwd
%gobuild -o $(pwd)/bin/host-metering %{goipath}
make build-selinux
%pre selinux
%selinux_relabel_pre -s %{selinuxtype}
%install
install -m 0755 -vd %{buildroot}%{_bindir}
install -m 0755 -vp $(pwd)/bin/* %{buildroot}%{_bindir}/
install -m 0755 -vd %{buildroot}%{_unitdir}
install -m 644 contrib/systemd/host-metering.service %{buildroot}%{_unitdir}/%{name}.service
install -m 0755 -vd %{buildroot}%{_presetdir}
install -m 644 contrib/systemd/80-host-metering.preset %{buildroot}%{_presetdir}/80-%{name}.preset
install -m 0755 -vd %{buildroot}%{_mandir}/man1
install -m 644 contrib/man/host-metering.1 %{buildroot}%{_mandir}/man1/host-metering.1
install -m 0755 -vd %{buildroot}%{_mandir}/man5
install -m 644 contrib/man/host-metering.conf.5 %{buildroot}%{_mandir}/man5/host-metering.conf.5
install -D -m 0644 contrib/selinux/%{modulename}.pp %{buildroot}%{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp
install -D -p -m 644 contrib/selinux/%{modulename}.if %{buildroot}%{_datadir}/selinux/devel/include/distributed/%{modulename}.if
%if %{with check}
%check
%endif
%post
%systemd_post %{name}.service
%post selinux
%selinux_modules_install -s %{selinuxtype} %{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp
%selinux_relabel_post -s %{selinuxtype}
if [ "$1" -le "1" ]; then # First install
# the daemon needs to be restarted for the custom label to be applied
%systemd_postun_with_restart %{modulename}.service
fi
%preun
%systemd_preun %{name}.service
%postun
%systemd_postun_with_restart %{name}.service
%postun selinux
if [ $1 -eq 0 ]; then
%selinux_modules_uninstall -s %{selinuxtype} %{modulename}
%selinux_relabel_post -s %{selinuxtype}
fi
%files
%doc README.md
%{_bindir}/*
%attr(644,root,root) %{_unitdir}/%{name}.service
%{_mandir}/man1/host-metering.1*
%{_mandir}/man5/host-metering.conf.5*
%{_presetdir}/*.preset
%files selinux
%{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp
%{_datadir}/selinux/devel/include/distributed/%{modulename}.if
%ghost %{_sharedstatedir}/selinux/%{selinuxtype}/active/modules/200/%{modulename}
%changelog
* Fri Jan 12 2024 Vobornik Petr <pvoborni@redhat.com> - 1.2.0-4
- Removal of automatic start if host-metering.service on rpm installation
* Tue Jan 9 2024 Vobornik Petr <pvoborni@redhat.com> - 1.2.0-3
- Resolves: RHEL-12368 [RFE] Add host-metering package to RHEL 7
- Enable and start host-metering.service on rpm installation
* Fri Jan 5 2024 Vobornik Petr <pvoborni@redhat.com> - 1.2.0-2
- Resolves: RHEL-12368 [RFE] Add host-metering package to RHEL 7
- Fixed default writeUrl
* Tue Dec 19 2023 Vobornik Petr <pvoborni@redhat.com> - 1.2.0-1
- Resolves: RHEL-12368 [RFE] Add host-metering package to RHEL 7
- Rebasing to upstream release v1.2.0
* Wed Dec 13 2023 Vobornik Petr <pvoborni@redhat.com> - 1.1.0-1
- Resolves: RHEL-12368 [RFE] Add host-metering package to RHEL 7
- Rebasing to upstream release v1.1.0
* Fri Dec 8 2023 Vobornik Petr <pvoborni@redhat.com> - 1.0.0-2
- Resolves: RHEL-12368 [RFE] Add host-metering package to RHEL 7
- Change custom log file permission to 0600
* Tue Nov 7 2023 Vobornik Petr <pvoborni@redhat.com> - 1.0.0-1
- Resolves: RHEL-12368 [RFE] Add host-metering package to RHEL 7