%define d_ver	5.0
%define m_ver	5.0
%define t_ver	5.0

Summary:  DHIS server, meant to update DNS records dynamically.
Summary(ja):  DHIS サーバ, DNS のデータを遠隔から動的に変更するツール
Name: dhisd
Version: 5.1
Release: 0vl4
License: Distributable (BSD like)
Group: System Environment/Daemons
URL: http://www.dhis.org/
Source0: ftp://ftp.dhis.org/pub/dhis/%{name}-%{version}.tar.gz
Source1: ftp://ftp.dhis.org/pub/dhis/dhis-dns-engine-%{d_ver}.tar.gz
Source2: ftp://ftp.dhis.org/pub/dhis/dhis-mx-sendmail-engine-%{m_ver}.tar.gz
Source3: ftp://ftp.dhis.org/pub/dhis/dhistools-dns-%{t_ver}.tar.gz
Source4: rc.dhisd
Requires: bind >= 8.2.3 gmp
BuildRequires: bind-devel gmp-devel
Buildroot: %{_tmppath}/%{name}-%{version}-root 

%description
DHIS is a system meant to provide dynamic updates of
DNS records for variable IP address states. The current system
distribution is composed of three modules, dhisd, the DHIS
server, relay, the mail relay server which may or may not be
used, and dhid, the DHIS client.

%description -l ja
DHIS は、DNS のデータを遠隔から動的に変更するツールで、ダイヤルアップ等で
常時接続されていないマシンでも、接続時だけ DNS に登録することで、
ドメイン名を用いたサーバを立ち上げることを可能にするシステムです。
本パッケージは DNS サーバと同一のマシン上にインストールする DHIS サーバです。

(DHIS クライアントは dhid パッケージです。)

%prep
tar xvzf %{SOURCE1}
tar xvzf %{SOURCE2}
tar xvzf %{SOURCE3}

%setup

%build
make RPM_OPT_FLAGS="$RPM_OPT_FLAGS"
cd ../dhis-dns-engine-%{d_ver}
make RPM_OPT_FLAGS="$RPM_OPT_FLAGS"
cp INSTALL ../%{name}-%{version}/INSTALL.dns-engine
cp README ../%{name}-%{version}/README.dns-engine
cd ../dhis-mx-sendmail-engine-%{m_ver}
make RPM_OPT_FLAGS="$RPM_OPT_FLAGS"
cp INSTALL ../%{name}-%{version}/INSTALL.mx-sendmail-engine
cp README ../%{name}-%{version}/README.mx-sendmail-engine
cd ../dhistools-dns-%{t_ver}
make RPM_OPT_FLAGS="$RPM_OPT_FLAGS"
cp README ../%{name}-%{version}/README.dhistools
cd ../%{name}-%{version}

%install
mkdir -p $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr
mkdir -p $RPM_BUILD_ROOT/usr/sbin
install -m 755 dhisd $RPM_BUILD_ROOT/usr/sbin
install -m 755 genkeys $RPM_BUILD_ROOT/usr/sbin
mkdir -p $RPM_BUILD_ROOT/etc/dhis
mkdir -p $RPM_BUILD_ROOT/etc/dhis/bin
mkdir -p $RPM_BUILD_ROOT/etc/dhis/db
mkdir -p $RPM_BUILD_ROOT/etc/dhis/pid
mkdir -p $RPM_BUILD_ROOT/etc/dhis/log
mkdir -p $RPM_BUILD_ROOT/etc/dhis/script
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d
install -m 755 %{SOURCE4} $RPM_BUILD_ROOT/etc/rc.d/init.d/dhisd

cd ../dhis-dns-engine-%{d_ver}
install -m 755 dhis-dns-engine $RPM_BUILD_ROOT/usr/sbin

cd ../dhis-mx-sendmail-engine-%{m_ver}
install -m 755 dhis-mx-sendmail-engine $RPM_BUILD_ROOT/usr/sbin

cd ../dhistools-dns-%{t_ver}
install -m 755 genid $RPM_BUILD_ROOT/usr/sbin
install -m 755 genpass $RPM_BUILD_ROOT/usr/sbin
install -m 755 register-p.sh $RPM_BUILD_ROOT/usr/sbin
install -m 755 register-q.sh $RPM_BUILD_ROOT/usr/sbin

cd ../%{name}-%{version}

%post 
#	set up any missing server dir's
# DIRS=" /etc/dhis /etc/dhis/bin /etc/dhis/pid /etc/dhis/db \
# 	/etc/dhis/log /etc/dhis/script/ " 
# for i in ` echo $DIRS `; do
# if [ ! -d $i ]; then
# 	mkdir $i
# fi
# done
# chmod 700 /etc/dhis /etc/dhis/* 
#	Set up a template database -- leave a prior one alone
TARGET=/etc/dhis/db/dhis.db.sample
cat - << END >> $TARGET
#
#	Sample configuration of the DHIS server
#
1001 {  ; A simple password authenticating host
        hostname        dyn1.example.com
        hostpass        pass1
        service         dns
}

