# Generated by go2rpm 1.14.0
%bcond_without check
%define debug_package %nil

# https://github.com/zrepl/zrepl
%global goipath         github.com/zrepl/zrepl
Version:                0.7.0

%gometa -f

%global common_description %{expand:
One-stop ZFS backup & replication solution.}

%global golicenses      LICENSE
%global godocs          README.md

Name:           zrepl
Release:        1%?dist
Summary:        One-stop ZFS backup & replication solution
Packager:       Ben Woods <git@ben.woods.am>

License:        MIT
URL:            https://zrepl.github.io/
Source:         %{gosource}

BuildRequires:    anda-srpm-macros
BuildRequires:    git-core
BuildRequires:    systemd-rpm-macros
Requires(post):   systemd
Requires(preun):  systemd
Requires(postun): systemd

%description %{common_description}

%gopkg

%prep
%goprep
go mod download

%build
go build -ldflags "-B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \n') -s -w" -buildmode=pie -o %{gobuilddir}/bin/zrepl %{goipath}

# Correct the path in the systemd unit file
sed 's:/usr/local/bin/:%{_bindir}/:g' dist/systemd/zrepl.service > %{gobuilddir}/zrepl.service

# Generate the default configuration file
sed 's#USR_SHARE_ZREPL#%{_datadir}/doc/zrepl#' packaging/systemd-default-zrepl.yml > %{gobuilddir}/zrepl.yml

# Generate shell auto-completion files
%{gobuilddir}/bin/zrepl gencompletion bash %{gobuilddir}/bash_completion
%{gobuilddir}/bin/zrepl gencompletion zsh %{gobuilddir}/zsh_completion

%install
%gopkginstall
install -m 0755 -vd                                     %{buildroot}%{_bindir}
install -m 0755 -vp %{gobuilddir}/bin/*                 %{buildroot}%{_bindir}/
install -Dm 0644 %{gobuilddir}/zrepl.service            %{buildroot}%{_unitdir}/zrepl.service
install -Dm 0644 %{gobuilddir}/zrepl.yml                %{buildroot}%{_sysconfdir}/zrepl/zrepl.yml
install -Dm 0644 %{gobuilddir}/bash_completion          %{buildroot}%{_datadir}/bash-completion/completions/zrepl
install -Dm 0644 %{gobuilddir}/zsh_completion           %{buildroot}%{_datadir}/zsh/site-functions/_zrepl
install -d                                              %{buildroot}%{_datadir}/doc/zrepl
cp -a   config/samples                                  %{buildroot}%{_datadir}/doc/zrepl/examples

%post
%systemd_post zrepl.service

%preun
%systemd_preun zrepl.service

%postun
%systemd_postun_with_restart zrepl.service

%files
%license LICENSE
%doc README.md
%{_bindir}/*
%{_unitdir}/zrepl.service
%dir %{_sysconfdir}/zrepl
%config(noreplace) %{_sysconfdir}/zrepl/zrepl.yml
%{_datadir}/bash-completion/completions/zrepl
%{_datadir}/zsh/site-functions/_zrepl
%{_datadir}/doc/zrepl

%gopkgfiles

%changelog
%autochangelog
