%define nokerberos False
%define _initdir   /etc/rc.d/init.d
%define use_alternatives 1

Summary: LPRng Print Spooler
Summary(ja): LPRng プリントスプーラ
Name: LPRng
Version: 3.8.21
Release: 1%{?_dist_release}
License: GPL and Artistic
Group: System Environment/Daemons
Source0: ftp://ftp.astart.com/pub/LPRng/LPRng/%{name}-%{version}.tgz
Source1: lpd.init
Patch0: LPRng-3.8.4-nonblock.patch
Patch1: LPRng-3.7.4-lpd-perms.patch
Patch2: LPRng-3.8.15-krb5.patch

Patch3: LPRng-3.8.21-config.sub.patch
Patch4: LPRng-3.8.21-lpq.patch
Patch5: LPRng-3.8.21-lpf.patch

# Vine Patch
Patch101: LPRng-3.7.4-negative-check.patch

URL: http://www.astart.com/LPRng.html
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root
Obsoletes: lpr
Provides: lpr
#Prereq: /sbin/chkconfig, %{_initdir}, mktemp, fileutils, textutils, gawk
Prereq: /sbin/chkconfig, mktemp, fileutils, textutils, gawk
BuildPreReq: gettext
%{!?nokerberos:BuildPrereq: krb5-devel}
%{!?nokerberos:Requires: krb5-libs}

%if %use_alternatives
Provides: /usr/bin/lpq /usr/bin/lpr /usr/bin/lp /usr/bin/cancel /usr/bin/lprm /usr/bin/lpstat
Prereq: alternatives
%endif

Vendor: Project Vine
Distribution: Vine Linux
Packager: Daisuke SUZUKI <daisuke@linux.or.jp>

%description
The LPRng software is an enhanced, extended, and portable implementation
of the Berkeley LPR print spooler functionality. While providing the
same interface and meeting RFC1179 requirements, the implementation
is completely new and provides support for the following features:
lightweight (no databases needed) lpr, lpc, and lprm programs; dynamic
redirection of print queues; automatic job holding; highly verbose
diagnostics; multiple printers serving a single queue; client programs
do not need to run SUID root; greatly enhanced security checks; and a
greatly improved permission and authorization mechanism.

The source software compiles and runs on a wide variety of UNIX systems,
and is compatible with other print spoolers and network printers that
use the LPR interface and meet RFC1179 requirements.  LPRng provides
emulation packages for the SVR4 lp and lpstat programs, eliminating the
need for another print spooler package. These emulation packages can be
modified according to local requirements, in order to support vintage
printing systems.

For users that require secure and/or authenticated printing support,
LPRng supports Kerberos V, MIT Kerberos IV Print Support, and PGP
authentication.  LPRng is being adopted by MIT for use as their Campus
Wide printing support system. Additional authentication support is
extremely simple to add.


%prep
%setup -q
%patch0 -p1 -b .nonblock
%patch1 -p1 -b .lpd-perms
%{!?nokerberos:%patch2 -p1 -b .kerb5}

%patch3 -p1 -b .config.sub
%patch4 -p1 -b .lpq
%patch5 -p1 -b .lpf

%patch101 -p1 -b .negative

# pick up configure.in changes
autoconf

## set up gettext
#cd po
#rm Makefile.in.in
#ln -s /usr/share/gettext/po/Makefile.in.in .
#cd ..
##rm -fr intl

    
%build
CFLAGS="-O2" ; export CFLAGS
%configure \
	--enable-nls \
	--with-userid=lp \
	--with-groupid=lp \
%{!?nokerberos:--enable-kerberos}
make MAKEPACKAGE=YES



%install
rm -rf %{buildroot}

# Installation of locales is broken... Work around it!
perl -pi -e "s,prefix =.*,prefix = %{buildroot}%{_prefix},g" po/Makefile
perl -pi -e "s,datadir =.*,datadir = %{buildroot}%{_prefix}/share,g" po/Makefile
perl -pi -e "s,localedir =.*,localedir = %{buildroot}%{_prefix}/share/locale,g" po/Makefile
perl -pi -e "s,gettextsrcdir =.*,gettextsrcdir = %{buildroot}%{_prefix}/share/gettext/po,g" po/Makefile

make SUID_ROOT_PERMS=" 04755" DESTDIR=%{buildroot} MAKEPACKAGE=YES mandir=%{_mandir} install
%__cp src/monitor %{buildroot}%{_prefix}/sbin/monitor


