Summary: Server for accessing CD-ROM books with NDTP
Summary(ja): NDTP を用いた CD-ROM 書籍をアクセスするためのサーバ
Name: ndtpd
Version: 3.1.5
Release: 5%{?_dist_release}
License: GPLv2
Group: Applications/Services
URL: http://www.sra.co.jp/people/m-kasahr/ndtpd/

Source: ftp://ftp.sra.co.jp/pub/net/ndtp/ndtpd/%{name}-%{version}.tar.gz
Source1: ndtpd

BuildRoot: %{_tmppath}/%{name}-%{version}-root
Requires: eb >= 3.3
Requires: rsyslog
BuildRequires: eb-devel >= 3.3
BuildRequires: zlib-devel
BuildRequires: nkf
Requires(pre): grep shadow-utils
Requires(post): grep /sbin/install-info
Requires(preun): grep /sbin/install-info /sbin/chkconfig
Requires(postun): grep shadow-utils

Distribution: Vine Linux
Vendor: Project Vine

%define ndtpdconfdir %{_sysconfdir}/ndtpd

%description
NDTPD is a server for accessing CD-ROM books with NDTP (Network
Dictionary Transfer Protocol) on TCP.  You can replace dserver with
NDTPD.  NDTPD can run on UNIX derived systems.  It supports to access
CD-ROM books of EB, EBG, EBXA, EBXA-C, S-EBXA and EPWING formats.
CD-ROM books of those formats are popular in Japan.  Since CD-ROM
books themseves are stands on the ISO 9660 format, you can mount the
discs by the same way as other ISO 9660 discs.

%description -l ja
NDTPD は TCP 上の NDTP (Network Disctionary Transfer Protocol) という
プロトコルを用いて、CD-ROM 書籍へのアクセスを行うサーバです。
dserver は NDTPD に置き換えることが可能です。

NDTPD は UNIX 系 OS のシステム上で動作させることができます。EB, EBG,
EBXA, EBXA-C, S-EBXA および EPWING 形式の CD-ROM 書籍に対応しています。
これらの形式の CD-ROM 書籍は、日本で一般的に使われています。CD-ROM 書籍
自体はISO 9660 形式になっていますので、他の ISO 9660 形式と同じ要領で
マウントすることができます。

%prep
%setup -q

mv README-ja README-ja.old
mv UPGRADE-ja UPGRADE-ja.old
nkf -w README-ja.old > README-ja
nkf -w UPGRADE-ja.old > UPGRADE-ja

%build
./configure --prefix=%{_prefix} \
    --sysconfdir=%{ndtpdconfdir} \
    --localstatedir=%{_localstatedir} \
    --infodir=%{_infodir} \
    --with-eb-conf=%{_sysconfdir}/eb.conf \
    --with-zlib
make all check info #dvi

%install
rm -rf %{buildroot}
make DESTDIR=%{buildroot} install
mkdir -p %{buildroot}%{_localstatedir}/ndtpd/log
install -m 755 -D %{SOURCE1} %{buildroot}%{_initdir}/ndtpd
rm -f %{buildroot}%{_infodir}/dir

cd %{buildroot}%{ndtpdconfdir}
cat ndtpd.conf.sample | sed -e 's|/usr/var|%{_localstatedir}|g' > ndtpd~
[ -s ndtpd~ ] && (rm -f ndtpd.conf.sample; mv ndtpd~ ndtpd.conf.sample)

%clean
rm -rf %{buildroot}

%pre
if [ `grep ndtpgrp %{_sysconfdir}/group | wc -l` = 0 ]; then
    %{_sbindir}/groupadd ndtpgrp
fi
if [ `grep ndtpuser %{_sysconfdir}/passwd | wc -l` = 0 ]; then
    %{_sbindir}/useradd -M -r -g ndtpgrp -d %{_localstatedir}/ndtpd \
     -s "" -c "ndtpd" ndtpuser || :
fi

%post
if [ -x /sbin/install-info ]; then
    for i in $(ls %{_infodir}/ndtpd*); do
	/sbin/install-info --info-dir=%{_infodir} $i
    done
