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

VERSION=0.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

# Explode the package framework:
cd $PKG
explodepkg $CWD/_mt-st.tar.gz

echo "+===========+"
echo "| mt-st-$VERSION |"
echo "+===========+"
cd $TMP
tar xzvf $CWD/mt-st-$VERSION.tar.gz
cd mt-st-$VERSION
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-$VERSION
cp -a COPYING README* *.lsm stinit.def.examples $PKG/usr/doc/mt-st-$VERSION
chown -R root.root $PKG/usr/doc/mt-st-$VERSION
chmod 644 $PKG/usr/doc/mt-st-$VERSION/*
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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