File cronie.spec of Package cronie.import4562

# spec file for package cronie
# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

# norootforbuild

# 3 : we don't need to do something with /etc/sysconfig/cron for now
%define cron_configs \{/etc/init.d/cron,/etc/pam.d/crond,/etc/crontab,/etc/cron.deny,/etc/omc/srvinfo.d/cron.xml\}

Name:           cronie
BuildRequires:  audit-devel libselinux-devel pam-devel
License:        MIT and BSD and GPLv2
Group:          System/Daemons
Recommends:     smtp_daemon
Recommends:     postfix
AutoReqProv:    on
PreReq:         permissions %fillup_prereq %insserv_prereq cron sysvinit(syslog)
Version:        1.4.7
Release:        9.<RELEASE21>
%{expand: %%define cronie_version %version}
Summary:        Cron Daemon
Source0:        %name-%version.tar.gz
Source1:        cron.init
Source2:        run-crons
Source3:        sample.root
Source4:        deny.sample
Source5:        cron.xml
Source6:        cronie-rpmlintrc
Source7:        cron_to_cronie.README
Source8:        cron.service
# PATCH-FEATURE-OPENSUSE cronie-pam_config.diff added pam config file from old cron
Patch3:         %name-pam_config.diff
# openSUSE set NHEADER_LINES to 3 - old openSUSE cron put three lines of comments 
# in top of crontab file, so we want to hide this junk comments if user edit 
# crontab file with crontab -e command, patch grabbed from old openSUSE cron
Patch4:         %name-nheader_lines.diff
# we use instead of 
Patch5:         %name-crond_pid.diff
# PATCH-FIX-UPSTREAM cronie-1.4.7-syslog_output.patch bnc#692871
Patch6:         cronie-1.4.7-syslog_output.patch
Conflicts:      cron <= 4.1
# When finish update protection of sles11 we could uncomment line bellow and drop all
# ugly hacks with subpackage cron needed for proper update proces
# Obsoletes:     cron <=4.x
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

