%bcond_with systemd
%bcond_without pam

Summary:        Job spooling tools.
Summary(ja):    ジョブスプーリングツール
Name:           at
Version:        3.1.23
Release:        1%{?_dist_release}
License:        GPLv3+ and GPLv2+ and ISC and MIT and Public Domain
URL:            http://ftp.debian.org/debian/pool/main/a/at

Source:         http://ftp.debian.org/debian/pool/main/a/at/at_%{version}.orig.tar.gz
Source1:        pam_atd
Source2:        atd.init
Source3:        atd.sysconf
Source5:        atd.systemd

Patch0:         at-aarch64.patch
Patch1:         at-3.1.18-make.patch
Patch2:         at-3.1.20-pam.patch
Patch4:         at-3.1.14-opt_V.patch
Patch5:         at-3.1.20-shell.patch
Patch6:         at-3.1.18-nitpicks.patch
Patch8:         at-3.1.14-fix_no_export.patch 
Patch9:         at-3.1.14-mailwithhostname.patch
Patch10:        at-3.1.14-usePOSIXtimers.patch
Patch12:        at-3.1.20-aborted-jobs.patch
Patch13:        at-3.1.18-noabort.patch
Patch14:        at-3.1.16-fclose-error.patch
Patch15:        at-3.1.16-clear-nonjobs.patch
Patch16:        at-3.1.18-utc-dst.patch
Patch17:        at-3.1.20-lock-locks.patch
Patch18:        at-3.1.23-document-n.patch
Patch19:        at-3.1.20-log-jobs.patch

# http://mantis.vinelinux.org/view.php?id=2483
Patch20:        at-3.1.23-usePOSIXtimers-fix.patch

BuildRequires: fileutils 
BuildRequires: flex
BuildRequires: bison
BuildRequires: autoconf

%if %{with systemd}
Requires(post): systemd-units
Requires(preun): systemd-units
Requires(postun): systemd-units
%else
BuildRequires: chkconfig
Requires(post): chkconfig
Requires(preun): chkconfig
Requires(postun): chkconfig
%endif

%if %{with pam}
BuildRequires: pam-devel
%endif
Conflicts: crontabs <= 1.5
# No, I'm not kidding
BuildRequires: postfix
Buildroot: %{_tmppath}/%{name}-%{version}-root


%description
At and batch read commands from standard input or from a specified
file. At allows you to specify that a command will be run at a
particular time. Batch will execute commands when the system load
levels drop to a particular level. Both commands use /bin/sh.

You should install the at package if you need a utility for
time-oriented job control. Note: If it is a recurring job that will
need to be repeated at the same time every day/week, etc. you should
use crontab instead.

%description -l ja
at と batch は標準入力や指定されたファイルからコマンドを読み取ります。
at を使用して特定の時間にコマンドを実行するように指定することが可能です。
batch はシステムの負荷レベルが特定のレベルを下回るとコマンドを実行します。
両コマンドとも /bin/sh を使います。

あなたが時間志向のジョブ管理のためのユーティリティを必要とするならば、at 
パッケージをインストールしてください。

メモ: もし毎日/週などの同じ時間にくり返される必要があるジョブであれば、
代わりに crontab を使うべきでしょう。

%prep
%setup -q
cp %{SOURCE1} .
%autopatch -p1
# patch10 touches configure.in
autoconf
# for patch11
rm -f lex.yy.* y.tab.*

%build
%configure --with-atspool=%{_localstatedir}/spool/at/spool \
           --with-jobdir=%{_localstatedir}/spool/at \
           --with-daemon_username=root  \
           --with-daemon_groupname=root \
%if %{with pam}
 	   --with-pam
%endif

make

%check
# don't run "make test" by default
%{?_without_check: %define _without_check 1}
%{!?_without_check: %define _without_check 1}

%if ! %{_without_check}                                                                                                       
	LANG=C make test > /dev/null
%endif

