Summary: A program for faxing using a Class 1, 2 or 2.0 fax modem.
Name: efax
%define ver 0.9a
%define rel 001114
%define minor b0

Version: %{ver}%{rel}%{minor}
Release: 1%{?_dist_release}
License: GPL
Group: Applications/Communications
Source: http://www.cce.com/efax/download/%{name}-%{ver}-%{rel}.tar.gz
#Source: http://shino.pos.to/linux/%{name}-%{ver}%{rel}%{minor}.tar.gz
Source1: http://shino.pos.to/linux/efax/efax.rc.sample
Source2: http://shino.pos.to/linux/efax/efax.rc.sample.ja
Source3: http://shino.pos.to/linux/efax/printcap.sample
Source4: http://shino.pos.to/linux/fax.html
Source5: http://shino.pos.to/linux/efax.html
Source6: http://shino.pos.to/linux/efax/fax-%{minor}
Source7: http://shino.pos.to/linux/efax/ppxpadduser
Patch1: http://shino.pos.to/linux/efax/efax-0.9-numlines.patch
Patch2: http://shino.pos.to/linux/efax/efax08a-time.patch
Patch5: http://shino.pos.to/linux/efax/efax-0.9-nullptr.patch
Patch6: http://shino.pos.to/linux/efax/efax-0.9a-frlen.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-root

Vendor: Project Vine
Distribution: Vine Linux

#Prefix: /usr
%define lockdir     /var/lock
%define faxdir      /var/spool/fax
%define incomingdir /var/spool/fax/incoming
%define outgoingdir /var/spool/fax/outgoing
%define logdir      /var/log/fax
%define printcap    /etc/printcap
%define printcap2   /etc/printcap.local
%define modemuser   uucp
%define lpuser       lp
%define efaxconf    /etc/efax.rc
%{!?_initrddir:%define _initrddir   /etc/rc.d/init.d}

Url: http://www.cce.com/efax

%description
Efax is a small ANSI C/POSIX program that sends and receives faxes using
any Class 1, 2 or 2.0 fax modem.
This package include pathces bugfixing fax start/stop commands and
tools for fax spooling.
You need to install efax if you want to send faxes and you have a
Class 1, 2 or 2.0 fax modem.

%description -l ja
efax はクラス1, 2 または2.0 fax モデムを使用して fax を送受信するための小さな 
ANSI C/POSIX なプログラムです。
このパッケージにはfax start/stop コマンドのバグフィックスと
スプーリングに便利なパッチと設定が含まれています。
クラス1, 2 または 2.0 fax モデムを使用して fax を送信する場合は efax を
インストールする必要があります。
 
%prep
%setup -q -n %{name}-%{ver}-%{rel}
%patch1 -p1 -b .numlines
%patch2 -p1 -b .time
%patch5 -p1 -b .nullptr
%patch6 -p0 -b .frlen
%__cp %{SOURCE1} ./
%__cp %{SOURCE2} ./
%__cp %{SOURCE3} ./
%__cp %{SOURCE4} ./
%__cp %{SOURCE5} ./
%__mv fax fax.org
%__cp %{SOURCE6} ./fax
%__cp %{SOURCE7} ./

%build
make RPM_OPT_FLAGS="-ansi $RPM_OPT_FLAGS"

%install
%__rm -rf $RPM_BUILD_ROOT
%__install -d -m 755 $RPM_BUILD_ROOT%{_bindir}
%__install -d -m 755 $RPM_BUILD_ROOT%{_mandir}/man1
%__install -d -m 775 $RPM_BUILD_ROOT%{faxdir}
%__install -d -m 777 $RPM_BUILD_ROOT%{logdir}
%__install -d -m 775 $RPM_BUILD_ROOT%{incomingdir}
%__install -d -m 770 $RPM_BUILD_ROOT%{outgoingdir}
touch  $RPM_BUILD_ROOT%{outgoingdir}/lock
chmod 644  $RPM_BUILD_ROOT%{outgoingdir}/lock
%__install -d -m 755 $RPM_BUILD_ROOT/etc
%__cp efax.rc.sample $RPM_BUILD_ROOT/etc/efax.rc

#%#makeinstall
make BINDIR=$RPM_BUILD_ROOT%{_bindir} MANDIR=$RPM_BUILD_ROOT%{_mandir} install

