#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-samba
SRC=/devel/manpagesrc
INFO=/devel/info-pages/usr/info
TEX=/devel/texinfo-docs

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

# Function to handle manpage source:
man2gz () { # $1 is source page name, $2 is target name for preformatted
            # output (full path && name) and $3 is the same, but for the
            # source.
  mkdir -p `dirname $2`
  groff -Tascii -mandoc $1 | gzip -9c > $2
  if [ ! "$3" = "" ]; then
    mkdir -p `dirname $3`
    cat $1 > $3 
  fi 
}

echo "+==============+"
echo "| samba-1.9.13 |"
echo "+==============+"
cd $TMP
tar xzvf $CWD/samba-1.9.13.tar.gz
cd samba-1.9.13
zcat $CWD/samba-1.9.13.diff.gz | patch
make LDFLAGS=-s 
mkdir $PKG/etc
cp smb.conf.sampl $PKG/etc
mkdir -p $PKG/usr/sbin
chown root.bin $PKG/usr/sbin
for i in smbd smbclient nmbd testparm testprns smbrun smbstatus; do \
        cp $i $PKG/usr/sbin/$i ; \
        chmod 0755 $PKG/usr/sbin/$i ; \
        chown root.bin $PKG/usr/sbin/$i ; \
done
man2gz smbstatus.1 $PKG/usr/man/preformat/cat1/smbstatus.1.gz $SRC/usr/man/man1/smbstatus.1
man2gz smbclient.1 $PKG/usr/man/preformat/cat1/smbclient.1.gz $SRC/usr/man/man1/smbclient.1
man2gz smbrun.1 $PKG/usr/man/preformat/cat1/smbrun.1.gz $SRC/usr/man/man1/smbrun.1
man2gz testparm.1 $PKG/usr/man/preformat/cat1/testparm.1.gz $SRC/usr/man/man1/testparm.1
man2gz testprns.1 $PKG/usr/man/preformat/cat1/testprns.1.gz $SRC/usr/man/man1/testprns.1
man2gz smb.conf.5 $PKG/usr/man/preformat/cat5/smb.conf.5.gz $SRC/usr/man/man5/smb.conf.5
man2gz samba.7 $PKG/usr/man/preformat/cat7/samba.7.gz $SRC/usr/man/man7/samba.7
man2gz smbd.8 $PKG/usr/man/preformat/cat8/smbd.8.gz $SRC/usr/man/man8/smbd.8
man2gz nmbd.8 $PKG/usr/man/preformat/cat8/nmbd.8.gz $SRC/usr/man/man8/nmbd.8
mkdir -p $PKG/usr/doc/samba-1.9.13
cp -a BROWSING.txt COPYING HINTS.txt INSTALL.txt MIRRORS OS2.txt PROJECTS \
README SMBGuide.txt SPEED.txt THANKS WARP.txt WINNT.txt announce change-log \
history samba.faq smb.conf.sampl smbprint.sysv $PKG/usr/doc/samba-1.9.13
chown root.root $PKG/usr/doc/samba-1.9.13/*

# Build the package:
cd $PKG
tar czvf $TMP/samba-1.9.13.tgz .

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/samba-1.9.13
  rm -rf $PKG
fi
