%bcond_with systemd

Summary:        Inotify cron system
Name:           incron
Version:        0.5.12
Release:        5%{?_dist_release}%{?with_systemd:.systemd}
Group:          System Environment/Base
Vendor:         Project Vine
Distribution:   Vine Linux
Packager:       tomop

License:        GPLv2
URL:            https://github.com/ar-/incron
Source0:        https://github.com/ar-/incron/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source1:        incrond.init
Source2:        incrond.service
Patch0:         incron-0.5.10-gcc.patch
Patch1:         incron-0.5.12-prevent-zombies.patch
# https://github.com/ar-/incron/pull/45/commits/134900ea1dd19834ba6e6c7e7e07611a0e0d78a0
Patch2:         incron-fix-segv-on-mkdir.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

%if %{with systemd}
%{?systemd_requires}
%else
Requires(post):   /sbin/chkconfig
Requires(preun):  /sbin/chkconfig, /sbin/service
Requires(postun): /sbin/service
%endif

%description
This program is an "inotify cron" system.
It consists of a daemon and a table manipulator.
You can use it a similar way as the regular cron.
The difference is that the inotify cron handles
filesystem events rather than time periods.

%prep
%setup -q
%patch0 -p1 -b .gcc
%patch1 -p1 -b .zombie
%patch2 -p1 -b .mkdir

%if %{with systemd}
sed -i -e 's|/var/run|/run|' \
	appinst.h \
	incron.conf.5 \
	incron.conf.example \
	incroncfg.cpp
%endif

%build
make %{?_smp_mflags} CXXFLAGS="%{optflags}"


%install
rm -rf %{buildroot}

#install files manually since source Makefile tries to do it as root
install -D -p incrond %{buildroot}%{_sbindir}/incrond
install -D -p -m 4755 incrontab %{buildroot}%{_bindir}/incrontab
install -d %{buildroot}%{_localstatedir}/spool/%{name}
install -d %{buildroot}%{_sysconfdir}/%{name}.d
install -D -p -m 0644 incron.conf.example %{buildroot}%{_sysconfdir}/%{name}.conf

%if %{with systemd}
install -D -p -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/incrond.service
%else
install -D -p -m 0755 %{SOURCE1} %{buildroot}%{_initdir}/incrond
%endif

# install manpages
make install-man MANPATH="%{buildroot}%{_mandir}" INSTALL="install -D -p"

%post
%if %{with systemd}
%systemd_post incrond.service
%else
if [ $1 -eq 1 ]; then
    /sbin/chkconfig --add incrond
fi
%endif


%preun
%if %{with systemd}
%systemd_preun incrond.service
%else
if [ $1 -eq 0 ]; then
        /sbin/service %{name} stop >/dev/null 2>&1 || :
        /sbin/chkconfig --del incrond
fi
%endif


%postun
%if %{with systemd}
%systemd_postun_with_restart incrond.service
%else
if [ $1 -ge 1 ]; then
        /sbin/service incrond condrestart >/dev/null 2>&1 || :
fi
%endif


%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root,-)
%license COPYING LICENSE*
%doc CHANGELOG README TODO
%attr(4755,root,root) %{_bindir}/incrontab
%{_sbindir}/incrond
%if %{with systemd}
%{_unitdir}/incrond.service
%else
%{_initdir}/incrond
%endif
%config(noreplace) %{_sysconfdir}/%{name}.conf
%{_mandir}/man1/incrontab.1.gz
%{_mandir}/man5/incrontab.5.gz
%{_mandir}/man5/incron.conf.5.gz
%{_mandir}/man8/incrond.8.gz
%dir %{_localstatedir}/spool/%{name}
%dir %{_sysconfdir}/%{name}.d


%changelog
* Sun Apr 05 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.5.12-5
- added R(postun):.
- added systemd stuff (disabled as default).

* Mon Dec 02 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.5.12-4
- imported Patch2.

* Mon Nov 04 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.5.12-3
- replaced Patch1.

* Sat Jul  9 2016 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.5.12-2
- added Patch1.

* Thu Jul  7 2016 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.5.12-1
- new upstream release.

* Sun Jan 12 2014 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.5.10-2
- rebuilt with current environment.

* Fri May 04 2012 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.5.10-1
- new upstream release.
- built for Vine Linux.

* Thu Feb 16 2012 Jon Ciesla <limburgher@gmail.com> - 0.5.9-4
- Migrate to systemd, BZ 789688.
- gcc47 patch.

* Fri Jan 13 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.5.9-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild

* Wed Feb 09 2011 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.5.9-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild

* Mon Dec 21 2009 Ruben Kerkhof <ruben@rubenkerkhof.com> 0.5.9-1
- Upstream released new version

* Fri Jul 24 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.5.8-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild

* Wed Feb 25 2009 Ruben Kerkhof <ruben@rubenkerkhof.com> 0.5.8-1
- Upstream released new version
- GCC 4.4 fixes
- Drop GCC 4.3 patch, fixed upstream

* Tue Feb 24 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.5.7-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_11_Mass_Rebuild

* Sat Feb 09 2008 Ruben Kerkhof <ruben@rubenkerkhof.com> - 0.5.7-1
- Sync with upstream

* Tue Mar 13 2007 <ruben@rubenkerkhof.com> 0.5.5-1
- Sync with upstream
* Mon Feb 12 2007 <ruben@rubenkerkhof.com> 0.5.4-1
- Update to new upstream version
- Upstream fixed permissions on pidfile
- New manpage for incron.conf
- Upstream fixed example conf file
* Sun Feb 04 2007 <ruben@rubenkerkhof.com> 0.5.1-1
- Updated to new upstream version
- Upstream fixed the incorrect encoding of the LICENSE-GPL file
* Sat Jan 27 2007 <ruben@rubenkerkhof.com> 0.5.0-1
- Updated to new upstream version
- Changed the service name in the scriptlets
- Added a configuration file
- Included GPL License
* Sat Jan 27 2007 <ruben@rubenkerkhof.com> 0.4.0-1
- First try at packaging it up