cron automatically starts programs at specific times. Add new entries
with "crontab -e". (See "man 5 crontab" and "man 1 crontab" for

Under /etc, find the directories cron.hourly, cron.daily, cron.weekly,
and cron.monthly.  Scripts and programs that are located there are
started automatically.

%package -n cron
License:        MIT and BSD and GPLv2
Version:        4.2
Release:        9.<RELEASE21>
Summary:        Auxiliary package
Group:          System/Daemons
Requires:       %{name} = %{cronie_version}-%{release}

%description -n cron
Auxiliary package, needed for proper update from vixie-cron 4.1 to cronie 1.4.4

%package anacron
License:        MIT and BSD and GPLv2
Summary:        Utility for running regular jobs
Group:          System/Base
Requires:       %{name} = %{cronie_version}

%description anacron
Anacron becames part of cronie. Anacron is used only for running regular jobs.
The default settings execute regular jobs by anacron, however this could be
overloaded in settings.

%setup -q
%patch3 -p1
%patch5 -p1
%patch6 -p1
cp %{S:7} ./cron_to_cronie.README

autoreconf -fiv
# fill macro CRON_VERSION it is used in top three lines of crontab file,should be reworked
export CFLAGS="$RPM_OPT_FLAGS -DCRON_VERSION=\\\"%{version}\\\""
export LDFLAGS="-Wl,-z,relro,-z,now,-z,defs"
%configure --with-audit --enable-anacron --with-pam --with-selinux --with-inotify --enable-pie SPOOL_DIR="/var/spool/cron/tabs"
%{__make} %{?_smp_mflags} 

%{__mkdir_p} -v %{buildroot}%{_localstatedir}/spool/cron/{tabs,lastrun}
%{__mkdir_p} -v %{buildroot}%{_sysconfdir}/cron.{d,hourly,daily,weekly,monthly}
%{__install} -v -m 600 %{SOURCE3} %{buildroot}/etc/crontab
%{__install} -v -m 600 %{SOURCE4} %{buildroot}/etc/cron.deny
%{__install} -v -d %{buildroot}/usr/lib/cron
%{__install} -v %{SOURCE2} %{buildroot}/usr/lib/cron
%{__install} -v -d %{buildroot}%{_sysconfdir}/init.d/
%{__install} -v -m744 %{SOURCE1} %{buildroot}%{_sysconfdir}/init.d/cron
%{__ln_s} -f ../../etc/init.d/cron %{buildroot}/usr/sbin/rccron
%{__install} -v -d %{buildroot}/lib/systemd/system
%{__install} -v -m 644 %{SOURCE8} %{buildroot}/lib/systemd/system
%{__install} -m 644 contrib/anacrontab $RPM_BUILD_ROOT%{_sysconfdir}/anacrontab
%{__install} -c -m755 contrib/0anacron $RPM_BUILD_ROOT%{_sysconfdir}/cron.hourly/0anacron
%{__mkdir_p} $RPM_BUILD_ROOT/var/spool/anacron
%{__mv} %{buildroot}%{_sbindir}/crond %{buildroot}%{_sbindir}/cron 

touch $RPM_BUILD_ROOT/var/spool/anacron/cron.daily
touch $RPM_BUILD_ROOT/var/spool/anacron/cron.weekly
touch $RPM_BUILD_ROOT/var/spool/anacron/cron.monthly

# service xml
%{__install} -v -d %{buildroot}%{_sysconfdir}/omc/srvinfo.d/
%{__install} -v -m644 %{S:5} %{buildroot}%{_sysconfdir}/omc/srvinfo.d/

%pre -n cron
# check if we are doing "ugly" update from old 4.1 vixie-cron
check_cron_mail_feature=`/usr/sbin/cron --help 2>&1 | /usr/bin/grep mail`
# vixie-cron 4.1 doesn't contain mail fature
if [ -e /usr/sbin/cron -a "${check_cron_mail_feature}" == "" ]; then
	# save configs for cronie post-install phase
	touch /var/run/update_from_old_cron
	echo $1
	for conf in	%{cron_configs} 
		%__mv "$conf" "$conf.bk" ||:

if [ -e /var/run/update_from_old_cron ]; then 
	# restore configs
	for conf in %{cron_configs}
		%__mv "$conf.bk" "$conf" ||:

# when we are doing rename then we pretend update with set 2
if [ -e /var/run/update_from_old_cron ]; then 
	set 2
	%restart_on_update cron
	# in %%postun restart_on_update call try-restart but we don't have init script in this phase when
	# we are doing "ugly" update, but don't panic, it produces only warning to stderr
	echo "Please ignore message about missing init script(from postun) - when occurs, we will install init script later with cronie package"
	%__mv /etc/init.d/cron /etc/init.d/cron.bk ||:
	%__ln_s /bin/true /etc/init.d/cron
%{fillup_and_insserv -y cron} 
%verify_permissions -e /etc/crontab -e /usr/bin/crontab

%stop_on_removal cron

%restart_on_update cron

if [ -e /var/run/update_from_old_cron ]; then 
	%{__rm} /var/run/update_from_old_cron ||:
	%__mv /etc/init.d/cron.bk /etc/init.d/cron ||:

%post anacron
[ -e /var/spool/anacron/cron.daily ] || touch /var/spool/anacron/cron.daily
[ -e /var/spool/anacron/cron.weekly ] || touch /var/spool/anacron/cron.weekly
[ -e /var/spool/anacron/cron.monthly ] || touch /var/spool/anacron/cron.monthly

%dir %attr(700,root,root) /var/spool/cron
%dir %attr(700,root,root) /var/spool/cron/tabs
%dir /var/spool/cron/lastrun
%config /etc/init.d/cron
%config /etc/pam.d/crond
%verify(not mode) %config(noreplace) /etc/crontab
%config(noreplace) /etc/cron.deny
%verify(not mode) %attr (4750,root,trusted) /usr/bin/crontab
%attr (755,root,root) %{_sbindir}/cron
%config %{_sysconfdir}/omc/srvinfo.d/cron.xml
%dir %{_sysconfdir}/omc/srvinfo.d/
%dir %{_sysconfdir}/omc/
%dir /lib/systemd
%dir /lib/systemd/system

%files anacron
%attr(0755,root,root) %{_sysconfdir}/cron.hourly/0anacron
%config(noreplace) %{_sysconfdir}/anacrontab
%dir /var/spool/anacron
%ghost %verify(not md5 size mtime) /var/spool/anacron/cron.daily
%ghost %verify(not md5 size mtime) /var/spool/anacron/cron.weekly
%ghost %verify(not md5 size mtime) /var/spool/anacron/cron.monthly

%files -n cron
%doc cron_to_cronie.README