%install
rm -rf %{buildroot}
make install \
	DAEMON_USERNAME=`id -nu`\
	DAEMON_GROUPNAME=`id -ng` \
	DESTDIR=%{buildroot}\
	sbindir=%{buildroot}%{_prefix}/sbin\
	bindir=%{buildroot}%{_bindir}\
	prefix=%{buildroot}%{_prefix}\
	exec_prefix=%{buildroot}%{_prefix}\
	docdir=%{buildroot}/usr/doc\
	mandir=%{buildroot}%{_mandir}\
	etcdir=%{buildroot}%{_sysconfdir} \
	ATJOB_DIR=%{buildroot}%{_localstatedir}/spool/at \
	ATSPOOL_DIR=%{buildroot}%{_localstatedir}/spool/at/spool \
	INSTALL_ROOT_USER=`id -nu` \
	INSTALL_ROOT_GROUP=`id -nu`;

echo > %{buildroot}%{_sysconfdir}/at.deny
mkdir docs
cp $RPM_BUILD_ROOT/%{_prefix}/doc/at/* docs/

mkdir -p %{buildroot}%{_sysconfdir}/pam.d
install -m 644 %{SOURCE1} %{buildroot}%{_sysconfdir}/pam.d/atd

%if %{with systemd}
# install systemd initscript
mkdir -p %{buildroot}/%{_unitdir}/
install -m 644 %{SOURCE5} %{buildroot}/%{_unitdir}/atd.service
%else
mkdir -p %{buildroot}%{_sysconfdir}/rc.d/init.d
install -m 755 %{SOURCE2} %{buildroot}%{_sysconfdir}/rc.d/init.d/atd
%endif

mkdir -p %{buildroot}/etc/sysconfig
install -m 755 %{SOURCE3} %{buildroot}/etc/sysconfig/atd

# remove unpackaged files from the buildroot
rm -r  %{buildroot}%{_prefix}/doc

%clean
rm -rf %{buildroot}

%post
touch %{_localstatedir}/spool/at/.SEQ
chmod 600 %{_localstatedir}/spool/at/.SEQ
chown daemon.daemon %{_localstatedir}/spool/at/.SEQ
%if %{with systemd}
%systemd_post atd.service
%else
# must be in chkconfig on
/sbin/chkconfig --add atd
%endif

%preun
%if %{with systemd}
%systemd_preun atd.service
%else
if [ "$1" = 0 ] ; then
  /sbin/service atd stop
  /sbin/chkconfig --del atd
fi
%endif

%postun
%if %{with systemd}
%systemd_postun_with_restart atd.service
%else
if [ "$1" -ge "1" ]; then
  /sbin/service atd condrestart
fi
%endif

%files
%defattr(-,root,root)
%doc docs/*
%config %{_sysconfdir}/at.deny
%if %{with systemd}
%attr(0644,root,root)		%{_unitdir}/atd.service
%else
%attr(0700,root,root)		%{_sysconfdir}/rc.d/init.d/atd
%endif
%attr(0700,root,root)		%{_sysconfdir}/sysconfig/atd
%attr(0700,daemon,daemon)	%dir %{_localstatedir}/spool/at
%attr(0600,daemon,daemon)	%verify(not md5 size mtime) %ghost %{_localstatedir}/spool/at/.SEQ
%attr(0700,daemon,daemon) %dir %{_localstatedir}/spool/at/spool
%attr(0640,root,daemon)	%config(noreplace) /etc/pam.d/atd
%{_sbindir}/atrun
%attr(0755,root,root)	%{_sbindir}/atd
%{_mandir}/man*/*
%{_bindir}/batch
%{_bindir}/atrm
%{_bindir}/atq
%attr(4755,root,root) %{_bindir}/at

%changelog
* Sat Apr 04 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.1.23-1
- new upstream release.
- imported Patch12-19 from rawhide.
- updated Patch20.

* Sun Jun 15 2014 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.1.14-1
- new upstream release.
- updated Patch1.
- removed Patch11 (no longer needed).

* Sat Nov 10 2012 Daisuke SUZUKI <daisuke@linux.or.jp> 3.1.13-4
- re-add Patch10 and Patch12 to use posix timer
  - http://mantis.vinelinux.org/view.php?id=2483

