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

VERSION=2.3.1
ARCH=noarch
BUILD=22

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
rm -rf $PKG
mkdir -p $PKG

# Explode the package framework:
cd $PKG
explodepkg $CWD/_devs.tar.gz

cd $TMP
rm -r MAKEDEV-2.3.1
tar xzvf $CWD/makedev_2.3.1.orig.tar.gz
cd MAKEDEV-2.3.1
zcat $CWD/makedev_2.3.1-46.2.diff.gz | patch -p1 -E
#zcat $CWD/makedev_2.3.1.slack.diff.gz | patch -p1 -E
# Add many more IDE devices:
zcat $CWD/makedev_2.3.1.hd.diff.gz | patch -p1 -E
# Still not enough:
zcat $CWD/makedev.hd.diff.gz | patch -p1 -E
cat MAKEDEV > $PKG/dev/MAKEDEV
cat README > $PKG/dev/README.MAKEDEV
gzip -9c MAKEDEV.man > $PKG/usr/man/man8/MAKEDEV.8.gz
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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