%global  debug_package    %{nil}
%global  _hardened_build  1

Summary:          TNFSD server
Name:             tnfsd
Version:          24.0522.1
Release:          1%{?dist}
License:          MIT
URL:              https://github.com/FujiNetWIFI/tnfsd
Source0:          https://github.com/FujiNetWIFI/tnfsd/archive/refs/tags/v{%version}.tar.gz#/%{name}-%{version}.tar.gz
Source1:          %{name}.service
Source2:          %{name}.xml
Source3:          %{name}.logrotate

Requires(pre):    shadow-utils
Requires:         (tnfsd-firewalld = %{?epoch}:%{version}-%{release} if firewalld)

%{?systemd_requires}
BuildRequires:    systemd
BuildRequires:    gcc
BuildRequires:    firewalld-filesystem

%description
This is a version of the Spectranet TNFSD server that has been extended
for use with #FujiNet devices.

%package firewalld
Summary: FirewallD metadata file for TNFSD
Requires: firewalld-filesystem
Requires(post): firewalld-filesystem

%description firewalld
This package contains FirewallD file for TNFSD.


%prep
%autosetup -n tnfsd-%{version}

%build
cd src
%make_build OS=LINUX USAGELOG=yes DEBUG=yes

%install
install -d $RPM_BUILD_ROOT/%{_var}/lib/tnfs
install -D -m 0755 bin/%{name} $RPM_BUILD_ROOT/%{_bindir}/%{name}
install -D -m 644 %{SOURCE1} $RPM_BUILD_ROOT/%{_unitdir}/%{name}.service
install -D -m 0644 %{SOURCE2} $RPM_BUILD_ROOT/%{_prefix}/lib/firewalld/services/%{name}.xml
install -D -m 0644 %{SOURCE3} $RPM_BUILD_ROOT/%{_sysconfdir}/logrotate.d/%{name}

%pre
getent group tnfs >/dev/null || groupadd -r tnfs
getent passwd tnfs >/dev/null || \
    useradd -r -g tnfs -d %{_var}/lib/tnfs -s /usr/sbin/nologin -c "TNFS Server" tnfs
exit 0

%post
%systemd_post %{name}.service

%preun
%systemd_preun %{name}.service

%postun
%systemd_postun_with_restart %{name}.service

%files
%license LICENSE.md
%doc README.md tnfs-protocol.md
%{_sysconfdir}/logrotate.d/%{name}
%{_bindir}/%{name}
%{_unitdir}/%{name}.service
%dir %attr(0755,tnfs,tnfs) %{_var}/lib/tnfs

%files firewalld
%{_prefix}/lib/firewalld/services/%{name}.xml

%changelog
* Thu May 23 2024 Greg Wildman <greg@techno.co.za> - 24.0522.1-1
- Update to latest release.

* Tue May 09 2023 Greg Wildman <greg@techno.co.za> - 0.1git95c5b55-5
- Update to latest commit.

* Wed Nov 23 2022 Greg Wildman <greg@techno.co.za> - 0.1git6488bba-4
- Enable DEBUG again

* Thu Nov 17 2022 Greg Wildman <greg@techno.co.za> - 0.1git6488bba-3
- Remove DEBUG and create systemd service log file

* Sun Oct 16 2022 Greg Wildman <greg@techno.co.za> - 0.1git6488bba-1
- Initial spec.