fi
if [ -x /bin/grep -a -f /etc/services ] ; then
    grep -q "^ndtp" /etc/services || \
	echo "ndtp          2010/tcp       # added by ndtpd RPM" >>  /etc/services
fi

if [ -x /bin/grep -a -f /etc/rsyslog.conf ] ; then
    grep -q "ndtpd" /etc/rsyslog.conf || \
	echo "local0.info     %{_localstatedir}/ndtpd/log/ndtpd.log" >>  /etc/rsyslog.conf
    kill -HUP `/sbin/pidof rsyslogd`
fi

if [ -x /bin/grep -a -f /etc/inetd.conf ] ; then
    grep -q "ndtp" /etc/inetd.conf || \
	echo "#ndtp    stream  tcp     nowait  root    /usr/sbin/ndtpd   ndtpd --inetd" >>  /etc/inetd.conf
fi
#kill -HUP `/sbin/pidof inetd`
if [ -x /bin/grep -a -f /etc/hosts.allow ] ; then
    grep -q "ndtp" /etc/hosts.allow || \
	echo "ndtp: 127.0.0.1 : allow" >>  /etc/hosts.allow
fi

#[ -x /sbin/chkconfig -a -x %{_initdir}/ndtpd ] && \
#/sbin/chkconfig --add ndtpd

if [ -f %{_localstatedir}/ndtpd/ndtpd.pid -a -x %{_initdir}/ndtpd ]; then
        %{_initdir}/ndtpd restart
fi