# install init script
mkdir -p %{buildroot}%{_sysconfdir}/rc.d/init.d
install -m755 %{SOURCE1} %{buildroot}%{_sysconfdir}/rc.d/init.d/lpd

%if %use_alternatives
cd %{buildroot}%{_bindir}
for i in cancel lp lpq lpr lprm lpstat; do
	mv $i $i.lprng
done
cd %{buildroot}%{_sbindir}
mv lpc lpc.lprng
cd %{buildroot}%{_mandir}/man1
for i in cancel lp lpq lpr lprm lpstat; do
	mv $i.1 $i-lprng.1
done

cd %{buildroot}%{_mandir}/man8
mv lpc.8 lpc-lprng.8
%endif

mv %{buildroot}%{_sysconfdir}/printcap %{buildroot}%{_sysconfdir}/printcap.sample

%clean
rm -rf %{buildroot}


%post
/sbin/chkconfig --add lpd
if [ -w /etc/printcap ] ; then
  TMP1=`mktemp /etc/printcap.XXXXXX`
  gawk '
    BEGIN { first = 1; cont = 0; last = "" }
    /^[:space:]*#/      { if(cont) sub("\\\\$", "", last)}
    { if(first == 0) print last }
    { first = 0 }
    { last = $0 }
    { cont = 0 }
    /\\$/ { cont = 1 }
    END {sub("\\\\$", "", last); print last}
  ' /etc/printcap > ${TMP1} && cat ${TMP1} > /etc/printcap && rm -f ${TMP1}
fi

%if %use_alternatives
/sbin/update-alternatives --install %{_bindir}/lpr print %{_bindir}/lpr.lprng 40 \
	--slave %{_bindir}/lp print-lp %{_bindir}/lp.lprng \
	 --slave %{_bindir}/lpq print-lpq %{_bindir}/lpq.lprng \
	 --slave %{_bindir}/lprm print-lprm %{_bindir}/lprm.lprng \
	 --slave %{_bindir}/lpstat print-lpstat %{_bindir}/lpstat.lprng \
	 --slave %{_bindir}/cancel print-cancel %{_bindir}/cancel.lprng \
	 --slave %{_sbindir}/lpc print-lpc %{_sbindir}/lpc.lprng \
	 --slave %{_mandir}/man1/cancel.1.gz print-cancelman %{_mandir}/man1/cancel-lprng.1.gz \
	 --slave %{_mandir}/man1/lp.1.gz print-lpman %{_mandir}/man1/lp-lprng.1.gz \
	 --slave %{_mandir}/man8/lpc.8.gz print-lpcman %{_mandir}/man8/lpc-lprng.8.gz \
	 --slave %{_mandir}/man1/lpq.1.gz print-lpqman %{_mandir}/man1/lpq-lprng.1.gz \
	 --slave %{_mandir}/man1/lpr.1.gz print-lprman %{_mandir}/man1/lpr-lprng.1.gz \
	 --slave %{_mandir}/man1/lprm.1.gz print-lprmman %{_mandir}/man1/lprm-lprng.1.gz \
	 --slave %{_mandir}/man1/lpstat.1.gz print-lpstatman %{_mandir}/man1/lpstat-lprng.1.gz 
%endif

%preun
if [ "$1" = 0 ]; then
  %{_initdir}/lpd stop >/dev/null 2>&1
  /sbin/chkconfig --del lpd

%if %use_alternatives
  /sbin/update-alternatives --remove print %{_bindir}/lpr.lprng
%endif
fi


%postun
if [ "$1" -ge "1" ]; then
  %{_initdir}/lpd condrestart >/dev/null 2>&1
fi


%triggerpostun -- lpr
/sbin/chkconfig --add lpd


