##
##  jitterbug.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:         jitterbug
Summary:      Bug Tracking System (OSSP Version)
URL:          http://jitterbug.samba.org/
Vendor:       Andrew Tridgell
Packager:     The OpenPKG Project
Distribution: OpenPKG [EVAL]
Group:        Database
License:      GPL
Version:      1.6.2.3
Release:      20020625

#   list of sources
Source0:      ossp-jitterbug-%{version}.tar.gz
Source1:      config.tar

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20020206, zlib
PreReq:       OpenPKG, openpkg >= 20020206, MTA, apache, gzip
AutoReq:      no
AutoReqProv:  no

%description
    JitterBug is a web based bug tracking system. It was originally
    developed by the Andrew Tridgell to handle bug tracking, problem
    reports and queries from Samba users.

%prep
    %setup -q -n ossp-jitterbug-%{version}

%build
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O} -I%{l_prefix}/include" \
    LDFLAGS="-L%{l_prefix}/lib" \
    ./configure \
        --prefix=%{l_prefix} \
        --sysconfdir=%{l_prefix}/etc/jitterbug
    %{l_shtool} subst \
        -e 's;^\(LIBS *=.*\)$;\1 -L%{l_prefix}/lib -lz;' \
        Makefile
    %{l_make} %{l_mflags -O}

%install
    rm -rf $RPM_BUILD_ROOT
    %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    tar xvf %{SOURCE config.tar}
    ( cd config
      l_hostname=`%{l_shtool} echo -e %h`
      l_domainname=`%{l_shtool} echo -e %d | cut -c2-`
      %{l_shtool} subst -v \
          -e "s;@l_hostname@;$l_hostname;g" \
          -e "s;@l_domainname@;$l_domainname;g" \
          -e 's;@l_prefix@;%{l_prefix};g' \
          -e 's;@l_musr@;%{l_musr};g' \
          -e 's;@l_muid@;%{l_muid};g' \
          -e 's;@l_mgrp@;%{l_mgrp};g' \
          -e 's;@l_mgid@;%{l_mgid};g' \
          -e 's;@l_nusr@;%{l_nusr};g' \
          -e 's;@l_nuid@;%{l_nuid};g' \
          -e 's;@l_ngrp@;%{l_ngrp};g' \
          -e 's;@l_ngid@;%{l_ngid};g' \
          `find . -type f -print`
      rm -rf */*.orig */.[a-z]*.orig >/dev/null 2>&1 || true
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/etc/jitterbug
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/var/jitterbug/bugdb
      %{l_shtool} install -c -m - etc/* \
          $RPM_BUILD_ROOT%{l_prefix}/etc/jitterbug/
      cp -rp var/* var/.[a-z]* \
          $RPM_BUILD_ROOT%{l_prefix}/var/jitterbug/bugdb/
    )
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/jitterbug/*' \
        '%attr(04755,root,%{l_mgrp}) %{l_prefix}/bin/jitterbug-*'

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

%post
    if [ ".$1" = .1 ]; then
        #   add hook into MTA configuration
        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 "bugdb: \"|$RPM_INSTALL_PREFIX/bin/jitterbug-mail bugdb-guest\""
              echo "owner-bugdb: postmaster"
            ) |\
            $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
                -a -i "$RPM_INSTALL_PREFIX:jitterbug" $aliases_file
            if [ ".$update_command" != . ]; then
                eval $update_command
            fi
        fi
        #   add hook into Apache configuration
        apacheconf="$RPM_INSTALL_PREFIX/etc/apache/apache.conf"
        if [ -f $apacheconf ]; then
            ( echo "Alias /bugdb $RPM_INSTALL_PREFIX/var/jitterbug/bugdb"
              echo "<Directory $RPM_INSTALL_PREFIX/var/jitterbug/bugdb>"
              echo "    AllowOverride all"
              echo "</Directory>"
            ) |\
            $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
                -a -i "$RPM_INSTALL_PREFIX:jitterbug" $apacheconf
        fi
    fi

%postun
    if [ ".$1" = .0 ]; then
        #   remove hook from MTA configuration
        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:jitterbug" $aliases_file
            if [ ".$update_command" != . ]; then
                eval $update_command
            fi
        fi
        #   remove hook from Apache configuration
        apacheconf="$RPM_INSTALL_PREFIX/etc/apache/apache.conf"
        if [ -f $apacheconf ]; then
            $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
                -r -i "$RPM_INSTALL_PREFIX:jitterbug" $apacheconf
        fi
    fi

