##
##  samba.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:         samba
Summary:      SMB/CIFS Server
URL:          http://www.samba.org/
Vendor:       Andrew Tridgell
Packager:     The OpenPKG Project
Distribution: OpenPKG [BASE]
Group:        Filesystem
License:      GPL
Version:      2.2.7a
Release:      20030103

#   package options
%option       with_pam  no

#   list of sources
Source0:      http://download.samba.org/samba/ftp/samba-%{version}.tar.bz2
Source1:      smb.conf
Source2:      smb.hosts
Source3:      rc.samba

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20030103, openssl
PreReq:       OpenPKG, openpkg >= 20030103
%if "%{with_pam}" == "yes"
BuildPreReq:  PAM
PreReq:       PAM
%endif
AutoReq:      no
AutoReqProv:  no

%description
    Samba is an open source software suite that provides seamless file
    and print services to SMB/CIFS clients.

%prep
    %setup -q

%build
    ( cd source
      CC="%{l_cc}"
      CFLAGS="%{l_cflags -O}"
      CPPFLAGS="-I%{l_prefix}/include -I%{l_prefix}/include/openssl"
      LDFLAGS="-L%{l_prefix}/lib"
%if "%{with_pam}" == "yes"
      CPPFLAGS="$CPPFLAGS -I`%{l_prefix}/etc/rc --query pam_incdir`" \
      LDFLAGS="$LDFLAGS -L`%{l_prefix}/etc/rc --query pam_libdir`" \
%endif
      export CC
      export CFLAGS
      export LDFLAGS
      ./configure \
          --prefix=%{l_prefix} \
          --localstatedir=%{l_prefix}/var/samba/run \
          --sysconfdir=%{l_prefix}/etc/samba \
          --with-privatedir=%{l_prefix}/var/samba/run \
          --with-sambaconfdir=%{l_prefix}/etc/samba \
          --with-lockdir=%{l_prefix}/var/samba/run \
          --with-swatdir=%{l_prefix}/share/samba \
          --with-codepagedir=%{l_prefix}/share/samba \
          --with-ssl --with-sslinc=%{l_prefix}/include \
          --with-included-popt \
%if "%{with_pam}" == "yes"
          --with-pam \
%endif
          --with-vfs
      %{l_make} %{l_mflags -O} \
          CONFIGFILE=%{l_prefix}/etc/samba/smb.conf \
          LMHOSTSFILE=%{l_prefix}/etc/samba/smb.hosts
    )

%install
    rm -rf $RPM_BUILD_ROOT
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/samba \
        $RPM_BUILD_ROOT%{l_prefix}/var/samba \
        $RPM_BUILD_ROOT%{l_prefix}/share/samba \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/samba \
        $RPM_BUILD_ROOT%{l_prefix}/var/samba/run \
        $RPM_BUILD_ROOT%{l_prefix}/var/samba/spool \
        $RPM_BUILD_ROOT%{l_prefix}/var/samba/netlogon \
        $RPM_BUILD_ROOT%{l_prefix}/var/samba/profiles
    ( cd source
      %{l_make} %{l_mflags} install \
          prefix=$RPM_BUILD_ROOT%{l_prefix} \
          BASEDIR=$RPM_BUILD_ROOT%{l_prefix} \
          CONFIGDIR=$RPM_BUILD_ROOT%{l_prefix}/etc/samba \
          VARDIR=$RPM_BUILD_ROOT%{l_prefix}/var/samba/run \
          SWATDIR=$RPM_BUILD_ROOT%{l_prefix}/share/samba \
          CODEPAGEDIR=$RPM_BUILD_ROOT%{l_prefix}/share/samba \
          CONFIGFILE=%{l_prefix}/etc/samba/smb.conf \
          LMHOSTSFILE=%{l_prefix}/etc/samba/smb.hosts
    )
    l_hostname=`%{l_shtool} echo -e %h%d`
    %{l_shtool} install -c -m 644 \
        -e 's;@l_prefix@;%{l_prefix};g' \
        -e "s;@l_hostname@;$l_hostname;g" \
        %{SOURCE smb.conf} \
        %{SOURCE smb.hosts} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/samba/
    for file in make_printerdef make_smbcodepage make_unicodemap \
        testparm testprns; do
        mv $RPM_BUILD_ROOT%{l_prefix}/bin/$file \
           $RPM_BUILD_ROOT%{l_prefix}/libexec/samba/$file
    done
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/samba/using_samba
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/samba/help
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/samba/images
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/samba/include
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    strip $RPM_BUILD_ROOT%{l_prefix}/sbin/* >/dev/null 2>&1 || true
    %{l_shtool} mkdir -f -p -m 755 $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
    %{l_shtool} install -c -m 755 -e 's;@l_prefix@;%{l_prefix};g' \
        %{SOURCE rc.samba} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/samba/*' \
        '%attr(1777,%{l_musr},%{l_mgrp}) %{l_prefix}/var/samba/spool' \
        '%attr(1777,%{l_musr},%{l_mgrp}) %{l_prefix}/var/samba/profiles'

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

%post
%if "%{with_pam}" == "yes"
    #   add PAM configuration entry
    if [ $1 -eq 1 ]; then
        $RPM_INSTALL_PREFIX/sbin/pamtool --add --smart --name=smbd
    fi
%endif

%preun
%if "%{with_pam}" == "yes"
    #   remove PAM configuration entry
    if [ $1 -eq 0 ]; then
        $RPM_INSTALL_PREFIX/sbin/pamtool --remove --smart --name=smbd
    fi
%endif