cd $RPM_BUILD_ROOT%{_bindir}
ln -s fax faxlpr

%clean
%__rm -rf $RPM_BUILD_ROOT
#rm -rf $RPM_BUILD_DIR/%{name}-%{version}-%{rel}

%pre
(id %{lpuser} > /dev/null 2>&1 ) || adduser -d /var/%{lpuser}  -c %{lpuser} %{lpuser}
:

%post
    [ -d %{lockdir}  ] || mkdir -p  %{lockdir}
    chmod 777 %{lockdir}

if [ -w /etc/inittab ] ; then
    grep -q "/bin/fax answer" /etc/inittab || \
    echo -e "# Uncomment next line to enable efax auto answer\n#s1:345:respawn:/bin/sh /usr/bin/fax answer" \
        >> /etc/inittab
fi

#HEADER="##PRINTTOOL3## LOCAL"
PRINTCAP=%{printcap}
[ -w %{printcap2} ] && PRINTCAP=%{printcap2}
if  [ -w "$PRINTCAP" ] && ! grep -q "^fax:" $PRINTCAP ; then
    tail -n 7 %{_docdir}/%{name}-%{version}/printcap.sample >> $PRINTCAP
#cat >> $PRINTCAP << EOF
#$HEADER 
#fax:\
#	:sd=/var/spool/fax/outgoing:\
#	:mx#0:\
#	:sh:\
#	:lp=/dev/null:\
#	:if=/usr/bin/faxlpr:
#EOF
    # restart lpd
    if (ps ax | grep -v grep | grep -q lpd) ; then
        [ -x %{_initrddir}/lpd ] && %{_initrddir}/lpd restart
    fi
fi
:

%postun
if [ $1 -eq 0 ] ; then
  # Delete fax entry from printcap
  PRINTCAP=%{printcap}
  [ -w %{printcap2} ] && PRINTCAP=%{printcap2}
  FILE=$PRINTCAP
  BEGIN=$(cat -n $FILE | grep 'fax:' | sed -e 's/^[ ]*//' -e 's/[^0-9].*//')
  END=$(cat -n $FILE | grep ':if=/usr/bin/faxlpr:' | sed -e 's/^[ ]*//' -e 's/[^0-9].*//')
  LINES=$(wc -l $FILE | sed -e 's/^[ ]*//' -e 's/[^0-9].*//')
  if [ -n "$BEGIN" -a -n "$END" -a -n "$LINES" ];then
     HEAD=$(expr $BEGIN - 2)
     TAIL=$(expr $LINES - $END)
     if [ $HEAD -ge 0 ];then
       rm -f $FILE.new
       (head -n $HEAD $FILE; tail -n $TAIL $FILE) > $FILE.new && \
       (mv -f $FILE $FILE.bak; mv $FILE.new $FILE)
       # restart lpd
       if (ps ax | grep -v grep | grep -q lpd) ; then
            [ -x %{_initrddir}/lpd ] && %{_initrddir}/lpd restart
       fi
     fi
  fi
fi
:

%files
%defattr(-,root,root)
%doc README COPYING *.sample* *.html ppxpadduser
%config %{_bindir}/fax
%config(missingok, noreplace) %{efaxconf} 
%{_bindir}/efax
%{_bindir}/efix
%{_bindir}/faxlpr
%{_mandir}/man1/fax.1*
%{_mandir}/man1/efax.1*
%{_mandir}/man1/efix.1*
%attr(-,root,%{modemuser}) %dir %{faxdir}
%attr(-,root,%{modemuser}) %{logdir}
%attr(-,root,%{modemuser}) %{incomingdir}
%attr(-,%{lpuser},%{lpuser}) %{outgoingdir}


%changelog
* Mon Sep 22 2008 Shu KONNO <owa@bg.wakwak.com> 0.9a001114b0-1vl5
- applied new versioning policy, spec in utf-8

* Sun Jul 30 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.9a001114b0-0vl2
- rebuilt for VineSeed
- s/Copyright/License/

