##
##  xinetd.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 information
Name:         xinetd
Summary:      Extended Internet Daemon
URL:          http://www.xinetd.org/
Vendor:       Panos
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Networking
License:      GPL
Version:      2.3.15
Release:      20130116

#   list of sources
Source0:      http://www.xinetd.org/xinetd-%{version}.tar.gz
Source1:      xinetd.conf
Source2:      rc.xinetd

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

%description
    xinetd is a secure replacement for the standard Unix service inetd(8).

%track
    prog xinetd = {
        version   = %{version}
        url       = http://www.xinetd.org/
        regex     = xinetd-(__VER__)\.tar\.gz
    }

%prep
    %setup -q

%build
    #   configure program
    %{l_shtool} subst \
        -e 's;/etc/xinetd.conf;%{l_prefix}/etc/xinetd/xinetd.conf;' \
        -e 's;/var/run/xinetd.dump;%{l_prefix}/var/xinetd/xinetd.dump;' \
        xinetd/xconfig.h
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    ./configure \
        --prefix=%{l_prefix} \
        --with-loadavg \
        --without-inet6

    #   build program
    %{l_make} %{l_mflags}

%install
    #   install program
    %{l_make} %{l_mflags} install \
        prefix=$RPM_BUILD_ROOT%{l_prefix} \
        exec_prefix=$RPM_BUILD_ROOT%{l_prefix}

    #   post-adjust installation
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    mv  $RPM_BUILD_ROOT%{l_prefix}/sbin/xconv.pl \
        $RPM_BUILD_ROOT%{l_prefix}/sbin/xconv
    %{l_shtool} subst \
        -e 's;/usr/bin/perl;%{l_prefix}/bin/perl;' \
        $RPM_BUILD_ROOT%{l_prefix}/sbin/xconv
    mv  $RPM_BUILD_ROOT%{l_prefix}/man/man8/xconv.pl.8 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8/xconv.8

    #   create additional directories
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/xinetd/xinetd.d \
        $RPM_BUILD_ROOT%{l_prefix}/var/xinetd

    #   install default configuration and run-command script
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE xinetd.conf} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/xinetd/
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.xinetd} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/xinetd/xinetd.conf'

%files -f files

%clean

%post
    #   after upgrade, restart service
    if [ $1 -eq 2 ]; then
        %{l_rc} xinetd restart || true
    fi

%preun
    #   before erase, stop service and remove temporary files
    if [ $1 -eq 0 ]; then
        %{l_rc} xinetd stop >/dev/null 2>&1 || true
        rm -f $RPM_INSTALL_PREFIX/var/xinetd/* >/dev/null 2>&1 || true
    fi

