##
##  petidomo.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:         petidomo
Summary:      Mailing List Server
URL:          http://www.ossp.org/pkg/tool/petidomo/
Vendor:       Peter Simons
Packager:     The OpenPKG Project
Distribution: OpenPKG [EVAL]
Group:        Mail
License:      GPL
Version:      4.0b1
Release:      20021128

#   list of sources
Source0:      ftp://ftp.ossp.org/pkg/tool/petidomo/petidomo-%{version}.tar.gz
Source1:      etc.petidomo.tar
Source2:      fsl.petidomo

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20020206, fsl, bison, flex
PreReq:       OpenPKG, openpkg >= 20020206, fsl, MTA
AutoReq:      no
AutoReqProv:  no

%description
    Petidomo is a mailing list manager very similar to the popular
    package Majordomo. It handles both list un-/subscription and the
    address expansion of list postings. The actual delivery of postings
    is performed by an MTA like Sendmail.

%prep
    %setup0 -q -c
    %setup1 -q -T -D -a 1

%build
    #   build petidomo
    ( cd petidomo-%{version}
      CC="%{l_cc}" \
      CFLAGS="`%{l_prefix}/bin/fsl-config --all --cflags`" \
      CPPFLAGS="`%{l_prefix}/bin/fsl-config --all --cflags`" \
      LDFLAGS="`%{l_prefix}/bin/fsl-config --all --ldflags`" \
      LIBS="`%{l_prefix}/bin/fsl-config --all --libs`" \
      ./configure \
          --prefix=%{l_prefix} \
          --sysconfdir=%{l_prefix}/etc/petidomo
      %{l_make} %{l_mflags}
    )

%install
    rm -rf $RPM_BUILD_ROOT
    ( cd petidomo-%{version}
      %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
    )
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/libexec/petidomo
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/etc/petidomo
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/var/petidomo
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/var/petidomo \
        $RPM_BUILD_ROOT%{l_prefix}/etc/petidomo \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fsl
    %{l_shtool} install -c -m 644 \
        /dev/null $RPM_BUILD_ROOT%{l_prefix}/var/petidomo/petidomo.log
    %{l_shtool} install -c -m 644 -e 's;@l_prefix@;%{l_prefix};g' \
        %{SOURCE fsl.petidomo} $RPM_BUILD_ROOT%{l_prefix}/etc/fsl/
    ( cd etc.petidomo
      l_hostname=`%{l_shtool} echo -e '%h%d'`
      %{l_shtool} install -c -m - \
          -e "s;@l_hostname@;${l_hostname};g" \
          -e 's;@l_prefix@;%{l_prefix};g' \
          * $RPM_BUILD_ROOT%{l_prefix}/etc/petidomo/
    )
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/petidomo/*' \
        '%attr(6755,%{l_musr},%{l_mgrp}) %{l_prefix}/bin/petidomo' \
        '%config %{l_prefix}/etc/fsl/fsl.petidomo' \
        '%not %dir %{l_prefix}/etc/fsl'

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

%post
    #   add hook into MTA configuration
    if [ ".$1" = .1 ]; then
        aliases_file=`$RPM_INSTALL_PREFIX/etc/rc --query mta_aliases_file`
        update_command=`$RPM_INSTALL_PREFIX/etc/rc --query mta_aliases_update`
        if [ ".$aliases_file" != . ]; then
            ( echo "petidomo:              \"|$RPM_INSTALL_PREFIX/bin/petidomo --mode=listserv\""
              echo "petidomo-approve:      \"|$RPM_INSTALL_PREFIX/bin/petidomo --mode=approve\""
              echo "petidomo-manager:      postmaster"
              echo "owner-owner:           petidomo-manager"
              echo "users:                 \"|$RPM_INSTALL_PREFIX/bin/petidomo --mode=deliver  --listname=users\""
              echo "users-request:         \"|$RPM_INSTALL_PREFIX/bin/petidomo --mode=listserv --listname=users\""
              echo "users-owner:           postmaster"
              echo "owner-users:           users-owner"
            ) |\
            $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
                -a -i "$RPM_INSTALL_PREFIX:petidomo" $aliases_file
        fi
        if [ ".$update_command" != . ]; then
            eval $update_command
        fi
    fi

%postun
    #   remove hook from MTA configuration
    if [ ".$1" = .0 ]; then
        aliases_file=`$RPM_INSTALL_PREFIX/etc/rc --query mta_aliases_file`
        update_command=`$RPM_INSTALL_PREFIX/etc/rc --query mta_aliases_update`
        if [ ".$aliases_file" != . ]; then
            $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
                -r -i "$RPM_INSTALL_PREFIX:petidomo" $aliases_file
        fi
        if [ ".$update_command" != . ]; then
            eval $update_command
        fi
    fi