* Mon Feb 28 2005 Masaki SHINOMIYA <shino@pos.to> 0.9a001114b0-0vl1
- use fax-b0, bugfix in handling '-m' option
- bugfix in function faxmail by Marc Ferraton <mferrato@ogm-techno.org>
- frlen.patch, REMID in fax both informed by Steven Doerfler <steven@lugaru.com>
- post and postun scripts, (_initrddir)
- accept '_054' as ','(comma)
- noreplace efax.rc
- build on Vine Linux 3.1

* Sun Mar 31 2002 Jun Nishii <jun@vinelinux.org> 0.9a001114a7-0vl2
- rebuild for Vine Linux 2.5

* Wed Jan 30 2002 Masaki SHINOMIYA <shino@pos.to> 0.9a001114a7-0vl1 for Vine 2.1
* Wed Jan 30 2002 Masaki SHINOMIYA <shino@pos.to> 0.9a001114a7-1
- avoid 'bad units' error in some european locale

* Sun Jan 6 2002 Masaki SHINOMIYA <shino@pos.to> 0.9a001114a6-0vl1 for Vine 2.1
* Sun Jan 6 2002 Masaki SHINOMIYA <shino@pos.to> 0.9a001114a6-1
- accept escape sequence, '_043'as'#', '_052'as'*'
- change the release number
- use macros

* Sat Dec 15 2001 Masaki SHINOMIYA <shino@pos.to> 0.9a001114-0a5
- spec for rpm -tb
- faxlpr to work with LPRng
- patches taken from RHL efax-0.9-9

* Sun Oct 7 2001 Masaki SHINOMIYA <shino@pos.to> 0.9a001114-0a4
- do not specify any distributions
* Sun Oct 7 2001 Masaki SHINOMIYA <shino@pos.to> 0.9a001114-0vl4
- efax-spooling.patch introducing INCOMING and OUTGOING
- symlink of faxlpr and efax.rc.sampl to use spooling
- postscript including chmod some directories to 777 to enable pooling
- CLASSINIT in efax.rc.sample
- descriptions
- html documents written by me

* Mon Aug 20 2001 Masaki SHINOMIYA <shino@pos.to> 0.9a001114-0vl3
- efax-answer.patch to fix some problems in auto answering function
- efax.rc to be a config

* Sat Jun 20 2001 Masaki SHINOMIYA <shino@pos.to> 0.9a001114-0vl2
- fixed bugs in postscript
- efax.rc.sample to be installed in /usr/doc directory

* Sat Jun 16 2001 Masaki SHINOMIYA <shino@pos.to> 0.9a001114-0vl1
- rename for VinePlus package

* Wed Jun 13 2001 Masaki SHINOMIYA <shino@pos.to> 0.9a-001114c
- create /etc/efax.rc if not exists
- /dev/modem is now default

* Wed Jun 6 2001 Masaki SHINOMIYA <shino@pos.to> 0.9a-001114b
- add log directory  /var/log/fax

* Tue May 29 2001 Masaki SHINOMIYA <shino@pos.to> 0.9a-001114a
- post-install-script, efax.rc.sample

* Thu May 23 2001 Masaki SHINOMIYA <shino@pos.to> 0.9a-001114

* Fri Oct 13 2000 MACHINO, Satoshi <machino@vinelinux.org> 0.9-1vl2
- fixed in %files for brp-redhat scripts

* Tue Jun 29 1999 Cristian Gafton <gafton@redhat.com>
- updated to 0.9 (#3808)

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

* Wed Feb 24 1999 Preston Brown <pbrown@redhat.com>
- Injected new description and group.

* Tue Feb 02 1999 Preston Brown <pbrown@redhat.com>
- patch to fix null ptr dereference
- added -ansi flag; fixes efix problem (produced bad tiff files)

* Fri Dec 18 1998 Preston Brown <pbrown@redhat.com>
- bumped spec number for initial rh 6.0 build

* Tue Aug 11 1998 Jeff Johnson <jbj@redhat.com>
- build root

* Mon Apr 27 1998 Prospector System <bugs@redhat.com>
- translations modified for de, fr, tr

* Wed Oct 22 1997 Michael Fulbright <msf@redhat.com>
- cleaned spec file to new standard, confirmed package is up to date

* Tue Mar 25 1997 Erik Troan <ewt@redhat.com>
- Added efax-08a-64bit.patch from David Mosberger
