#!/bin/sh
# Set initial variables:
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-dosfstools
VERSION=2.11
ARCH=alpha
BUILD=2

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf dosfstools-$VERSION
tar xzf $CWD/dosfstools-$VERSION.src.tar.gz
cd dosfstools-$VERSION
chown -R root:root .
make || exit 1
cd mkdosfs
mkdir -p $PKG/sbin
cat mkdosfs > $PKG/sbin/mkdosfs
chmod 755 $PKG/sbin/mkdosfs
mkdir -p $PKG/usr/man/man8
cat mkdosfs.8 | gzip -9c > $PKG/usr/man/man8/mkdosfs.8.gz
cd ../dosfsck
cat dosfsck > $PKG/sbin/dosfsck
chmod 755 $PKG/sbin/dosfsck
cat dosfsck.8 | gzip -9c > $PKG/usr/man/man8/dosfsck.8.gz
cd ..
mkdir -p $PKG/usr/doc/dosfstools-$VERSION
cp -a CHANGES TODO $PKG/usr/doc/dosfstools-$VERSION
mkdir -p $PKG/usr/doc/dosfstools-$VERSION/mkdosfs
( cd mkdosfs ; cp -a ANNOUNCE COPYING README mkdosfs-ygg-0.3b.lsm $PKG/usr/doc/dosfstools-$VERSION/mkdosfs )
mkdir -p $PKG/usr/doc/dosfstools-$VERSION/dosfsck
( cd dosfsck ; cp -a CHANGES COPYING README $PKG/usr/doc/dosfstools-$VERSION/dosfsck )

cd $TMP
rm -rf todos
tar xzf $CWD/todos.tar.gz
cd todos
chown -R root:root .
make || exit 1
mkdir -p $PKG/usr/bin
cat todos > $PKG/usr/bin/todos
cat fromdos > $PKG/usr/bin/fromdos
chmod 755 $PKG/usr/bin/*dos
mkdir -p $PKG/usr/man/man1
cat todos.1.gz > $PKG/usr/man/man1/todos.1.gz
cat fromdos.1.gz > $PKG/usr/man/man1/fromdos.1.gz

( cd $PKG
 find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
 find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/dosfstools-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/dosfstools.build.log
