%global debug_package %{nil} Name: smartctl_exporter Version: 0.14.0 Release: %autorelease Summary: Export smartctl statistics to prometheus License: Apache-2.0 URL: https://github.com/prometheus-community/smartctl_exporter Source0: %{url}/archive/refs/tags/v%{version}.tar.gz BuildRequires: curl BuildRequires: git BuildRequires: golang BuildRequires: systemd-rpm-macros %{?systemd_requires} Requires: smartmontools >= 7.0 %description %{summary}. %prep %autosetup -n %{name}-%{version} __SYSTEM_GO_VERSION="$(go version | sed -E 's/^go version go([0-9]+(\.[0-9]+){1,2}).*/\1/')" __REQUIRED_GO_VERSION="$(awk '$1 == "go" { print $2; exit }' go.mod)" __REQUIRED_GO_VERSION="$(printf '%s\n' "$__REQUIRED_GO_VERSION" | awk -F. ' NF == 2 { print $0 ".0" } NF == 3 { print $0 } ')" if [ -z "$__SYSTEM_GO_VERSION" ] || [ -z "$__REQUIRED_GO_VERSION" ]; then echo "Unable to determine the Go versions" exit 1 fi if [ "$(printf '%s\n%s\n' "$__SYSTEM_GO_VERSION" "$__REQUIRED_GO_VERSION" | sort -V | tail -n1)" = "$__SYSTEM_GO_VERSION" ]; then echo "Skipping Go download. Required ${__REQUIRED_GO_VERSION}, Installed: ${__SYSTEM_GO_VERSION}" else if [ "%{_arch}" = "x86_64" ]; then __TOOLCHAIN_ARCH=amd64 elif [ "%{_arch}" = "aarch64" ]; then __TOOLCHAIN_ARCH=arm64 else echo "Unsupported arch: %{_arch}" exit 1 fi echo "Downloading Go ${__REQUIRED_GO_VERSION} for ${__TOOLCHAIN_ARCH} ..." curl --location --silent "https://go.dev/dl/go${__REQUIRED_GO_VERSION}.linux-${__TOOLCHAIN_ARCH}.tar.gz" \ | tar --extract --gzip --file=- fi %build if [ -x go/bin/go ]; then export PATH="$(pwd)/go/bin:${PATH}" fi go version go build -buildmode=pie -mod=mod -trimpath \ -ldflags "-X github.com/prometheus/common/version.Version=%{version} \ -X github.com/prometheus/common/version.Revision=v%{version}-%{release} \ -X github.com/prometheus/common/version.Branch=%{version}" \ -o %{name} %install install -D --mode=0755 %{name} %{buildroot}%{_bindir}/%{name} install -D --mode=0644 systemd/%{name}.service %{buildroot}%{_unitdir}/%{name}.service %files %license LICENSE %doc README.md CHANGELOG.md %{_bindir}/%{name} %{_unitdir}/%{name}.service %post %systemd_post %{name}.service %preun %systemd_preun %{name}.service %postun %systemd_postun_with_restart %{name}.service %changelog %autochangelog