#!/bin/sh
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-aboot

VERSION=0.9b
ARCH=alpha
BUILD=3

mkdir -p $PKG
cd $TMP
tar xjvf $CWD/aboot-$VERSION.tar.bz2
cd aboot-$VERSION
zcat $TMP/patches/a/aboot-$VERSION.patch.gz | patch -p0 --verbose
make
mkdir -p $PKG/usr/doc/aboot-$VERSION
cp -a doc/faq $PKG/usr/doc/aboot-$VERSION
cp -a COPYING ChangeLo* INSTALL README TODO $PKG/usr/doc/aboot-$VERSION
cat sdisklabel/README > $PKG/usr/doc/aboot-$VERSION/README.sdisk
mkdir -p $PKG/usr/man/man{5,8}
cp -a doc/man/*.8 $PKG/usr/man/man8
cp -a doc/man/*.5 $PKG/usr/man/man5
gzip -9 $PKG/usr/man/man{5,8}/*
mkdir -p $PKG/{sbin,boot,etc}
cp -a sdisklabel/swriteboot sdisklabel/sdisklabel $PKG/sbin
cp -a tools/abootconf tools/e2writeboot tools/isomarkboot $PKG/sbin
cp bootlx $PKG/boot
cp aboot.conf $PKG/etc
strip --strip-unneeded $PKG/sbin/*
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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