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

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/_mt_st.tar.gz

echo "+===========+"
echo "| mt-st-0.6 |"
echo "+===========+"
cd $TMP
tar xzvf $CWD/mt-st-0.6.tar.gz
cd mt-st-0.6
rm -f mt
make
strip mt stinit
cat mt > $PKG/bin/mt-st
cat stinit > $PKG/sbin/stinit
mkdir -p $PKG/usr/man/man{1,8}
cat mt.1 | gzip -9c > $PKG/usr/man/man1/mt-st.1.gz
cat stinit.8 | gzip -9c > $PKG/usr/man/man8/stinit.8.gz
mkdir -p $PKG/usr/doc/mt-st-0.6
cp -a COPYING README* *.lsm stinit.def.examples $PKG/usr/doc/mt-st-0.6
chown -R root.root $PKG/usr/doc/mt-st-0.6
chmod 644 $PKG/usr/doc/mt-st-0.6/*

# Build the package:
cd $PKG
tar czvf $TMP/mt_st.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/mt-st-0.6
  rm -rf $PKG
fi