1002 {  ; Another password host
        hostname        dyn2.example.com
        hostpass        pass2
        service         dns
}

1003 {  ; Here's a QRC secure host
        hostname        dyn3.example.com
        authn           34234856347856438756384756384563485638447
        authn           34987469785496774967876795867785967946759
        authn           45375893578937538975389475398457438759348
        authn           43957439857395734895738475395739753948573
        service         dns
        service         mx-sendmail
}
END
TARGET=/etc/dhis/db/services.db.sample
cat - << END >> $TARGET
#
#	Sample configuration of the DHIS server
#
dns     5       /usr/sbin/dhis-dns-engine
mx      5       /usr/sbin/dhis-mx-sendmail-engine
END
#
chmod 600 /etc/dhis/db/dhis.db*
chmod 600 /etc/dhis/db/services.db*
#	Per INSTALL, we add this 
ln -sf /usr/sbin/dhisd                   /etc/dhis/bin
ln -sf /usr/sbin/genkeys                 /etc/dhis/bin
ln -sf /usr/sbin/dhis-dns-engine         /etc/dhis/bin
ln -sf /usr/sbin/dhis-mx-sendmail-engine /etc/dhis/bin
ln -sf /usr/sbin/genid                   /etc/dhis/bin
ln -sf /usr/sbin/genpass                 /etc/dhis/bin
ln -sf /usr/sbin/register-p.sh           /etc/dhis/bin
ln -sf /usr/sbin/register-q.sh           /etc/dhis/bin
#
/sbin/chkconfig --add dhisd

%preun
if [ $1 = 0 ]; then
    /etc/rc.d/init.d/dhisd stop > /dev/null 2>&1
    /sbin/chkconfig --del dhisd
fi

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%doc README COPYRIGHT CONTRIBUTORS INSTALL MODULES
%doc README.dns-engine INSTALL.dns-engine
%doc README.mx-sendmail-engine INSTALL.mx-sendmail-engine
%doc README.dhistools
/usr/sbin/dhisd
/usr/sbin/genkeys
/usr/sbin/dhis-dns-engine
/usr/sbin/dhis-mx-sendmail-engine
/usr/sbin/genid
/usr/sbin/genpass
/usr/sbin/register-p.sh
/usr/sbin/register-q.sh
%attr(0700, root, root) %dir /etc/dhis
%attr(0700, root, root) %dir /etc/dhis/bin
%attr(0700, root, root) %dir /etc/dhis/db
%attr(0700, root, root) %dir /etc/dhis/pid
%attr(0700, root, root) %dir /etc/dhis/log
%attr(0700, root, root) %dir /etc/dhis/script
%config /etc/rc.d/init.d/dhisd


%changelog
* Fri Mar 08 2002 Toru Sagami <sagami@vinelinux.org> 5.1-0vl4
- rebuild on current VineSeed
- initscript marked as config

* Sun Sep 30 2001 KAJIKI Yoshihiro <kajiki@ylug.org> [5.1-0vl3]
- correct file attribute of documents

* Fri Sep 28 2001 KAJIKI Yoshihiro <kajiki@ylug.org> [5.1-0vl1]
- update to 5.1
- correct link mistake in spec file (Sorry!)

* Mon Aug 27 2001 KAJIKI Yoshihiro <kajiki@ylug.org> [5.0-0vl3]
- add engines into files (my mistake)

* Mon Aug 27 2001 KAJIKI Yoshihiro <kajiki@ylug.org> [5.0-0vl2]
- rebuild on VineSeed

* Sun Aug 26 2001 KAJIKI Yoshihiro <kajiki@ylug.org> [5.0-0vl1]
- update to 5.0
- marge dhistools

* Fri Aug 24 2001 KAJIKI Yoshihiro <kajiki@ylug.org> [4.0.2-0vl1]
- rebuild for Vine 2.1.5 based on the Owl River Company's RPM [4.0.2-3]
- modify spec file to rebuild as a common user

* Sun Dec 17 2000 R P Herrold ( herrold@owlriver.com )
- repair a typo in the initial .db setup - thanks
-    to luciano_terra@zipmail.com.br

* Sat Dec 16 2000 R P Herrold ( herrold@owlriver.com )
- conform to a more modern macro set dhisd-4.0.2-2

* Sat Dec 16 2000 R P Herrold ( herrold@owlriver.com )
- Initial build

