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

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
tar xvzf $CWD/_donut.tar.gz

echo "+=======+"
echo "| Donut |"
echo "+=======+"
cd $TMP
mkdir Donut-1.0
cd Donut-1.0
tar xvzf $CWD/donut.tar.gz
make
strip donut
cat donut > $PKG/usr/lib/glide/demos/donut/donut
cp -a data/*.dat $PKG/usr/lib/glide/demos/donut/data
( cd $PKG/usr/lib/glide/demos/donut/data ; chown root.root * )
( cd $PKG/usr/lib/glide/demos/donut/data ; chmod 644 * )
cp -a license.txt readme.txt $PKG/usr/doc/Donut
( cd $PKG/usr/doc/Donut ; chown root.root * )
( cd $PKG/usr/doc/Donut ; chmod 644 * )

# make the package
cd $PKG
echo "n" | makepkg $TMP/donut.tgz

# clean up the extra stuff
if [ "$1" = "--cleanup" ]; then
   rm -rf $PKG
   rm -rf $TMP/Donut-1.0
fi
