##
##  majordomo.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:         majordomo
Summary:      Mailing List Manager
URL:          http://www.greatcircle.com/majordomo/
Vendor:       Great Circle Associates
Packager:     The OpenPKG Project
Distribution: OpenPKG [EVAL]
Group:        Mail
License:      Majordomo License Agreement
Version:      1.94.5
Release:      20021219

#   list of sources
Source0:      http://www.greatcircle.com/majordomo/%{version}/majordomo-%{version}.tar.gz
Source1:      users.config
Patch0:       majordomo.patch

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20020206, perl, gcc
PreReq:       OpenPKG, openpkg >= 20020206, perl, bash, MTA
AutoReq:      no
AutoReqProv:  no

%description
    Majordomo is a program which automates the management of Internet
    mailing lists. Commands are sent to Majordomo via electronic mail
    to handle all aspects of list maintenance. Once a list is set
    up, virtually all operations can be performed remotely by email,
    requiring no intervention upon the postmaster of the list site.

%prep
    %setup -q
    %patch -p0

%build
    %{l_shtool} subst \
        -e 's;^\(PERL =\).*;\1 %{l_prefix}/bin/perl;' \
        -e 's;^\(CC =\).*;\1 %{l_prefix}/bin/gcc;' \
        -e 's;^\(W_HOME =\).*;\1 %{l_prefix}/libexec/majordomo;' \
        -e 's;^\(W_MAJORDOMO_CF =\).*;\1 %{l_prefix}/etc/majordomo/majordomo.cf;' \
        -e 's;^\(MAN =\).*;\1 %{l_prefix}/man;' \
        -e 's;^\(W_USER =\).*;\1 %{l_ruid};' \
        -e 's;^\(W_GROUP =\).*;\1 %{l_rgid};' \
        -e 's;^\(W_SHELL =\).*;\1 %{l_prefix}/bin/bash;' \
        -e 's;^\(W_PATH =\).*;\1 %{l_prefix}/bin:/bin:/usr/bin;' \
        -e 's;^\(TMPDIR =\).*;\1 %{l_prefix}/var/majordomo/tmp;' \
        Makefile
    %{l_shtool} subst \
        -e 's|"Majordomo-Owner|"majordomo-owner|' \
        -e 's|"Majordomo|"majordomo|' \
        -e 's|\(\$homedir *= *"\)[^"]*\(";\)|\1%{l_prefix}/libexec/majordomo\2|' \
        -e 's|\(\$listdir *= *"\)[^"]*\(";\)|\1%{l_prefix}/var/majordomo/list\2|' \
        -e 's|\(\$log *= *"\)[^"]*\(";\)|\1%{l_prefix}/var/majordomo/log/majordomo.log\2|' \
        -e 's|\(\$sendmail_command *= *"\)[^"]*\(";\)|\1%{l_prefix}/sbin/sendmail\2|' \
        -e 's|\(\$whereami *= *"\)[^"]*\(";\)|\1example.com\2|' \
        -e 's|"/usr/tmp";|"%{l_prefix}/var/majordomo/tmp";|' \
        sample.cf
    %{l_shtool} subst \
        -e 's;/usr/lib/sendmail;%{l_prefix}/sbin/sendmail;g' \
        -e 's;/usr/sbin/sendmail;%{l_prefix}/sbin/sendmail;g' \
        `find . -type f -print`
    %{l_make} %{l_mflags -O} wrapper

