%global wwgroup warewulf
%if 0%{?sle_version}
%global tftpdir "/srv/tftpboot"
%global srvdir "/srv"
%else
%global tftpdir "/var/lib/tftpboot"
%global srvdir "%{_localstatedir}/warewulf/srv"
%endif
%define debug_package %{nil}

Name: warewulf
Summary: A provisioning system for large clusters of bare metal and/or virtual systems
Version: @VERSION@
Release: @RELEASE@%{?dist}
License: BSD-3-Clause
URL:     https://github.com/hpcng/warewulf
Source:  https://github.com/hpcng/warewulf/releases/download/v%{version}/warewulf-%{version}.tar.gz

ExclusiveOS: linux

Conflicts: warewulf < 4
Conflicts: warewulf-common
Conflicts: warewulf-cluster
Conflicts: warewulf-vnfs
Conflicts: warewulf-provision
Conflicts: warewulf-ipmi

BuildRequires: make

%if 0%{?rhel}
BuildRequires: systemd
BuildRequires: golang
Requires: tftp-server
Requires: nfs-utils
%else
# sle_version
BuildRequires: systemd-rpm-macros
BuildRequires: go
Requires: tftp
Requires: nfs-kernel-server
%endif

%if 0%{?rhel} >= 8 || 0%{?sle_version}
Requires: dhcp-server
%else
# rhel < 8
Requires: dhcp
%endif

%description
Warewulf is a stateless and diskless container operating system provisioning
system for large clusters of bare metal and/or virtual systems.


%prep
%setup -q -n %{name}-%{version}


%build
make genconfig PREFIX=/usr \
    SRVDIR=%{srvdir} \
    LOCALSTATEDIR=%{_localstatedir} \
    SYSCONFDIR=%{_sysconfdir} \
    DATADIR=%{_datadir} \
    MANDIR=%{_mandir} \
    BINDIR=%{_bindir} \
    TFTPDIR=%{tftpdir} \
    SYSTEMDDIR=%{_unitdir} \
    MANDIR=%{_mandir} \
    BASH_COMPLETION=/etc/bash_completion.d/ \
    FIREWALLDDIR=/usr/lib/firewalld/services

make

%install
make install DESTDIR=%{buildroot}

%pre
getent group %{wwgroup} >/dev/null || groupadd -r %{wwgroup}


%post
%systemd_post warewulfd.service


%preun
%systemd_preun warewulfd.service


%postun
%systemd_postun_with_restart warewulfd.service


%files
%defattr(-, root, %{wwgroup})
%dir %{_sysconfdir}/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/*
%config(noreplace) %attr(0640,-,-) %{_sysconfdir}/%{name}/nodes.conf
%{_sysconfdir}/bash_completion.d/warewulf

%dir %{_localstatedir}/warewulf
%{_localstatedir}/warewulf/chroots
%{_localstatedir}/warewulf/overlays
%{srvdir}

%attr(-, root, root) %{_bindir}/wwctl
%attr(-, root, root) %{_prefix}/lib/firewalld/services/warewulf.xml
%attr(-, root, root) %{_unitdir}/warewulfd.service
%attr(-, root, root) %{_mandir}/man1/wwctl*

%changelog
* Sat Jan 15 2022 Gregory Kurtzer <gmkurtzer@gmail.com> - 4.2.0-1
- Integrated genconfig Make options
- Cleaned up SPEC to use default RPM macros

* Tue Jan 11 2022 Jeremy Siadal <jeremy.c.siadal@intel.com> - 4.2.0-1
- Merge overlay subdirectories
- Add configuration options to make
- Relocate tftpboot for OpenSUSE
- Remove libexecdir macro; changing in OpenSUSE 15.4

* Mon Nov 1 2021 Jeremy Siadal <jeremy.c.siadal@intel.com> - 4.2.0-1
- Add support for OpenSUSE
- Update file attribs
- Update license string
- Make shared store relocatable

* Fri Sep 24 2021 Michael L. Young <myoung@ciq.co> - 4.2.0-1
- Update spec file to use systemd macros
- Use macros to refer to system paths
- Update syntax

* Tue Jan 26 2021 14:46:24 JST Brian Clemens <bclemens@ctrliq.com> - 4.0.0
- Initial release
