##
##  netatalk.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 version
%define       V_opkg 3.1.18
%define       V_dist 3.1.18

#   package information
Name:         netatalk
Summary:      Apple Filetransfer Protocol (AFP) Server
URL:          http://netatalk.sourceforge.net/
Vendor:       Netatalk Developer Team
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Filesystem
License:      GPL
Version:      %{V_opkg}
Release:      20231005

#   list of sources
Source0:      http://downloads.sourceforge.net/netatalk/netatalk-%{V_dist}.tar.bz2
Source1:      rc.netatalk
Patch0:       netatalk.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  openssl, gcrypt, db, libiconv, libevent
PreReq:       openssl, gcrypt, db, libiconv, libevent

%description
    Netatalk is Open Source Apple Filetransfer Protocol (AFP)
    fileserver. A Unix system running Netatalk is capable of serving
    many Macintosh clients simultaneously as an AppleShare file server
    (AFP), AppleTalk router, Unix BSD print server, and for accessing
    AppleTalk printers via Printer Access Protocol (PAP).

%track
    prog netatalk = {
        version   = %{version}
        url       = http://netatalk.sourceforge.net/
        regex     = netatalk-(\d+\.\d+\.\d+)\.tar\.bz2
    }

%prep
    %setup -q -n netatalk-%{V_dist}
    %patch -p0

%build
    #   configure program
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    ./configure \
        --prefix=%{l_prefix} \
        --libexecdir=%{l_prefix}/libexec/netatalk \
        --mandir=%{l_prefix}/man \
        --with-uams-path=%{l_prefix}/lib/netatalk \
        --with-lockfile=%{l_prefix}/var/netatalk/run/netatalk.pid \
        --with-ssl-dir=%{l_prefix} \
        --with-bdb=%{l_prefix} \
        --with-libiconv=%{l_prefix} \
        --with-libevent-header=%{l_prefix}/include \
        --with-libevent-lib=%{l_prefix}/lib \
        --without-ldap \
        --without-kerberos \
        --without-dtrace \
        --disable-pgp-uam \
        --disable-krb4-uam \
        --disable-krbV-uam \
        --disable-tcp-wrappers

    #   build program
    %{l_make} %{l_mflags -O}

%install
    #   install program
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"

    #   strip down installation
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    strip $RPM_BUILD_ROOT%{l_prefix}/sbin/* >/dev/null 2>&1 || true
    rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/netatalk/*.a
    rm -f $RPM_BUILD_ROOT%{l_prefix}/etc/netatalk/netatalk.conf

    #   install run-command script
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.netatalk} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   create run-time directories
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/var/netatalk/run \
        $RPM_BUILD_ROOT%{l_prefix}/var/netatalk/log

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/netatalk/*' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/netatalk' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/netatalk/*'

%files -f files

%clean

%pre
    #   before upgrade, save status and stop service
    [ $1 -eq 2 ] || exit 0
    eval `%{l_rc} netatalk status 2>/dev/null | tee %{l_tmpfile}`
    %{l_rc} netatalk stop 2>/dev/null
    exit 0

%post
    if [ $1 -eq 2 ]; then
        #   after upgrade, restore status
        { eval `cat %{l_tmpfile}`; rm -f %{l_tmpfile}; true; } >/dev/null 2>&1
        [ ".$netatalk_active" = .yes ] && %{l_rc} netatalk start
    fi
    exit 0

%preun
    #   before erase, stop service and remove log files
    if [ $1 -eq 0 ]; then
        %{l_rc} netatalk stop 2>/dev/null
        rm -f  $RPM_INSTALL_PREFIX/var/netatalk/run/* >/dev/null 2>&1 || true
        rm -f  $RPM_INSTALL_PREFIX/var/netatalk/log/* >/dev/null 2>&1 || true
    fi
    exit 0