* Sat Nov 10 2012 Daisuke SUZUKI <daisuke@linux.or.jp> 3.1.13-3
- remove Patch10
  - atd doesn't execute queued job until the next jobs is queued.

* Thu Nov 08 2012 Daisuke SUZUKI <daisuke@linux.or.jp> 3.1.13-2
- fix pam_atd to use system-auth instead of password-auth

* Tue Nov 06 2012 Daisuke SUZUKI <daisuke@linux.or.jp> 3.1.13-1
- update to 3.1.13
- update patches to sync with fedora 3.1.13-10.

* Mon Sep 27 2010 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.1.10.1-17
- rebuild with rpm-4.8.1

* Tue Mar 31 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 3.1.10.1-16
- spec in utf-8

* Tue May 27 2008 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 3.1.10.1-15
- new upstream release
- apply new versioning policy

* Thu Jul 12 2007 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 3.1.10-14vl1
- update based on fedora development 3.1.10-14.
- build with new toolchains.
  * Tue Jul  9 2007 Marcela Maslanova <mmaslano@redhat.com> - 3.1.10-14
  - feature: add configuration file
  - fix -V option
  - fix init script

  * Tue Jul  3 2007 Marcela Maslanova <mmaslano@redhat.com> - 3.1.10-13
  - Resolves: rhbz#243064

  * Tue Jul  3 2007 Marcela Maslanova <mmaslano@redhat.com> - 3.1.10-12
  - crashing atd
  - work only for root, still broken some functions
  - Resolves: rhbz#243064

  * Tue Mar 27 2007 Marcela Maslanova <mmaslano@redhat.com> - 3.1.10-11
  - mistake in pam_atd
  - rhbz#234120

  * Tue Mar 05 2007 Marcela Maslanova <mmaslano@redhat.com> - 3.1.10-10
  - rhbz#224597

  * Mon Mar 03 2007 Marcela Maslanova <mmaslano@redhat.com> - 3.1.10-9
  - review
  
  * Wed Feb 20 2007 Marcela Maslanova <mmaslano@redhat.com> - 3.1.10-8
  - review
  - rhbz#225288
  
  * Tue Jan 30 2007 Marcela Maslanova <mmaslano@redhat.com> - 3.1.10-7
  - no debug file - useless
  - new pam configuration
  - rhbz#224597
  
  * Tue Oct 27 2006 Marcela Maslanova <mmaslano@redhat.com> - 3.1.10-6
  - fix daylight-saving again 
  - fix #214759 - problem with seteuid
  
  * Wed Oct 25 2006 Marcela Maslanova <mmaslano@redhat.com> - 3.1.10-5
  - daylight-saving
  
  * Tue Oct 24 2006 Marcela Maslanova <mmaslano@redhat.com> - 3.1.10-3
  - new version from upstream 3.1.10
  
  * Thu Aug 23 2006 Marcela Maslanova <mmaslano@redhat.com> - 3.1.8-82.fc6
  - #176486 don't fork option added (patch from Enrico Scholz)

  * Wed Jul 12 2006 Jesse Keating <jkeating@redhat.com> - 3.1.8-81.2
  - rebuild
  
  * Fri Feb 10 2006 Jesse Keating <jkeating@redhat.com> - 3.1.8-81.1
  - bump again for double-long bug on ppc(64)
  
  * Tue Feb 07 2006 Jason Vas Dias <jvdias@redhat.com> - 3.1.8-81
  - rebuild for new gcc, glibc, glibc-kernheaders
  - workaround new refusal of /usr/bin/install to chown
  
  * Fri Dec 18 2005 Jason Vas Dias<jvdias@redhat.com> - 3.1.8-80.2
  - rebuild for new flex
  
  * Fri Dec 16 2005 Jesse Keating <jkeating@redhat.com>
  - rebuilt for new gcj
  
  * Fri Oct 14 2005 Dan Walsh <dwalsh@redhat.com> - 3.1.8-80
  - Add seuserbyname support
  
  * Fri Sep 30 2005 Tomas Mraz <tmraz@redhat.com> - 3.1.8-79
  - use include instead of pam_stack in pam config
  
  * Fri Jun 03 2005 Jason Vas Dias <jvdias@redhat.com> 3.1.8-78
  - fix bug 159220: add pam_loginuid to pam session stack in /etc/pam.d/atd 
  - fix bug 102341: add '-r' synonym for '-d' / atrm for POSIX / SuS conformance
  
  * Fri Apr 08 2005 Jason Vas Dias <jvdias@redhat.com> 3.1.8-77
  - always call pam_setcred(pamh, PAM_DELETE_CRED) before session 
  - close
  
  * Tue Apr 05 2005 Jason Vas Dias <jvdias@redhat.com> 3.1.8-70
  - always call pam_close_session on PAM_FAIL or pam_end
  
  * Tue Mar 08 2005 Jason Vas Dias <jvdias@redhat.com> 3.1.8-68
  - Put PAM authentication check in 'check_permissions()', so
  - user can know when using at(1) if PAM permission is denied.
  
  * Tue Mar 08 2005 Jason Vas Dias <jvdias@redhat.com> 3.1.8-67
  - better fix for bug 150131: change DAEMON_USERNAME and 
  - DAEMON_GROUPNAME to 'root' .
  
  * Mon Mar 07 2005 Jason Vas Dias <jvdias@redhat.com> 3.1.8-66
  - fix bug 150131: atd should not relinquish root privilege if
  - doing su(1) equivalent with PAM .
  
  * Tue Jan 25 2005 Jason Vas Dias <jvdias@redhat.com> 3.1.8-64
  - bugs 5160/146132: add PAM authentication control to atd

