##
##  djbdns.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_djbdns 1.05
%define       V_manual 20021211

#   package information
Name:         djbdns
Summary:      Collection of Domain Name System tools
URL:          http://cr.yp.to/djbdns.html
Vendor:       D. J. Berstein
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        DNS
License:      GPL
Version:      %{V_djbdns}
Release:      20080101

#   list of sources
Source0:      http://cr.yp.to/djbdns/djbdns-%{V_djbdns}.tar.gz
Source1:      http://smarden.org/pape/djb/manpages/djbdns-%{V_djbdns}-man-%{V_manual}.tar.gz
Source2:      rc.djbdns
Source3:      djbdnssetup
Source4:      djbdnsrunsvc
Source5:      dnsroots.global
Patch0:       djbdns.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101

%description
    djbdns is a collection of Domain Name System tools.

%track
    prog djbdns = {
        version   = %{version}
        url       = http://cr.yp.to/djbdns/install.html
        regex     = djbdns-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %setup -q -T -D -a 1
    %patch -p0

%build
    echo %{l_cc} %{l_cppflags} >conf-cc
    echo %{l_cc} %{l_ldflags} >conf-ld
    echo %{l_prefix} >conf-home
    %{l_make} %{l_mflags -O}

%install
    %{l_shtool} mkdir -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/djbdns \
        $RPM_BUILD_ROOT%{l_prefix}/var/djbdns \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/djbdns/bin \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man5 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8
    for f in \
        axfr-get cachetest dnsfilter dnsip dnsipq dnsmx dnsname \
        dnsq dnsqr dnstrace dnstxt pickdns-data random-ip \
        rbldns-data tinydns-data tinydns-edit tinydns-get ; do
        %{l_shtool} install -c -s -m 755 \
            $f \
            $RPM_BUILD_ROOT%{l_prefix}/bin/
    done
    for f in \
        dnstracesort ; do
            %{l_shtool} install -c -m 755 \
                $f \
                $RPM_BUILD_ROOT%{l_prefix}/bin/
    done
    for f in \
        axfrdns-conf dnscache-conf pickdns-conf rbldns-conf \
        tinydns-conf walldns-conf ; do
        %{l_shtool} install -c -s -m 755 \
            $f \
            $RPM_BUILD_ROOT%{l_prefix}/sbin/
    done
    for f in \
        axfrdns dnscache pickdns rbldns tinydns walldns ; do
        %{l_shtool} install -c -s -m 755 \
            $f \
            $RPM_BUILD_ROOT%{l_prefix}/libexec/djbdns/bin/
    done
    %{l_shtool} install -c -m 644 \
        %{SOURCE dnsroots.global} $RPM_BUILD_ROOT%{l_prefix}/etc/djbdns/
    for i in 1 5 8; do
        for f in djbdns-man/*.$i; do
            %{l_shtool} install -c -m 644 \
                $f $RPM_BUILD_ROOT%{l_prefix}/man/man$i/
        done
    done
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.djbdns} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE djbdnssetup} \
        $RPM_BUILD_ROOT%{l_prefix}/sbin/
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE djbdnsrunsvc} \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/djbdns/bin/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%attr(0700,%{l_susr},%{l_sgrp}) %{l_prefix}/sbin/djbdnssetup'

%files -f files

%clean

%post
    #   after upgrade, restart service
    [ $1 -eq 2 ] || exit 0
    eval `%{l_rc} djbdns status 2>/dev/null`
    [ ".$djbdns_active" = .yes ] && %{l_rc} djbdns restart
    exit 0

%preun
    [ $1 -eq 0 ] && $RPM_INSTALL_PREFIX/bin/openpkg rc djbdns stop

    #   before erase, stop service
    [ $1 -eq 0 ] || exit 0
    %{l_rc} djbdns stop 2>/dev/null
    exit 0

