##
##  gup.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:         gup
Summary:      Group Update (Newsgroups Subscription Manager)
URL:          http://packages.debian.org/stable/news/gup.html
Vendor:       Mark Delany
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        News
License:      Public Domain
Version:      0.5.13
Release:      20080405

#   list of sources
Source0:      http://ftp.debian.org/debian/pool/main/g/gup/gup_%{version}.tar.gz
Patch0:       gup.patch

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

%description
    GUP is a small mail robot for managing the USENET newsgroup
    subscriptions of feeds in INN.

%track
    prog gup = {
        version   = %{version}
        url       = http://ftp.debian.org/debian/pool/main/g/gup/
        regex     = gup_(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %patch -p0

%build
    %{l_shtool} subst \
        -e 's;/usr/sbin/sendmail;%{l_prefix}/sbin/sendmail;' \
        -e 's;/var/lib/news;%{l_prefix}/var/gup;' \
        -e 's;"news";"postmaster";' \
        -e 's;USE_FLOCK;USE_DOTLOCK;' \
        config.h
    %{l_make} %{l_mflags -O} \
        CC="%{l_cc}" \
        P_CFLAGS="%{l_cflags -O}"

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/gup \
        $RPM_BUILD_ROOT%{l_prefix}/var/gup/sites
    %{l_shtool} install -c -s -m 4755 \
        gup $RPM_BUILD_ROOT%{l_prefix}/sbin/
    %{l_shtool} install -c -m 644 \
        gup.8 $RPM_BUILD_ROOT%{l_prefix}/man/man8/
    echo "test test postmaster@localhost" >config
    %{l_shtool} install -c -m 600 \
        config $RPM_BUILD_ROOT%{l_prefix}/etc/gup/config
    ( echo "From: \"Group Update\" <gup@localhost>"
      echo "User-Agent: gup/%{version}"
      echo ""
      echo "This is the Group Update (gup/%{version}) service on"
      echo "localhost managing your Usenet newsgroup subscription."
    ) >header
    %{l_shtool} install -c -m 644 \
        header $RPM_BUILD_ROOT%{l_prefix}/etc/gup/header
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std} \
        '%config %{l_prefix}/etc/gup/*'

%files -f files

%clean

%post
    aliases_file=`$RPM_INSTALL_PREFIX/bin/openpkg rc --query MTA_aliases_file`
    update_command=`$RPM_INSTALL_PREFIX/bin/openpkg rc --query MTA_aliases_update`
    if [ ".$aliases_file" != . ]; then
        gup="$RPM_INSTALL_PREFIX/sbin/gup"
        gup="$gup -d $RPM_INSTALL_PREFIX/etc/gup"
        gup="$gup -m $RPM_INSTALL_PREFIX/etc/gup/header"
        gup="$gup -s $RPM_INSTALL_PREFIX/var/gup/sites"
        gup="$gup -l $RPM_INSTALL_PREFIX/var/gup/logfile"
        gup="$gup -a $RPM_INSTALL_PREFIX/var/inn/db/active"
        gup="$gup -n $RPM_INSTALL_PREFIX/var/inn/db/newsgroups"
        echo "gup: \"|$gup\"" |\
        $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
            -a -i "$RPM_INSTALL_PREFIX:gup" $aliases_file
    fi
    if [ ".$update_command" != . ]; then
        eval $update_command
    fi

%preun
    aliases_file=`$RPM_INSTALL_PREFIX/bin/openpkg rc --query MTA_aliases_file`
    update_command=`$RPM_INSTALL_PREFIX/bin/openpkg rc --query MTA_aliases_update`
    if [ ".$aliases_file" != . ]; then
        $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
            -r -i "$RPM_INSTALL_PREFIX:gup" $aliases_file
    fi
    if [ ".$update_command" != . ]; then
        eval $update_command
    fi

