%bcond_with systemd
%bcond_with tracker

%global tracker_api 3.0

################################################# BASIC PACKAGE INFORMATION
Summary:        AFP fileserver for Macintosh clients
Summary(ja):    Macintoshクライアント向けのAFPファイルサーバー
Name:           netatalk
Version:        3.1.12
Release:        5%{_dist_release}%{?with_systemd:.systemd}
Group:          servers
Vendor:         Project Vine
Distribution:   Vine Linux
Packager:       shaolin, tomop

License:        GPLv2+
URL:            http://netatalk.sourceforge.net/
Source0:        %{name}-%{version}.tar.bz2
Source1:        netatalk.pam-system-auth
Source2:        netatalk.conf
Patch0:         netatalk-3.0.1-basedir.patch
Patch1:         netatalk-systemd-execstartpre.patch
# https://github.com/Netatalk/Netatalk/pull/110
Patch2:         netatalk-fix-incorrect-fsf-address.patch
# https://github.com/Netatalk/Netatalk/pull/113
Patch3:         netatalk-afpstats-python3-compat.patch
# https://github.com/Netatalk/Netatalk/pull/125
Patch4:         netatalk-invalid_dircache_entries.patch

############################################################## REQUIREMENTS
BuildRequires:  cracklib openssl-devel pam quota libtool automake
BuildRequires:  autoconf libdb-devel pam-devel libgcrypt-devel
BuildRequires:  avahi-devel libacl-devel openldap-devel
BuildRequires:  dbus-devel dbus-glib-devel glib2-devel
BuildRequires:  libevent-devel libtdb-devel libmariadb-devel
%if %{with tracker}
BuildRequires:  tracker-devel
%endif

Requires:       dbus-python3
Requires:       dconf
%if %{with systemd}
BuildRequires:  systemd
%{?systemd_requires}
%else
Requires(post): /sbin/chkconfig
Requires(preun): /sbin/chkconfig
Requires(preun): /sbin/service
Requires(postun): /sbin/service
%endif

BuildRoot:     %{_tmppath}/%{name}-%{version}-root

