File i2pd.spec of Package i2pd

Name:           i2pd
Version:        2.39.0
Release:        1%{?dist}
Summary:        I2P router written in C++

License:        BSD
URL:            https://github.com/PurpleI2P/i2pd
Source0:        https://github.com/PurpleI2P/i2pd/archive/%{version}/%name-%version.tar.gz
Source1:        i2pd.service

%if 0%{?rhel} == 7
BuildRequires:  cmake3
%else
BuildRequires:  cmake
%endif

BuildRequires:  chrpath
BuildRequires:  gcc-c++
BuildRequires:  zlib-devel
BuildRequires:  boost-devel
BuildRequires:  openssl-devel
BuildRequires:  miniupnpc-devel
BuildRequires:  systemd-units


%description
C++ implementation of I2P.


%package systemd
Summary:        Files to run I2P router under systemd
BuildArch:      noarch
Requires:	i2pd
Requires:	logrotate
Requires:	systemd
Requires(pre):  %{_sbindir}/useradd %{_sbindir}/groupadd
Obsoletes:      %{name}-daemon


%description systemd
C++ implementation of I2P.

This package contains systemd unit file to run i2pd as a system service
using dedicated user's permissions.


%prep
%setup -q


%build
cd build
%cmake3 \
    -DWITH_LIBRARY=OFF \
    -DWITH_UPNP=ON \
    -DWITH_HARDENING=ON \
    -DBUILD_SHARED_LIBS:BOOL=OFF

%{?cmake3_build}%{?!cmake3_build:%{make_build}}


%install
cd build
%{?__cmake_builddir:cd %{__cmake_builddir}}
chrpath -d i2pd
%{__install} -D -m 755 i2pd %{buildroot}%{_sbindir}/i2pd
%{__install} -d -m 755 %{buildroot}%{_datadir}/i2pd
%{__install} -d -m 755 %{buildroot}%{_datadir}/i2pd/tunnels.conf.d
%{__install} -d -m 700 %{buildroot}%{_sharedstatedir}/i2pd
%{__install} -d -m 700 %{buildroot}%{_localstatedir}/log/i2pd
%{__install} -D -m 644 %{_builddir}/%{name}-%{version}/contrib/i2pd.conf %{buildroot}%{_sysconfdir}/i2pd/i2pd.conf
%{__install} -D -m 644 %{_builddir}/%{name}-%{version}/contrib/subscriptions.txt %{buildroot}%{_sysconfdir}/i2pd/subscriptions.txt
%{__install} -D -m 644 %{_builddir}/%{name}-%{version}/contrib/tunnels.conf %{buildroot}%{_sysconfdir}/i2pd/tunnels.conf
%{__install} -D -m 644 %{_builddir}/%{name}-%{version}/contrib/i2pd.logrotate %{buildroot}%{_sysconfdir}/logrotate.d/i2pd
%{__install} -D -m 644 %{SOURCE1} %{buildroot}%{_unitdir}/i2pd.service
%{__install} -D -m 644 %{_builddir}/%{name}-%{version}/debian/i2pd.1 %{buildroot}%{_mandir}/man1/i2pd.1
%{__cp} -r %{_builddir}/%{name}-%{version}/contrib/certificates/ %{buildroot}%{_datadir}/i2pd/certificates
%{__cp} -r %{_builddir}/%{name}-%{version}/contrib/tunnels.d/ %{buildroot}%{_sysconfdir}/i2pd/tunnels.conf.d
%{__ln_s} %{_datadir}/%{name}/certificates %{buildroot}%{_sharedstatedir}/i2pd/certificates


%pre systemd
getent group i2pd >/dev/null || %{_sbindir}/groupadd -r i2pd
getent passwd i2pd >/dev/null || \
  %{_sbindir}/useradd -r -g i2pd -s %{_sbindir}/nologin \
                      -d %{_sharedstatedir}/i2pd -c 'I2P Service' i2pd


%post systemd
# Move config files from old version to proper place
for f in i2pd.conf tunnels.conf; do
  if [ -f "%{_sharedstatedir}/i2pd/$f" ]; then
    %{__mv} "%{_sharedstatedir}/i2pd/$f" "%{_sysconfdir}/i2pd/$f"
  fi
done

%systemd_post i2pd.service


%preun systemd
%systemd_preun i2pd.service


%postun systemd
%systemd_postun_with_restart i2pd.service


%files
%doc LICENSE README.md contrib/i2pd.conf contrib/subscriptions.txt contrib/tunnels.conf contrib/tunnels.d
%{_sbindir}/i2pd
%{_datadir}/i2pd
%{_mandir}/man1/i2pd.1*


%files systemd
%dir %attr(0750,root,i2pd) %{_sysconfdir}/i2pd
%dir %attr(0750,root,i2pd) %{_sysconfdir}/i2pd/tunnels.conf.d
%config(noreplace) %{_sysconfdir}/i2pd/*.conf
%config(noreplace) %{_sysconfdir}/i2pd/tunnels.conf.d/*.conf
%{_sysconfdir}/i2pd/tunnels.conf.d/README
%{_sysconfdir}/i2pd/subscriptions.txt
%{_unitdir}/i2pd.service
%dir %attr(0700,i2pd,i2pd) %{_sharedstatedir}/i2pd
%dir %attr(0700,i2pd,i2pd) %{_localstatedir}/log/i2pd
%{_sharedstatedir}/i2pd/certificates
%{_sysconfdir}/logrotate.d/i2pd