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

PKG=$TMP/package-ytalk

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

# Explode the package framework:
cd $PKG
explodepkg $CWD/_ytalk.tar.gz

# Find the size of a file:
filesize() {
 SIZE=`ls -l -d -G $1 | cut -b23-32`
 echo -n $SIZE
}

echo "+=============+"
echo "| ytalk-3.1.1 |"
echo "+=============+"
cd $TMP
tar xzvf $CWD/ytalk-3.1.1.tar.gz
cd ytalk-3.1.1
mkdir -p $PKG/usr/doc/ytalk-3.1.1
cp -a BUGS ChangeLog INSTALL README README.old ytalk-3.1.1.lsm $PKG/usr/doc/ytalk-3.1.1
chmod 644 $PKG/usr/doc/ytalk-3.1.1/*
chown root.root $PKG/usr/doc/ytalk-3.1.1/*
./configure --prefix=/usr --with-x=no i386-slackware-linux
make
strip ytalk
cat ytalk > $PKG/usr/bin/ytalk
cat ytalk.1 | gzip -9c > $PKG/usr/man/man1/ytalk.1.gz
cat ytalkrc > $PKG/usr/etc/ytalkrc

# Build the package:
cd $PKG
tar czvf $TMP/ytalk.tgz .

# Warn of zero-length files:
for file in `find . -type f -print` ; do
 if [ "`filesize $file`" = "0" ]; then
  echo "WARNING: zero length file $file"
 fi
 if [ "`filesize $file`" = "20" ]; then
  echo "WARNING: possible empty gzipped file $file"
 fi
done

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