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

VERSION=2.1.10
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/_pciutils.tar.gz

echo "+================+"
echo "| pciutils-$VERSION |"
echo "+================+"
cd $TMP
tar xjvf $CWD/pciutils-$VERSION.tar.bz2
cd pciutils-$VERSION
# Fetch the latest pci.ids:
rm -f pci.ids
wget http://pciids.sourceforge.net/pci.ids
make
strip lspci setpci
cat lspci > $PKG/sbin/lspci
cat setpci > $PKG/sbin/setpci
cat pci.ids > $PKG/usr/share/pci.ids
gzip -9c lspci.8 > $PKG/usr/man/man8/lspci.8.gz
gzip -9c setpci.8 > $PKG/usr/man/man8/setpci.8.gz
mkdir -p $PKG/usr/doc/pciutils-$VERSION
cp -a README ChangeLog TODO $PKG/usr/doc/pciutils-$VERSION
chown root.root $PKG/usr/doc/pciutils-$VERSION/*
chmod 644 $PKG/usr/doc/pciutils-$VERSION/*
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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