* Tue Nov 23 2004 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.1.8-60vl1
- based on Fedora development 3.1.8-60
  * Tue Oct 05 2004 Jason Vas Dias <jvdias@redhat.com> 3.1.8-60
  - fix bug 131510: no_export env. var. blacklisting should not
  - remove 'SHELL' when only 'SHELLOPTS' is blacklisted.
  - at(1) man-page should not say 'commands are run with /bin/sh'
  - and should explain usage of SHELL environement variable and
  - details of blacklisted variables.
  * Tue Sep 28 2004 Rik van Riel <riel@redhat.com> 3.1.8-58
  - fix typo in man page, bug 112303 
  - (regenerated at-3.1.8-man-timespec-path.patch with fix)
  * Tue Aug 03 2004 Jason Vas Dias <jvdias@redhat.com>
  - fixed bug 125634 - made usage() agree with manpage
  * Thu Jul 29 2004 Jason Vas Dias <jvdias@redhat.com>
  - Added POSIX.2 -t option for RFE 127485
  * Fri Jun 20 2003 Jens Petersen <petersen@redhat.com> - 3.1.8-46
  - add at-3.1.8-atrun.8-typo-97697.patch to fix typo in atrun.8 (#97697)
  - update at.1 description of shell behaviour (#91233)
  * Tue Jun 17 2003 Jens Petersen <petersen@redhat.com> - 3.1.8-45
  - make the job shell default to SHELL instead of "/bin/sh" (#91233)
  * Tue Jun  3 2003 Jens Petersen <petersen@redhat.com> - 3.1.8-43
  - Replace redundant at-3.1.7-paths.patch by at-3.1.8-man-timespec-path.patch
    to fix timespec path
  * Tue Jun  3 2003 Jens Petersen <petersen@redhat.com> - 3.1.8-41
  - update source to at_3.1.8-11 from debian upstream
    - update source url
    - at-debian.patch no longer needed
    - at-3.1.7-paths.patch: the patch to "at.1.in" no longer needed
    - replace at-3.1.8-lexer.patch with at-3.1.8-11-lexer-parser.diff
    - at-3.1.8-dst.patch no longer needed
    - at-3.1.8-lsbdoc.patch no longer needed
    - at-3.1.8-o_excl.patch no longer needed
    - bump release number
- added Japanese summary and description from vinedocs.sf.jp :)
- rebuild with new toolchains

* Wed Jan 23 2002 Toru Sagami <sagami@vinelinux.org> 3.1.8-23vl1
- follow 3.1.8-23 (RHSA-2002:015-13)
- apply docpath patch instead of patch16 (due to brute-force patch2 unrevised)
- Replace sendmail with /usr/sbin/sendmail (postfix) for BuildPreReq

* Sat Jun 09 2001 <sagami@vinelinux.org>
- 3.1.8-12vl3: rebuilt for %%{_mandir}

* Tue Dec 12 2000 Daisuke SUZUKI <daisuke@linux.or.jp> 3.1.8-12vl2
- remove /etc/init.d from PreReq

* Sun Nov 19 2000 Satoshi MACHINO <machino@vinelinux.org> 3.1.8-12vl1
- build on Vine Linux with gcc-2.95.3

* Wed Aug 23 2000 Crutcher Dunnavant <crutcher@redhat.com>
- Well, we will likely never really close the UTC issues,
- because of 1) fractional timezones, and 2) daylight savigns time.
- but there is a slight tweak to the handling of dst in the UTC patch.