%install
    rm -rf $RPM_BUILD_ROOT
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/majordomo \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/majordomo \
        $RPM_BUILD_ROOT%{l_prefix}/var/majordomo/tmp \
        $RPM_BUILD_ROOT%{l_prefix}/var/majordomo/log \
        $RPM_BUILD_ROOT%{l_prefix}/var/majordomo/list
    %{l_make} %{l_mflags} install install-wrapper \
        W_HOME=$RPM_BUILD_ROOT%{l_prefix}/libexec/majordomo \
        W_MAJORDOMO_CF=$RPM_BUILD_ROOT%{l_prefix}/etc/majordomo/majordomo.cf \
        MAN=$RPM_BUILD_ROOT%{l_prefix}/man \
        TMPDIR=$RPM_BUILD_ROOT%{l_prefix}/var/majordomo/tmp \
        W_USER=`%{l_shtool} echo -e %u` \
        W_GROUP=`%{l_shtool} echo -e %g` \
        WRAPPER_OWNER=`%{l_shtool} echo -e %u` \
        WRAPPER_GROUP=`%{l_shtool} echo -e %g`
    mv $RPM_BUILD_ROOT%{l_prefix}/libexec/majordomo/majordomo.cf \
       $RPM_BUILD_ROOT%{l_prefix}/etc/majordomo/
    rm -f $RPM_BUILD_ROOT%{l_prefix}/libexec/majordomo/sample.cf
    mv $RPM_BUILD_ROOT%{l_prefix}/libexec/majordomo/archive2.pl \
       $RPM_BUILD_ROOT%{l_prefix}/libexec/majordomo/archive
    mv $RPM_BUILD_ROOT%{l_prefix}/libexec/majordomo/wrapper \
       $RPM_BUILD_ROOT%{l_prefix}/bin/majordomo-wrapper
    mv $RPM_BUILD_ROOT%{l_prefix}/libexec/majordomo/bin/approve \
       $RPM_BUILD_ROOT%{l_prefix}/bin/majordomo-approve
    mv $RPM_BUILD_ROOT%{l_prefix}/libexec/majordomo/bin/bounce \
       $RPM_BUILD_ROOT%{l_prefix}/bin/majordomo-bounce
    mv $RPM_BUILD_ROOT%{l_prefix}/libexec/majordomo/bin/medit \
       $RPM_BUILD_ROOT%{l_prefix}/bin/majordomo-medit
    for man in bounce-remind digest approve bounce resend; do
        mv $RPM_BUILD_ROOT%{l_prefix}/man/man1/$man.1 \
           $RPM_BUILD_ROOT%{l_prefix}/man/man1/majordomo-$man.1
    done
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/libexec/majordomo/bin
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/libexec/majordomo/Tools
    %{l_shtool} install -c -m 600 \
        %{SOURCE users.config} \
        $RPM_BUILD_ROOT%{l_prefix}/var/majordomo/list/
    echo "User Support Mailing List <users@example.com>" >users.info
    %{l_shtool} install -c -m 600 \
        users.info $RPM_BUILD_ROOT%{l_prefix}/var/majordomo/list/users.info
    %{l_shtool} install -c -m 600 \
        /dev/null $RPM_BUILD_ROOT%{l_prefix}/var/majordomo/list/users.aliases
    %{l_shtool} install -c -m 600 \
        /dev/null $RPM_BUILD_ROOT%{l_prefix}/var/majordomo/list/users.archive
    %{l_shtool} install -c -m 600 \
        /dev/null $RPM_BUILD_ROOT%{l_prefix}/var/majordomo/list/users
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%attr(4755,%{l_susr},%{l_rgrp}) %{l_prefix}/bin/majordomo-wrapper' \
        '%config %{l_prefix}/etc/majordomo/majordomo.cf' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/majordomo/list' \
        '%config %attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/majordomo/list/*' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/majordomo/log' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/majordomo/tmp'

%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 "#    Majordomo Common Interface"
              echo "majordomo:             \"|$RPM_INSTALL_PREFIX/bin/majordomo-wrapper majordomo\""
              echo "majordomo-master:      nobody"
              echo "majordomo-owner:       majordomo-master"
              echo "owner-majordomo:       majordomo-master"
              echo "owner-owner:           majordomo-master"
              echo ""
              echo "#    Majordomo Mailing List"
              echo "users:                 \"|$RPM_INSTALL_PREFIX/bin/majordomo-wrapper resend -l users -h example.com users-L\""
              echo "users-L:               :include:$RPM_INSTALL_PREFIX/var/majordomo/list/users,"
              echo "                       \"|$RPM_INSTALL_PREFIX/bin/majordomo-wrapper archive -a -f $RPM_INSTALL_PREFIX/var/majordomo/list/users.archive\""
              echo "users-request:         \"|$RPM_INSTALL_PREFIX/bin/majordomo-wrapper request-answer users\""
              echo "users-approval:        nobody"
              echo "owner-users:           nobody"
            ) |\
            $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
                -a -i "$RPM_INSTALL_PREFIX:majordomo" $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:majordomo" $aliases_file
        fi
        if [ ".$update_command" != . ]; then
            eval $update_command
        fi
    fi