%description
Netatalk is a freely-available Open Source AFP fileserver. A *NIX/*BSD
system running Netatalk is capable of serving many Macintosh clients
simultaneously as an AppleShare file server (AFP).

%description -l ja
　Netatalkは自由に利用可能なオープンソースAFPファイルサーバーです。
Netatalkを実行している*NIX/*BSDシステムでは、多くのMacintoshクライ
アントに対してAppleShareファイルサーバー（AFP）としてサービスを提供
可能です。


%package devel
Summary:       Headers for Netatalk development
Summary(ja):   Netatalk開発用ヘッダファイル
Group:         programming

%description devel
This package contains the header files for Netatalk.


%debug_package


%prep
%setup -q
%autopatch -p1

rm -frv libevent/

ln -s ./NEWS ChangeLog

# Avoid re-running the autotools
touch -r aclocal.m4 configure configure.ac macros/gssapi-check.m4

# fix permissions
find include \( -name '*.h' -a -executable \) -exec chmod -x {} \;

# Don't call systemctl daemon-reload during the build
sed -i 's\-systemctl daemon-reload\\g' distrib/initscripts/Makefile.in


%build
%configure \
        --disable-silent-rules \
        --disable-static \
        --enable-shared \
        --localstatedir=%{_localstatedir}/lib \
        --with-pkgconfdir=%{_sysconfdir}/netatalk \
        --with-cracklib \
        --with-pam \
        --with-shadow \
        --with-uams-path=%{_libdir}/netatalk \
        --enable-shared \
        --enable-krbV-uam \
        --enable-overwrite \
        --with-gnu-ld \
%if %{with systemd}
        --with-lockfile=/run/lock/netatalk/netatalk \
        --with-init-style=redhat-systemd \
        --with-init-dir=%{_unitdir} \
%else
        --with-init-style=redhat-sysv \
%endif
        --with-libgcrypt \
        --without-libevent \
        --without-tdb \
        --with-pam-confdir=%{_sysconfdir}/pam.d \
        --with-dbus-sysconf-dir=%{_sysconfdir}/dbus-1/system.d \
        -with-spotlight \
%if %{with tracker}
        --with-tracker-pkgconfig-version=%{tracker_api}
%endif

make %{?_smp_mflags} all

%install
### INSTALL (USING "make install") ###
rm -rf ${RPM_BUILD_ROOT}

make DESTDIR=$RPM_BUILD_ROOT mandir=%{_mandir} install

# install our tmpfiles config
install -Dpm644 %{SOURCE2} %{buildroot}%{_tmpfilesdir}/netatalk.conf

# install example config files in doc
mkdir config.example
cp -fp config/afp.conf config.example
cp -fp config/extmap.conf config.example
mkdir -p $RPM_BUILD_ROOT/usr/share/netatalk

cp -fp %{SOURCE1} config.example
# XXX bad hack until this file is updated in glibc-headers:
rm -f $RPM_BUILD_ROOT/usr/include/netatalk/at.h

# Clean up .a and .la files
find $RPM_BUILD_ROOT -name \*.a -exec rm {} \;
find $RPM_BUILD_ROOT -name \*.la -exec rm {} \;

# Fix python shebang
sed -i 's\^#!/usr/bin/env python$\#!%{__python3}\' %{buildroot}/usr/bin/afpstats


%clean
rm -rf ${RPM_BUILD_ROOT}


%post
if [ -e /var/netatalk/afp_signature.conf -a ! -e /var/lib/netatalk/afp_signature.conf ]; then
    mv -f /var/netatalk/afp_signature.conf /var/lib/netatalk/
fi
if [ -e /etc/netatalk/afp_signature.conf -a ! -e /var/lib/netatalk/afp_signature.conf ]; then
    mv -f /etc/netatalk/afp_signature.conf /var/lib/netatalk/
fi
if [ -e /var/netatalk/afp_voluuid.conf -a ! -e /var/lib/netatalk/afp_voluuid.conf ]; then
    mv -f /var/netatalk/afp_voluuid.conf /var/lib/netatalk/
fi
if [ -e /etc/netatalk/afp_voluuid.conf -a ! -e /var/lib/netatalk/afp_voluuid.conf ]; then
    mv -f /etc/netatalk/afp_voluuid.conf /var/lib/netatalk/
fi

%if %{with systemd}
%systemd_post %{name}.service
%else
/sbin/chkconfig --add netatalk
%endif

%preun
%if %{with systemd}
%systemd_preun %{name}.service
%else
if [ "$1" = "0" -o -x /bin/systemctl ] ; then
    # check for existence due to renaming initscript
    if [ -x  %{_initrddir}/netatalk ] ; then
        /sbin/service netatalk stop > /dev/null 2>&1
        /sbin/chkconfig --del netatalk
    fi
fi
%endif

%postun
%if %{with systemd}
%systemd_postun_with_restart %{name}.service
%else
if [ "$1" -ge "1" -a ! -x /bin/systemctl ]; then
    /sbin/service netatalk condrestart > /dev/null 2>&1 || :
fi
%endif


%files
%defattr(-,root,root)
%license COPYING COPYRIGHT
%doc NEWS
%doc config.example
%if %{with systemd}
%{_unitdir}/netatalk.service
%{_tmpfilesdir}/netatalk.conf
%else
%attr(755,root,root) %{_initrddir}/netatalk
%endif
%dir %{_sysconfdir}/netatalk
%config(noreplace) %{_sysconfdir}/netatalk/afp.conf
%config(noreplace) %{_sysconfdir}/netatalk/extmap.conf
%config(noreplace) %{_sysconfdir}/netatalk/dbus-session.conf
%config(noreplace) %{_sysconfdir}/pam.d/netatalk
%config(noreplace) %{_sysconfdir}/dbus-1/system.d/netatalk-dbus.conf
%{_sbindir}/*
%{_bindir}/*
%exclude %{_bindir}/netatalk-config
%{_mandir}/man*/*
%exclude %{_mandir}/man*/netatalk-config*
%{_datadir}/netatalk
%{_libdir}/*.so
%{_libdir}/*.so.*
%dir %{_libdir}/netatalk
%{_libdir}/netatalk/*.so
%{_localstatedir}/lib/netatalk

%files devel
%defattr(-,root,root)
%license COPYING COPYRIGHT
%dir %{_includedir}/atalk
%attr(0644,root,root) %{_includedir}/atalk/*
%{_datadir}/aclocal/netatalk.m4
%{_bindir}/netatalk-config
%{_mandir}/man*/netatalk-config.1*