%files
%defattr(-,root,root)
%attr(644,root,root) %config(noreplace) %{_sysconfdir}/lpd.conf
%attr(644,root,root) %config(noreplace) %{_sysconfdir}/lpd.perms
%config %{_sysconfdir}/rc.d/init.d/lpd
%{_sysconfdir}/printcap.sample
%{_sysconfdir}/lpd.conf.sample
%{_sysconfdir}/lpd.perms.sample
%ifarch x86_64
%{_libdir}
%else
%{_libdir}/*.so.*
%endif
%attr(755,lp,lp) %{_bindir}/lpq.lprng
%attr(755,lp,lp) %{_bindir}/lprm.lprng
%attr(755,lp,lp) %{_bindir}/lpr.lprng
%attr(755,lp,lp) %{_bindir}/lpstat.lprng
%{_bindir}/lp.lprng
%{_bindir}/cancel.lprng
%attr(755,lp,lp) %{_sbindir}/lpc.lprng
%attr(755,root,root)  %{_sbindir}/lpd
%attr(755,root,root)  %{_sbindir}/checkpc
%attr(755,root,root)  %{_sbindir}/monitor
%attr(755,root,root)  /usr/libexec/filters/*
%{_mandir}/*/*
%doc CHANGES CONTRIBUTORS COPYRIGHT INSTALL LICENSE 
%doc README* VERSION Y2KCompliance
%doc HOWTO/*.html HOWTO/*.jpg


%changelog
* Sun Sep 14 2008 Shu KONNO <owa@bg.wakwak.com> 3.8.21-1vl5
- applied new versioning policy, spec in utf-8

* Mon Nov 26 2007 Shu KONNO <owa@bg.wakwak.com> 3.8.21-0vl3
- changed source url to ftp://ftp.lprng.com/pub/LPRng/LPRng/LPRng-%%{version}.tgz
- added Patch3: LPRng-3.8.21-config.sub.patch (for x86_64)
- added Patch4: LPRng-3.8.21-lpq.patch
- added Patch5: LPRng-3.8.21-lpf.patch
- added %{_sysconfdir}/{printcap,lpd.conf,lpd.perms}.sample in %%files section

* Fri Oct 31 2003 Tomoya TAKA <taka@vinelinux.org> 3.8.21-0vl2
- remove workaround for gettext in %%prep

* Mon Sep  1 2003 Tomohiro 'Tomo-p' KATO <tomop@teamgedoh.net> 3.8.21-0vl1.1
- use alternatives.

* Wed Jun  4 2003 Jun Nishii <jun@vinelinux.org> 3.8.21-0vl1
- ver.up

* Wed Jan 29 2003 Tomoya TAKA <taka@vinelinux.org> 3.8.20-0vl1
- drop LPRng-3.7.4-alpha-direct.patch
- drop HOWTO/*.gif and add HOWTO/*.jpg from/to %%doc

* Mon Jan 23 2003 Satoshi MACHINO <machino@vinelinux.org> 3.8.20-0vl1
- updated to 3.8.20
	-- dropped LPRng-3.7.4-lockfile.patch
	-- dropped LPRng-3.7.4-nointl.patch
	-- dropped LPRng-3.7.4-inet_ntop.patch
	-- added /usr/lib/liblpr.so
- imported some patches from LPRng-3.8.19-1
	-- added LPRng-3.8.4-nonblock.patch
	-- added LPRng-3.7.4-lpd-perms.patch
	-- added LPRng-3.8.15-krb5.patch
	
* Fri Jul 13 2001 Daisuke SUZUKI <daisuke@linux.or.jp> 3.7.4-6vl5
- change CFLAGS in %make from -ggdb to -O2

* Thu Feb 15 2001 Tomoya TAKA <tomoya@olive.plala.or.jp>
- 3.7.4-6vl4
- change type of Direct_DYN on alpha (int -> int64_t)

* Wed Feb 14 2001 Jun Nishii <jun@vinelinux.org>
- 3.7.4-6vl3
- negative solution to avoid changing permision of the filter under spool directory.

* Thu Feb  8 2001 Jun Nishii <jun@vinelinux.org>
- 3.7.4-6vl2
- fix lpd.init

* Tue Feb  6 2001 Jun Nishii <jun@vinelinux.org>
- 3.7.4-6vl1

* Sat Feb 03 2001 MATSUBAYASHI 'Shaolin' Kohji <shaolin@rhythmaning.org>
- 3.6.26-1vl2
- remove /etc/rc.d/init.d from Prereq: for better compatibility with apt
- added Japanese summary
- use better macro(s) (%%{_initdir})

* Tue Dec 19 2000 Jun Nishii <jun@vinelinux.org>
- 3.6.26-1vl1

* Sat Oct 21 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- 3.2.26; fixes some security problems (Bug #19518)

* Mon Sep 11 2000 Crutcher Dunnavant <crutcher@redhat.com>
- Added gettext to the BuildPreReq list

* Mon Sep 11 2000 Crutcher Dunnavant <crutcher@redhat.com>
- Fixed lpd.init to use /etc/rc.d/init.d/, instead of /etc/init.d

* Mon Sep 11 2000 Crutcher Dunnavant <crutcher@redhat.com>
- changed the prereq: /etc/init.d to: /etc/rc.d/init.d
- we are not changing that over (yet?)

* Mon Aug 14 2000 Crutcher Dunnavant <crutcher@redhat.com>
- removed the sticky bit from lpc

* Mon Aug 14 2000 Crutcher Dunnavant <crutcher@redhat.com>
- removed the sticky bit from the client programs (LPRng doesn't need them)

* Sat Aug 05 2000 Bill Nottingham <notting@redhat.com>
- condrestart fixes

* Fri Aug  4 2000 Bill Nottingham <notting@redhat.com>
- triggerpostun on lpr

* Sun Jul 30 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- 3.6.22 (some fixes)

* Tue Jul 25 2000 Bill Nottingham <notting@redhat.com>
- fix prereq

* Sat Jul 22 2000 Nalin Dahyabhai <nalin@redhat.com>
- fix bogus checkpc error messages when the lockfile doesn't exist because
  init scripts clear /var/run (#14472)

* Tue Jul 18 2000 Nalin Dahyabhai <nalin@redhat.com>
- fix chkconfig comments in the init script

* Mon Jul 17 2000 Nalin Dahyabhai <nalin@redhat.com>
- move the init script to /etc/rc.d/init.d
- fix perms on setuid binaries

* Fri Jul 14 2000 Nalin Dahyabhai <nalin@redhat.com>
- patch checkpc to not complain when filter is executable and in the
  spool directory
- remove --disable-force_localhost from configure invocation for better
  compatibility with BSD LPR and rhs-printfilters
- change group back to lp, which is what printtool expects

* Thu Jul 13 2000 Nalin Dahyabhai <nalin@redhat.com>
- change default group to 'daemon' to match 6.2
- enable NLS support
- remove Prefix: tag
- break init script out into a separate file
- fix up broken printcaps in post-install
- run checkpc -f at start-time

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

* Tue Jul 11 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- 3.6.21
- get rid of the notypedef patch - gcc has been fixed at last.

* Mon Jun 26 2000 Preston Brown <pbrown@redhat.com>
- sample config files removed from /etc.
- initscript moved to /etc/init.d

* Wed Jun 21 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- 3.6.18

* Sat Jun 17 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- 3.6.16
- adapt Kerberos and fixmake patches
- get rid of CFLAGS="-O"; gcc has been fixed
- fix build with glibc 2.2

* Mon Jun 05 2000 Preston Brown <pbrown@redhat.com>
- ifdef 0 is illegal, changed to if 0.
- work around compiler typdef bug.

* Thu Jun 01 2000 Preston Brown <pbrown@redhat.com>
- start, stop, and restart are functions not switch statements now.
  reduces overhead.
- patch to allow autoconf to choose which user/group to run as

* Wed May 31 2000 Preston Brown <pbrown@redhat.com>
- remove init.d symbolic links.
- remove txt/ps/info versions of the HOWTO from the pkg
- use new fhs paths

* Thu May 25 2000 Nalin Dahyabhai <nalin@redhat.com>
- change free() to krb5_free_data_contents() when patching for Kerberos 5
- detect libcrypto or libk5crypto when looking for Kerberos 5

* Tue May 16 2000 Nalin Dahyabhai <nalin@redhat.com>
- enable Kerberos support
- remove extra defattr in files list
- add --disable-force_localhost to configure invocation
- remove "-o root" at install-time

* Tue May 16 2000 Matt Wilson <msw@redhat.com>
- add Prereq of /sbin/chkconfig
- fix broken conflicting declaration on alpha

* Tue Apr 18 2000 Bernhard Rosenkraenzer <bero@redhat.com>
- initial Red Hat packaging, fix up the spec file

* Mon Sep 13 1999 Patrick Powell <papowell@astart.com>
- resolved problems with symbolic links to /etc/init.d
  files - used the chkconfig facility

* Sat Sep  4 1999 Patrick Powell <papowell@astart.com>
- did ugly things to put the script in the spec file

* Sat Aug 28 1999 Giulio Orsero <giulioo@tiscalinet.it>
- 3.6.8

* Fri Aug 27 1999 Giulio Orsero <giulioo@tiscalinet.it>
- 3.6.7 First RPM build.