##
##  proftpd.spec -- OpenPKG RPM Specification
##  Copyright (c) 2000-2003 Cable & Wireless Deutschland GmbH
##  Copyright (c) 2000-2003 The OpenPKG Project <http://www.openpkg.org/>
##  Copyright (c) 2000-2003 Ralf S. Engelschall <rse@engelschall.com>
##
##  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:         proftpd
Summary:      Professional FTP Daemon
URL:          http://www.proftpd.net/
Vendor:       The ProFTPD Project
Packager:     The OpenPKG Project
Distribution: OpenPKG [BASE]
Group:        FTP
License:      GPL
Version:      1.2.7
Release:      20030103

#   package options
%option       with_pam  no

#   list of sources
Source0:      ftp://ftp.proftpd.net/distrib/source/proftpd-%{version}.tar.bz2
Source1:      proftpd.conf
Source2:      proftpd.msg.goaway
Source3:      proftpd.msg.login
Source4:      rc.proftpd

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20030103, ncurses, make
PreReq:       OpenPKG, openpkg >= 20030103, ncurses
%if "%{with_pam}" == "yes"
BuildPreReq:  PAM
PreReq:       PAM
%endif
AutoReq:      no
AutoReqProv:  no

%description
    ProFTPD grew out of the desire to have a secure and configurable FTP
    server, and out of a significant admiration of the Apache web server.
    There are currently a very limited number of FTP servers running on unix
    (or unix-like) hosts. The most commonly used server is probably wu-ftpd.
    While wu-ftpd provides excellent performance and is generally a good
    product, it lacks numerous features found in newer Win32 FTP servers, and
    has a poor security history. Many people, including the developers who
    work on ProFTPD have spent a great deal of time fixing bugs and hacking
    features into wu-ftpd.  Unfortunately, it quickly became clear that a
    complete redesign was necessary in order to implement the configurability
    and features desired. ProFTPD is not a hack based on any other server,
    it's an independent source tree from the ground up. Click here for a small
    list of some of the sites ProFTPD powers -- many of them handling large
    volumes of traffic on a daily basis.

%prep
    %setup -q

%build
    #   make non-standard "rundir" the same as standard "sysconfdir"
    %{l_shtool} subst \
        -e 's;^\(rundir=@localstatedir@\)/proftpd;\1;' \
        Make.rules.in

    #   configure the ProFTPd source tree
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
%if "%{with_pam}" == "yes"
    CPPFLAGS="%{l_cppflags ncurses} -I`%{l_prefix}/etc/rc --query pam_incdir`" \
    LDFLAGS="%{l_ldflags} -L`%{l_prefix}/etc/rc --query pam_libdir`" \
%else
    CPPFLAGS="%{l_cppflags ncurses}" \
    LDFLAGS="%{l_ldflags}" \
%endif
    ./configure \
        --prefix=%{l_prefix} \
        --sysconfdir=%{l_prefix}/etc/proftpd \
        --localstatedir=%{l_prefix}/var/proftpd \
        --with-modules=mod_ratio:mod_readme \
%if "%{with_pam}" == "yes"
        --enable-pam
%endif

    #   build ProFTPd programs
    %{l_make} %{l_mflags -O}

%install
    rm -rf $RPM_BUILD_ROOT

    #   make sure the "install" procedure does not try
    #   to perform explicit ownership assignments
    %{l_shtool} subst -v \
        -e 's;-o $(INSTALL_USER) -g $(INSTALL_GROUP);;g' \
        -e 's;chown;true;g' \
        Makefile

    #   perform the "install" procedure while redirecting
    #   it to the temporarily install area
    %{l_make} %{l_mflags} \
        install-proftpd install-utils install-man \
        prefix=$RPM_BUILD_ROOT%{l_prefix} \
        sysconfdir=$RPM_BUILD_ROOT%{l_prefix}/etc/proftpd \
        localstatedir=$RPM_BUILD_ROOT%{l_prefix}/var/proftpd \
        rundir=$RPM_BUILD_ROOT%{l_prefix}/var/proftpd

    #   strip installation
    rm -f $RPM_BUILD_ROOT%{l_prefix}/sbin/in.proftpd

    #   install more stuff manually
    %{l_shtool} mkdir -f -p -m 755 $RPM_BUILD_ROOT%{l_prefix}/share/proftpd
    %{l_shtool} install -c -m 644 doc/faq.html \
        $RPM_BUILD_ROOT%{l_prefix}/share/proftpd/faq.html
    %{l_shtool} install -c -m 644 doc/Configuration.html \
        $RPM_BUILD_ROOT%{l_prefix}/share/proftpd/cfg.html

    #   extended installation with own stuff
    l_pam="#"
%if "%{with_pam}" == "yes"
    l_pam=""
%endif
    %{l_shtool} install -c -m 644 \
        -e 's;@l_prefix@;%{l_prefix};g' \
        -e 's;@l_nusr@;%{l_nusr};g' \
        -e 's;@l_ngrp@;%{l_ngrp};g' \
        -e "s;@l_pam@;${l_pam};g" \
        %{SOURCE proftpd.conf} $RPM_BUILD_ROOT%{l_prefix}/etc/proftpd/
    %{l_shtool} install -c -m 644 \
        %{SOURCE proftpd.msg.goaway} \
        %{SOURCE proftpd.msg.login} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/proftpd/
    %{l_shtool} install -c -m 644 \
        %{SOURCE proftpd.msg.login} \
        $RPM_BUILD_ROOT%{l_prefix}/share/proftpd/.msg.login
    %{l_shtool} install -c -m 644 \
        %{SOURCE proftpd.msg.goaway} \
        $RPM_BUILD_ROOT%{l_prefix}/share/proftpd/.msg.goaway
    %{l_shtool} mkdir -f -p -m 755 $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
    %{l_shtool} install -c -m 755 -e 's;@l_prefix@;%{l_prefix};g' \
        %{SOURCE rc.proftpd} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   determine the package ingredients
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/proftpd/proftpd.conf'

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

%post
%if "%{with_pam}" == "yes"
    #   add PAM configuration entry
    if [ $1 -eq 1 ]; then
        $RPM_INSTALL_PREFIX/sbin/pamtool --add --smart --name=proftpd
    fi
%endif

%preun
%if "%{with_pam}" == "yes"
    #   remove PAM configuration entry
    if [ $1 -eq 0 ]; then
        $RPM_INSTALL_PREFIX/sbin/pamtool --remove --smart --name=proftpd
    fi
%endif
    if [ $1 -eq 0 ]; then
        $RPM_INSTALL_PREFIX/etc/rc proftpd stop
        rm -f $RPM_INSTALL_PREFIX/var/proftpd/*.log
        rm -f $RPM_INSTALL_PREFIX/var/proftpd/*.pid
    fi