%changelog
* Tue Oct 05 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.12-5
- rebuilt with openssl-3.0.0.

* Tue Mar 30 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.12-4
- disabled tracker.

* Sat Mar 13 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.12-3
- rebuilt with current environment.
- cleaned up BR.

* Tue Apr 14 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.12-2
- rebuilt with libevent-2.1.11.
- added systemd support (disabled as default).

* Mon Jan 07 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.12-1
- new upstream release.

* Sun Nov 04 2018 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.11-2
- rebuilt with openssl-1.1.1 and libevent-2.1.8.

* Thu Mar 16 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.11-1
- new upstream release.

* Wed Jul 20 2016 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.9-1
- new upstream release.
- dropped Patch1: fixed in upstream.

* Wed Dec 30 2015 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.8-2
- added Patch1.

* Wed Dec 30 2015 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.8-1
- new upstream release.

* Tue Jun 16 2015 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 3.1.7-1
- new upstream release.

* Mon Dec  1 2014 Ryoichi INAGAKI <ryo1@toki.waseda.jp> - 2.2.2-2
- rebuilt with libgcrypt 1.6.0 and libdb 5.3.28

* Thu Apr 26 2012 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.2.2-1
- new upstream release.
- added build option 'force_uidgid'.

* Sun Sep 18 2011 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 2.2.1-1
- new upstream release
- fix configure options; add missing BRs

* Thu Jul 28 2011 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 2.2.0-3
- now back from the upstream confusion (and one more or two...)
  new upstream release 2.2.0 at the official site

* Mon Jul 25 2011 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 2.2.0-2
- fix Patch10 to follow HAT-san's strong and confident objection
  (no need to set ATALK_NAME explicitly in netatalk.conf)

