%bcond_with systemd

%global _hardened_build 1
%global _sbindir /sbin

Summary:        Random number generator related utilities
Summary(ja):    乱数生成器関連のユーティリティ
Name:           rng-tools
Version:        6.14
Release:        1%{?_dist_release}%{?with_systemd:.systemd}
Group:          system
Vendor:         Project Vine
Distribution:   Vine Linux

License:        GPLv2+
URL:            https://github.com/nhorman/rng-tools
Source0:        https://github.com/nhorman/rng-tools/archive/refs/tags/v%{version}.tar.gz#/rng-tools-%{version}.tar.gz

Source1:        rngd.service
Source100:      rngd.init
Source101:      rngd.sysconfig
Source1000:     Changelog.fedora

# https://sourceforge.net/p/gkernel/patches/111/

BuildRequires: gcc make
BuildRequires: gettext
BuildRequires: libgcrypt-devel
BuildRequires: autoconf automake
BuildRequires: libsysfs-devel curl-devel
BuildRequires: libxml2-devel openssl-devel
BuildRequires: jansson-devel
BuildRequires: jitterentropy-devel
#BuildRequires: libp11-devel
#BuildRequires: rtl-sdr-devel
Provides: jitterentropy-rngd

%if %{with systemd}
BuildRequires:  systemd-units
Requires(post): systemd-units
Requires(preun): systemd-units
Requires(postun): systemd-units
%else
Requires(post): chkconfig
Requires(preun): chkconfig
Requires(postun): chkconfig
%endif

%description
Hardware random number generation tools.


%debug_package


%prep 
%autosetup 


%build
./autogen.sh
%configure \
	--without-pkcs11 \
	--without-rtlsdr \
	%{nil}

%make_build


%install
%make_install

%if %{with systemd}
# install systemd unit file
install -Dt %{buildroot}%{_unitdir} -m0644 %{SOURCE1}
%else
mkdir -p %{buildroot}%{_initdir}
mkdir -p %{buildroot}%{_sysconfdir}/sysconfig
install -m755 %{SOURCE100} %{buildroot}%{_initdir}/rngd
install -m644 %{SOURCE101} %{buildroot}%{_sysconfdir}/sysconfig/rngd
%endif


%post
%if %{with systemd}
%systemd_post rngd.service
%else
/sbin/chkconfig --add rngd
%endif

%preun
%if %{with systemd}
%systemd_preun rngd.service
%else
if [ "$1" = 0 -o -x /bin/systemctl ]; then
  /sbin/service stop rngd >/dev/null 2>&1 ||:
  /sbin/chkconfig --del rngd
fi
%endif

%postun
%if %{with systemd}
%systemd_postun_with_restart rngd.service
%else
if [ "$1" != 0 ]; then
  /sbin/service stop condrestart >/dev/null 2>&1 ||:
fi
%endif


%files
%{!?_licensedir:%global license %%doc}
%license COPYING
%doc AUTHORS NEWS README
%{_bindir}/randstat
%{_bindir}/rngtest
%{_sbindir}/rngd
%{_mandir}/man1/rngtest.1.*
%{_mandir}/man8/rngd.8.*
%if %{with systemd}
%attr(0644,root,root)   %{_unitdir}/rngd.service
%else
%attr(0755,root,root)   %{_initdir}/rngd
%attr(0644,root,root)   %config(noreplace) %{_sysconfdir}/sysconfig/rngd
%endif


%changelog
* Sat Oct 16 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 6.14-1
- new upstream release.
- built with openssl-3.0.0.

* Mon Mar 08 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 6.11-1
- new upstream release.

* Sun Aug 09 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 6.10-5
* added suffix to %%release with systemd build.

* Thu Apr 02 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 6.10-4
- initial build for Vine Linux.
