# Description: SMB Fileserver and AD Domain server
# URL: http://www.samba.org
# Packager: pierre at nutyx dot org
# Depends on: talloc avahi gnutls libgpg-error popt python cups kerberos libcap tdb openldap libxslt

name=samba
version=4.3.3
release=1

source=( http://ftp.samba.org/pub/samba/stable/$name-$version.tar.gz tls-use-gnutls_priority_set_direct.patch)

build() {
source /etc/blfs-bootscripts
wget http://www.linuxfromscratch.org/blfs/downloads/svn/$scripts-$scriptsversion.tar.bz2
if [ "`uname -m`" == "x86_64" ]; then
        LIB=lib64
else
        LIB=lib
fi
cd $name-$version

sed -e "/deps='LIBASYNC_REQ'/              \
       {
         s/$/,/
         a\                 install=False
       }"                                  \
    -i lib/async_req/wscript_build

./configure                             \
    --prefix=/usr                       \
    --sysconfdir=/etc                   \
    --localstatedir=/var                \
    --with-piddir=/run/samba            \
    --with-pammodulesdir=/lib/security  \
    --enable-fhs                        \
    --without-systemd

make

sed -i "/samba3.blackbox.failure.failure/i \^samba3.raw.eas" selftest/knownfail

make DESTDIR=$PKG install

install -d $PKG/$LIB
mv -v $PKG/usr/lib/libnss_win{s,bind}.so*   $PKG/$LIB
ln -v -sf /$LIB/libnss_winbind.so.2 $PKG/usr/lib/libnss_winbind.so
ln -v -sf /$LIB/libnss_wins.so.2    $PKG/usr/lib/libnss_wins.so
   
install -v -m644 examples/smb.conf.default $PKG/etc/samba/smb.conf.default

mkdir -pv $PKG/etc/openldap/schema
install -v -m644 examples/LDAP/README \
$PKG/etc/openldap/schema/README.LDAP

install -v -m644 examples/LDAP/samba* \
$PKG/etc/openldap/schema

install -v -m755 examples/LDAP/{get*,ol*} \
$PKG/etc/openldap/schema


#  cups 
cd $PKG/usr/lib/
install -d cups/backend
ln -v -sf $PKG/usr/bin/smbspool $PKG/usr/lib/cups/backend/smb

# service
cd $SRC

tar xf $scripts-$scriptsversion.tar.bz2
cd $SRC/$scripts-$scriptsversion
make DESTDIR=$PKG install-samba
make DESTDIR=$PKG install-winbindd
}