#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-autofs

VERSION=3.1.7
ARCH=i386
BUILD=1

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

echo "+==============+"
echo "| autofs-$VERSION |"
echo "+==============+"
cd $TMP
tar xjvf $CWD/autofs-$VERSION.tar.bz2
cd autofs-$VERSION
zcat $CWD/autofs-$VERSION.diff.gz | patch -p1 --verbose --backup --suffix=.orig -E
mkdir -p $PKG/usr/doc/autofs-$VERSION
cp -a COPYING COPYRIGHT NEWS README README.options TODO \
  multiserver_mount.patch samples $PKG/usr/doc/autofs-$VERSION
chown -R root.root $PKG/usr/doc/autofs-$VERSION
find $PKG/usr/doc/autofs-$VERSION -type d -exec chmod 755 {} \;
find $PKG/usr/doc/autofs-$VERSION -type f -exec chmod 644 {} \;
./configure --prefix=/usr i386-slackware-linux
make
cd daemon
mkdir -p $PKG/usr/sbin
cat automount > $PKG/usr/sbin/automount
chown root.bin $PKG/usr/sbin/automount
chmod 755 $PKG/usr/sbin/automount
cd ../modules
mkdir -p $PKG/usr/lib/autofs
for file in *.so ; do
  cat $file > $PKG/usr/lib/autofs/$file
done
cd ../man
mkdir -p $PKG/usr/man/man5 $PKG/usr/man/man8
for file in *.5 ; do
  cat $file | gzip -9c > $PKG/usr/man/man5/$file.gz
done
for file in *.8 ; do
  cat $file | gzip -9c > $PKG/usr/man/man8/$file.gz
done
strip $PKG/usr/sbin/*
chown -R root.bin $PKG/usr/sbin
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/autofs-$VERSION-$ARCH-$BUILD.tgz

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