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

VERSION=5.1
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 "| hdparm-$VERSION |"
echo "+============+"
cd $TMP
tar xzvf $CWD/hdparm-$VERSION.tar.gz
cd hdparm-$VERSION
make
strip hdparm
mkdir -p $PKG/usr/sbin
cat hdparm > $PKG/usr/sbin/hdparm
chmod 755 $PKG/usr/sbin/hdparm
chown -R root.bin $PKG/usr/sbin
mkdir -p $PKG/usr/man/man8
cat hdparm.8 | gzip -9c > $PKG/usr/man/man8/hdparm.8.gz
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
echo "n" | makepkg $TMP/hdparm-$VERSION-$ARCH-$BUILD.tgz

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