* Sat Jul 23 2011 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 2.2.0-1
- new upstream release (at http://www003.upp.so-net.ne.jp/hat/netatalk/)
- add Source100 to add one missing header file in the tarball
- revise Patch10
- explicitly specify --disable-ddp for the first time

* Wed May 04 2011 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 2.1.5-1
- new upstream release

* Sun Feb 06 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> - 2.1.3-3
- rebuild with openssl-1.0.0c

* Sun Jul 25 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 2.1.3-2
- fix Patch10 & update description - upon HAT-san's suggestions

* Sun Jul 25 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 2.1.3-1
- new upstream release
- update Vine patch

* Thu Feb 11 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 2.0.5-1
- new upstream release

* Sun May 31 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 2.0.4-1
- new upstream release

* Sun Mar  8 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 2.0.3-7
- rebuilt both for VineSeed / VinePlus-4.0

* Fri Jul 25 2008 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2.0.3-6
- updated to the cjk-6 patch
- Patch11/12 updated - VineSeed is now set with ja_JP.UTF-8 locale
- Patch14 updated for db46

* Sun Apr 20 2008 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2.0.3-5
- remove openslp dependency

* Tue Apr 15 2008 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2.0.3-4
- add Patch11 for Vine's default setting (volcharset:EUC-JP, etc.)
- TODO: remember to revise this fix after VineSeed changes default locale
        from ja_JP.eucJP (current) to ja_JP.UTF-8 (near future)

* Tue Apr 15 2008 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2.0.3-3
- revise description (thanks HAT-san for pointing this out)
- run libtoolize/aclocal/auto{make,conf,header} before doing configure
  (without this, uams_* modules won't get .so suffix)

* Mon Apr 14 2008 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2.0.3-2
- Patch10 updated; dropped Patch11, Patch12, Source10 and Source11
  (Patch10 now includes all the modifications and more fixes)

* Fri Apr 11 2008 Tomohiro 'Tomo-p' KATO <tomop@teamgedoh.net> 2.0.3-1
- add patch13 and patch14 for db-4.3.
- move files in %%_libexecdir to %%libdir.

* Sat Oct 21 2006 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2.0.3-0vl1
- updated to 2.0.3 release w/ cjk patches (see the above Patch section)

* Tue Oct 19 2004 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2.0-0vl4
- security fix: added Patch10 (CAN-2004-0974)

* Tue Oct 19 2004 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2.0-0vl3
- configure --with-cnid-default-backend=dbd (cdb seems to be unstable)

* Wed Oct 13 2004 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2.0-0vl1
- updated to 2.0 with cjk patch
  (see the above Patch section for details)

* Tue May 28 2002 Masaki Shinomiya <shino@pos.to> 1.5.3.1-0vl4
- merge the patch repairing bug for System 7.5.5
- (patch6 netatalk-1.5.3.oldsys.patch)
- made by Akihiro Okamaoto <med012@art.osaka-med.ac.jp>
- patch6 addupted no matter noeuc is, license GPL, URL in comment

* Sat Apr 27 2002 Masaki Shinomiya <shino@pos.to> 1.5.3.1-0vl3
- euc and kana patch originally by
- Akihiro Okamoto <med012@art.osaka-med.ac.jp> against netatalk-1.4b2+asun2.1.3
- applied to netatalk-1.5.2 by me 
- README.vine
- omit VERSION from doc, omit perl from require

* Wed Apr 24 2002 Masaki Shinomiya <shino@pos.to> 1.5.3.1-0vl2
- this package is removed because the release number duplicated

* Mon Apr 01 2002 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 1.5.3.1-0vl2
- move acleandir.rc to the doc directory, remove executable flag.

* Sun Mar 31 2002 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 1.5.3.1-0vl1
- updated to new upstream release

* Fri Mar 01 2002 Toru Sagami <sagami@vinelinux.org> 1.5.2-0vl3
- added Japanese Summary for devel and corrected Group

* Thu Feb 28 2002 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 1.5.2-0vl2
- Oops, check /var/lock/atalkd instead of /var/run/atd.pid
  (say atd.pid doesn't have anything to do with netatalk!!)

* Tue Feb 26 2002 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 1.5.2-0vl1
- updated to new upstream release

* Thu Feb 07 2002 Toru Sagami <sagami@vinelinux.org> 1.5.1.1-0vl3
- install man pages into %%{_mandir}
- PreReq: /sbin/chkconfig /sbin/ldconfig grep textutils
- let pre script exit 0

* Thu Feb 07 2002 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 1.5.1.1-0vl2
- spec cleanup
- backup old prefs directory (/etc/atalk -> /etc/netatalk/00OLD_VERSION_PREFS)
- restart atalk daemons in the %%post section

* Sun Feb 3 2002  k hanai <hanai@koto.kpu-m.ac.jp>
 - v1.5.1.1-0vl1

* Fri Jan 25 2002 k hanai <hanai@koto.kpu-m.ac.jp>
  - v1.5.0-0vl1
  - release 1.5.0 for sourceforge

* Thu Apr 12 2001 rufus t firefly <rufus.t.firefly@linux-mandrake.com>
  - v1.5pre6-1rh7
  - pre-release 6 for sourceforge

* Wed Mar 07 2001 rufus t firefly <rufus.t.firefly@linux-mandrake.com>
  - v1.5pre5-1
  - pre-release 5 for sourceforge

* Fri Feb 23 2001 rufus t firefly <rufus.t.firefly@linux-mandrake.com>
  - v1.5pre5-0
  - pre-release 5 for sourceforge (prebuild)

* Tue Feb 20 2001 rufus t firefly <rufus.t.firefly@linux-mandrake.com>
  - v1.5pre4-1
  - pre-release 4 for sourceforge
  - modified/split mandrake spec for redhat 7 build

* Mon Dec 18 2000 rufus t firefly <rufus.t.firefly@linux-mandrake.com>
  - v1.5pre3-1mdk
  - pre-release 3 for sourceforge
  - moved away from 1.4.99 ... 

* Wed Nov 08 2000 rufus t firefly <rufus.t.firefly@linux-mandrake.com>
  - v1.4.99-0.20001108mdk
  - pre-release 2 for sourceforge

* Wed Sep 27 2000 rufus t firefly <rufus.t.firefly@linux-mandrake.com>
  - v1.4.99-0.20000927mdk
  - pre-release 1 for sourceforge
