File i2pd.spec of Package i2pd

%{!?cmake_build:%define cmake_build %{make_build}}
%{!?cmake_install:%define cmake_install %{make_install}}

Name:           i2pd
Version:        2.42.1
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

BuildRequires:  cmake >= 2.8.12
BuildRequires:  gcc-c++
BuildRequires:  zlib-devel
BuildRequires:  boost-devel
BuildRequires:  openssl-devel
BuildRequires:  miniupnpc-devel
BuildRequires:  systemd-units

Requires:       logrotate
Requires:       systemd
Requires(pre):  %{_sbindir}/useradd %{_sbindir}/groupadd

Provides:       %{name}-daemon = %{?epoch?%{epoch}:}%{version}-%{release}
Provides:       %{name}-systemd = %{?epoch?%{epoch}:}%{version}-%{release}
Obsoletes:      %{name}-daemon
Obsoletes:      %{name}-systemd


%description
C++ implementation of I2P.


%prep
%setup -q


%build
cd build
%cmake \
    -DWITH_LIBRARY=OFF \
    -DWITH_UPNP=ON \
    -DWITH_HARDENING=ON \
    -DBUILD_SHARED_LIBS:BOOL=OFF \
    -DCMAKE_SKIP_RPATH:BOOL=ON \
    -DCMAKE_INSTALL_BINDIR:STRING=sbin

%cmake_build


%install
pushd build
%cmake_install
popd
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 contrib/i2pd.conf %{buildroot}%{_sysconfdir}/i2pd/i2pd.conf
install -D -m 644 contrib/subscriptions.txt %{buildroot}%{_sysconfdir}/i2pd/subscriptions.txt
install -D -m 644 contrib/tunnels.conf %{buildroot}%{_sysconfdir}/i2pd/tunnels.conf
install -D -m 644 contrib/i2pd.logrotate %{buildroot}%{_sysconfdir}/logrotate.d/i2pd
install -D -m 644 %{SOURCE1} %{buildroot}%{_unitdir}/i2pd.service
install -D -m 644 debian/i2pd.1 %{buildroot}%{_mandir}/man1/i2pd.1
cp -r contrib/certificates/ %{buildroot}%{_datadir}/i2pd/certificates
cp -r contrib/tunnels.d/ %{buildroot}%{_sysconfdir}/i2pd/tunnels.conf.d
ln -s %{_datadir}/%{name}/certificates %{buildroot}%{_sharedstatedir}/i2pd/certificates


%pre
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_post i2pd.service


%preun
%systemd_preun i2pd.service


%postun
%systemd_postun_with_restart i2pd.service


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


%files
%license LICENSE
%doc README.md contrib/i2pd.conf contrib/subscriptions.txt contrib/tunnels.conf contrib/tunnels.d
%{_sbindir}/i2pd
%{_datadir}/i2pd
%{_mandir}/man1/i2pd.1*
%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