File rubygem-postfix-rate-policyd.spec of Package postfix-rate-policyd

%define mod_name postfix-rate-policyd
%define mod_full_name %{mod_name}-%{version}
Name:           rubygem-postfix-rate-policyd
Version:        1.0.2
Release:        0
Summary:        Intercom mail policyd rubygem
License:        Apache-2.0
Group:          Development/Languages/Ruby
URL:            https://rubygems.org/gems/postfix-rate-policyd
Source:         %{mod_full_name}.gem
Source1:        config.yml
Source2:        postfix-rate-policyd.service
BuildRequires:  %{ruby >= 1.9}
BuildRequires:  %{rubygem gem2rpm}
BuildRequires:  ruby-macros >= 5

%description
Intercom mail policyd rubygem

%package -n postfix-rate-policyd
Summary:  Intercom mail policyd
Group:    System/Daemons
Requires: rubygem(%{mod_name}) = %{version}

%description -n postfix-rate-policyd
Intercom mail policyd daemon

%prep

%build

%install
%gem_install \
  --symlink-binaries \
  --doc-files="README.md" \
  -f
install -d %{buildroot}%{_sysconfdir}/postfix-rate
install -m 644 %{SOURCE1} %{buildroot}%{_sysconfdir}/postfix-rate/policyd.yml
install -D -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/postfix-rate-policyd.service
install -d -m 0644 %{buildroot}%{_localstatedir}/lib/postfix-rate-policyd

%gem_packages

%files -n postfix-rate-policyd
%dir %{_sysconfdir}/postfix-rate
%config(noreplace) %{_sysconfdir}/postfix-rate/policyd.yml
%{_unitdir}/postfix-rate-policyd.service
%attr(0700, itmpolicyd, itmpolicyd) %dir %{_localstatedir}/lib/postfix-rate-policyd

%pre -n postfix-rate-policyd
%{_bindir}/getent group  itmpolicyd >/dev/null || %{_sbindir}/groupadd -r itmpolicyd
%{_bindir}/getent passwd itmpolicyd >/dev/null || %{_sbindir}/useradd -r -d %{_localstatedir}/lib/postfix-rate-policyd -s /bin/false -c "intercom mail policyd" -g itmpolicyd itmpolicyd
%service_add_pre postfix-rate-policyd.service
exit 0

%preun -n postfix-rate-policyd
%service_del_preun postfix-rate-policyd.service
exit 0

%post -n postfix-rate-policyd
%tmpfiles_create %_tmpfilesdir/mailserver_agent.conf
%service_add_post postfix-rate-policyd.service
exit 0

%postun -n postfix-rate-policyd
%service_del_postun postfix-rate-policyd.service
exit 0

%changelog