* Wed Aug 23 2000 Crutcher Dunnavant <crutcher@redhat.com>
- fixed bug #15685
- which had at miscaluclating UTC times.

* Sat Jul 15 2000 Bill Nottingham <notting@redhat.com>
- move initscript back

* Wed Jul 12 2000 Prospector <bugzilla@redhat.com>
- automatic rebuild

* Thu Jul  6 2000 Bill Nottingham <notting@redhat.com>
- prereq /etc/init.d

* Sat Jul  1 2000 Nalin Dahyabhai <nalin@redhat.com>
- fix syntax error in init script

* Tue Jun 27 2000 Preston Brown <pbrown@redhat.com>
- don't prereq, only require initscripts

* Mon Jun 26 2000 Preston Brown <pbrown@redhat.com>
- move init script
- add condrestart directive
- fix post/preun/postun scripts
- prereq initscripts >= 5.20

* Sat Jun 17 2000 Bill Nottingham <notting@redhat.com>
- fix verify of /var/spool/at/.SEQ (#12262)

* Mon Jun 12 2000 Nalin Dahyabhai <nalin@redhat.com>
- fix status checking and syntax error in init script

* Fri Jun  9 2000 Bill Nottingham <notting@redhat.com>
- fix for long usernames (#11321)
- add some bugfixes from debian

* Mon May  8 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- 3.1.8

* Wed Mar  1 2000 Bill Nottingham <notting@redhat.com>
- fix a couple of more typos, null-terminate some strings

* Thu Feb 10 2000 Bill Nottingham <notting@redhat.com>
- fix many-years-old typo in atd.c

* Thu Feb  3 2000 Bill Nottingham <notting@redhat.com>
- handle compressed man pages

* Mon Aug 16 1999 Bill Nottingham <notting@redhat.com>
- initscript munging, build as non-root user

* Sun Jun 13 1999 Jeff Johnson <jbj@redhat.com>
- correct perms for /var/spool/at after defattr.

* Mon May 24 1999 Jeff Johnson <jbj@redhat.com>
- reset SIGCHLD before exec (#3016).

* Sun Mar 21 1999 Cristian Gafton <gafton@redhat.com> 
- auto rebuild in the new build environment (release 8)

* Thu Mar 18 1999 Cristian Gafton <gafton@redhat.com>
- fix handling the 12:00 time

* Wed Jan 13 1999 Bill Nottingham <notting@redhat.com>
- configure fix for arm

* Wed Jan 06 1999 Cristian Gafton <gafton@redhat.com>
- build for glibc 2.1

* Tue May 05 1998 Prospector System <bugs@redhat.com>
- translations modified for de, fr, tr

* Wed Apr 22 1998 Michael K. Johnson <johnsonm@redhat.com>
- enhanced initscript

* Sun Nov 09 1997 Michael K. Johnson <johnsonm@redhat.com>
- learned to spell

* Wed Oct 22 1997 Michael K. Johnson <johnsonm@redhat.com>
- updated to at version 3.1.7
- updated lock and sequence file handling with %ghost
- Use chkconfig and atd, now conflicts with old crontabs packages

* Thu Jun 19 1997 Erik Troan <ewt@redhat.com>
- built against glibc