%preun
if [ $1 = 0 ]; then
  if [ -x /sbin/install-info ]; then
      for i in $(ls %{_infodir}/ndtpd*); do
	  /sbin/install-info --delete --info-dir=%{_infodir} $i
      done
  fi
  [ -x /sbin/chkconfig -a -x %{_initdir}/ndtpd ] && \
      /sbin/chkconfig --del ndtpd
  ls %{_localstatedir}/ndtpd/log/* &> /dev/null && \
      rm -f %{_localstatedir}/ndtpd/log/*

  if [ -x /bin/grep -a -f /etc/rsyslog.conf ] ; then
      if grep -q "ndtpd" /etc/rsyslog.conf ; then
          grep -v "ndtpd" /etc/rsyslog.conf > /etc/rsyslog.new && \
              mv -f /etc/rsyslog.new /etc/rsyslog.conf
          kill -HUP `/sbin/pidof rsyslogd`
      fi
  fi

  if [ -x /bin/grep -a -f /etc/inetd.conf ] ; then
      if grep -q "^ndtp" /etc/inetd.conf ; then
           grep -v "ndtp" /etc/inetd.conf > /etc/inetd.new && \
           mv -f /etc/inetd.new /etc/inetd.conf
           kill -HUP `/sbin/pidof inetd`
      fi
  fi

  if [ -x /bin/grep -a -f /etc/hosts.allow ] ; then
      if grep -q "ndtp" /etc/hosts.allow ; then
           grep -v "ndtp" /etc/hosts.allow > /etc/hosts.allow.new && \
           mv -f /etc/hosts.allow.new /etc/hosts.allow
      fi
  fi

  if [ -f %{_localstatedir}/ndtpd/ndtpd.pid -a -x %{_initdir}/ndtpd ]; then
                %{_initdir}/ndtpd stop
  fi
  rm -f %{_localstatedir}/ndtpd/*.lock

fi
:

%postun
if [ $1 = 0 ]; then
   if [ `grep ndtpuser %{_sysconfdir}/passwd | wc -l` = 1 ]; then
      %{_sbindir}/userdel ndtpuser
   fi
   if [ `grep ndtpgrp %{_sysconfdir}/group | wc -l` = 1 ]; then
      %{_sbindir}/groupdel ndtpgrp
   fi
fi

%files
%defattr(-,root,root)
%doc AUTHORS COPYING ChangeLog* NEWS README README-ja UPGRADE UPGRADE-ja
%config %{ndtpdconfdir}/ndtpd.conf.sample
%{_infodir}/ndtpd-ja.info*
%{_infodir}/ndtpd.info*
%{_libexecdir}/ndtpstat
%{_sbindir}/ndtpcheck
%{_sbindir}/ndtpcontrol
%{_sbindir}/ndtpd
%{_sbindir}/ndtpdaily
%{_sbindir}/ndtpupgrade
%{_initdir}/ndtpd
%attr(-,ndtpuser,ndtpgrp) %{_localstatedir}/ndtpd

%changelog
* Thu Jan 29 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 3.1.5-5
- rebuilt on current VineSeed
- moved to Applications/Services Group
- fixed README-ja, UPGRADE-ja encoding
- updated %%post and %%preun script for rsyslog
- added Requires: rsyslog

* Sun Jan  2 2011 IWAI, Masaharu <iwai@alib.jp> 3.1.5-4
- build with eb 4.4.3

* Wed Jul 22 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.1.5-3
- rebuilt with eb-4.4.1

* Fri Oct 10 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.1.5-2vl5
- fixed release

* Wed Oct 08 2008 Shu KONNO <owa@bg.wakwak.com> 3.1.5-1vl5
- applied new versioning policy, spec in utf-8

* Thu Dec 13 2007 IWAI, Masaharu <iwai@alib.jp> 3.1.5-0vl2
- rebuild with eb-4.3

* Sun Oct 3 2004 Kunio Murasawa <murasawa@fa2.so-net.ne.jp> 3.1.5-0vl1
- new upstream release
- changed Copyright to License
- removed define _sysconfdir, _initdir, _localstatdir
- fixed Requires: eb >= 3.3
- fixed Group: System Environment/Daemons
- added configure --infodir
- removed rm info-[1-2]* in install section

* Tue Sep 24 2002 Masaki Shinomiya <shino@pos.to> 3.1.3-0vl3
- merge Vine-2.5 Plus's Spec file by Kyoichiro Suda <sudakyo@fat.coara.or.jp>
- services, inetd.conf, syslog.conf, ndtpd.conf.sample, post, preun

* Sat Jul  6 2002 IWAI Masaharu <iwai@alib.jp> 3.1.3-0vl2
- update to 3.1.3 for VineSeed Plus
- merged 3.1.3-0vl1 for Vine-2.5 Plus's Spec file
  - added startup script %%{SOURCE1}
  - fixed Distribution and Vendor tags
  - 3.1.3-0vl1 Changelog
      * Tue Jun 11 2002 Satoshi Tanaka <tnim@mint.freemail.ne.jp>
      - Update version 3.1.3 for the Vine Linux 2.x

      * Tue Mar 12 2002 Satoshi Tanaka <tnim@mint.freemail.ne.jp>
      - Update version 3.1.1 for the Vine Linux 2.1.5

* Thu Nov 15 2001 Tomoya TAKA <taka@vinelinux.org> 3.0.2-0vl1
- update to 3.0.2
- add Requires: eb, zlib and BuildPrereq: zlib-devel
- fix spec files, use rpm macros

* Fri Jul  6 2001 UECHI Yasumasa <uh@u.dhis.portside.net>
-3.0.1-0vl1
- version up to 3.0.1
- add user ndtpuser, group ndtpgrp

* Sat Jun 23 2001 Tomoya TAKA <tomoya@olive.plala.or.jp>
- 3.0-0vl2
- add PreReq: /sbin/install-info, handle info pages in %%post and %%preun

* Fri Jun 22 2001 UECHI Yasumasa <uh@u.dhis.portside.net>
- 3.0-0vl1
- version up to 3.0
- remove EB library from this pkg

* Wed Jun 14 2000 Masaki Kawamura <kawamura@ic.sci.yamaguchi-u.ac.jp>
- add Provides: eb == 2.3.7, eb-devel == 2.3.7

* Wed Apr 26 2000 Masaki Kawamura <kawamura@ic.sci.yamaguchi-u.ac.jp>
- Update version 2.3.7 for the Vine Linux 2.0

* Wed Dec  9 1998 ZUKERAN, shin <shin@ryukyu.ad.jp>
- fix -version-info parameter with pje.patch.
- fix ndtpd.init
