#!/bin/sh
# Set initial variables:
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-bin
VERSION=8.5.3
ARCH=alpha
BUILD=1
TARGET=$ARCH-alphaslack-linux

mkdir -p $PKG
cd $PKG
explodepkg $CWD/_bin.tar.gz

echo "+=============+"
echo "| debianutils |"
echo "+=============+"
( cd $TMP
tar xzf $CWD/debianutils_2.7.tar.gz
cd debianutils-2.7
./configure --prefix=/usr $TARGET
make
make install DESTDIR=$PKG
rm -f $PKG/usr/man/man1/which.1
rm -f $PKG/usr/man/man8/run-parts.8

echo "+==============+"
echo "| eject-2.0.13 |"
echo "+==============+"
cd $TMP
tar xzf $CWD/eject-2.0.13.tar.gz
cd eject-2.0.13
./configure --prefix=/usr $TARGET
make
make install DESTDIR=$PKG

echo "+===========+"
echo "| fbset-2.1 |"
echo "+===========+"
cd $TMP
tar xzf $CWD/fbset-2.1.tar.gz
cd fbset-2.1
make
strip fbset
mkdir -p $PKG/usr/sbin
cat fbset > $PKG/usr/sbin/fbset
chown -R root.bin $PKG/usr/sbin
chmod 755 $PKG/usr/sbin/fbset
mkdir -p $PKG/etc
cat etc/fb.modes.ATI > $PKG/etc/fb.modes
mkdir -p $PKG/usr/man/man5
cat fb.modes.5 | gzip -9c > $PKG/usr/man/man5/fb.modes.5.gz
mkdir -p $PKG/usr/man/man8
cat fbset.8 | gzip -9c > $PKG/usr/man/man8/fbset.8.gz

echo "+========+"
echo "| ed-0.2 |"
echo "+========+"
cd $TMP
tar xzf $CWD/ed-0.2.tar.gz
cd ed-0.2
zcat $CWD/ed-0.2.mkstemp.diff.gz | patch -p1 -E --backup --verbose
./configure --prefix=/usr $TARGET
make
cat ed > $PKG/bin/ed
cat ed.1 | gzip -9c > $PKG/usr/man/man1/ed.1.gz
cat ed.info | gzip -9c > $PKG/usr/info/ed.info.gz

echo "+==========+"
echo "| compress |"
echo "+==========+"
cd $TMP
tar xzf $CWD/compress.tar.gz
cd compress
zcat $CWD/compress.diff.gz | patch -p0 -E --backup --verbose
make
cat compress > $PKG/usr/bin/compress
cat compress.1 | gzip -9c > $PKG/usr/man/man1/compress.1.gz
echo '.so man1/compress.1' | gzip -9c > $PKG/usr/man/man1/uncompress.1.gz

echo "+=========+"
echo "| banners |"
echo "+=========+"
cd $TMP
tar xzf $CWD/banners.tar.gz
cd banners
make
cat bban > $PKG/usr/bin/bban
cat sysvbanner > $PKG/usr/bin/sysvbanner

echo "+===========+"
echo "| file-X.xx |"
echo "+===========+"
cd $TMP
tar xzf $CWD/file-4.09.tar.gz
cd file-4.09
chown -R root.root .
zcat $CWD/file.magic.diff.gz | patch -p1 -E --verbose
zcat $CWD/file.zisofs.diff.gz | patch -p1 -E --verbose
./configure --prefix=/usr --sysconfdir=/etc --datadir=/etc --enable-fsect-man5 $TARGET
mkdir -p $PKG/usr/doc/file-4.09
cp -a LEGAL.NOTICE README $PKG/usr/doc/file-4.09
chmod 644 $PKG/usr/doc/file-4.09/*
make
make install DESTDIR=$PKG

echo "+=============+"
echo "| patch-2.5.4 |"
echo "+=============+"
cd $TMP
tar xzf $CWD/patch-2.5.4.tar.gz
cd patch-2.5.4
mkdir -p $PKG/usr/doc/patch-2.5.4
cp -a AUTHORS COPYING INSTALL NEWS README $PKG/usr/doc/patch-2.5.4
chmod 644 $PKG/usr/doc/patch-2.5.4/*
chown root.root $PKG/usr/doc/patch-2.5.4/*
./configure --prefix=/usr $TARGET
make
cat patch > $PKG/usr/bin/patch
cat patch.man  | gzip -9c > $PKG/usr/man/man1/patch.1.gz

echo "+===========+"
echo "| rpm2targz |"
echo "+===========+"
cd $TMP
cc -o rpmoffset $CWD/rpmoffset.c
strip rpmoffset
cat rpmoffset > $PKG/usr/bin/rpmoffset
rm rpmoffset
cat $CWD/rpm2targz > $PKG/usr/bin/rpm2targz
mkdir -p $PKG/usr/doc/rpm2targz
cp -a $CWD/rpm2targz.README $PKG/usr/doc/rpm2targz/rpm2targz.README
chown root.root $PKG/usr/doc/rpm2targz/rpm2targz.README
chmod 644 $PKG/usr/doc/rpm2targz/rpm2targz.README

echo "+===========+"
echo "| run-parts |"
echo "+===========+"
zcat $CWD/run-parts.gz > $PKG/usr/bin/run-parts
chmod 755 $PKG/usr/bin/run-parts
chown root.bin $PKG/usr/bin/run-parts
cat $CWD/run-parts.8.gz > $PKG/usr/man/man8/run-parts.8.gz

echo "+=================+"
echo "| sharutils-4.2.1 |"
echo "+=================+"
cd $TMP
tar xzf $CWD/sharutils-4.2.1.tar.gz
cd sharutils-4.2.1
mkdir -p $PKG/usr/doc/sharutils-4.2.1
cp -a ABOUT-NLS AUTHORS BACKLOG COPYING INSTALL NEWS README README.OLD THANKS TODO $PKG/usr/doc/sharutils-4.2.1
chown root.root $PKG/usr/doc/sharutils-4.2.1/*
chmod 644 $PKG/usr/doc/sharutils-4.2.1/*
# For now, NLS seems to cause build errors on this one...
./configure --disable-nls --prefix=/usr $TARGET
make
cd src
cat shar > $PKG/usr/bin/shar
cat unshar > $PKG/usr/bin/unshar
cat uuencode > $PKG/usr/bin/uuencode
cat uudecode > $PKG/usr/bin/uudecode
cd ../doc
cat sharutils.info | gzip -9c > $PKG/usr/info/sharutils.info.gz
# Include old manpages, since the source package doesn't have them anymore:
for page in shar.1.gz unshar.1.gz uuencode.1.gz ; do
  cat $CWD/$page > $PKG/usr/man/man1/$page
done
echo '.so man1/uuencode.1' | gzip -9c > $PKG/usr/man/man1/uudecode.1.gz
cat $CWD/uuencode.5.gz > $PKG/usr/man/man5/uuencode.5.gz

echo "+===============+"
echo "| splitvt-1.6.5 |"
echo "+===============+"
cd $TMP
tar xzf $CWD/splitvt-1.6.5.tar.gz
cd splitvt-1.6.5
./configure
make
cat splitvt > $PKG/usr/bin/splitvt
cat splitvt.1 | gzip -9c > $PKG/usr/man/man1/splitvt.1.gz
mkdir -p $PKG/usr/doc/splitvt-1.6.5
cp -a examples ANNOUNCE CHANGES NOTES README TODO $PKG/usr/doc/splitvt-1.6.5
( cd $PKG/usr/doc/splitvt-1.6.5
  find . -type d | xargs chmod 755
  find . -type f | xargs chmod 644 )
chown -R root.root $PKG/usr/doc/splitvt-1.6.5

echo "+==========+"
echo "| time-1.7 |"
echo "+==========+"
cd $TMP
tar xzf $CWD/time-1.7.tar.gz
cd time-1.7
zcat $CWD/resuse.h.diff.gz | patch -p0 --verbose
./configure --prefix=/usr $TARGET
make
cat time > $PKG/usr/bin/time
cat time.info | gzip -9c > $PKG/usr/info/time.info.gz

echo "+============+"
echo "| tree-1.4b3 |"
echo "+============+"
cd $TMP
tar xzf $CWD/tree-1.4b3.tar.gz
cd tree-1.4
zcat $CWD/tree-gcc34.patch.gz | patch -p1 --verbose
make clean
make
cat tree > $PKG/usr/bin/tree
chown root.bin $PKG/usr/bin/tree
chmod 755 $PKG/usr/bin/tree
cat tree.1 | gzip -9c > $PKG/usr/man/man1/tree.1.gz
mkdir -p $PKG/usr/doc/tree-1.4b3
cp -a CHANGES LICENSE README README.sacl $PKG/usr/doc/tree-1.4b3
chmod 644 $PKG/usr/doc/tree-1.4b3/*
chown -R root.root $PKG/usr/doc/tree-1.4b3

echo "+============+"
echo "| which-2.16 |"
echo "+============+"
cd $TMP
tar xzf $CWD/which-2.16.tar.gz
cd which-2.16
./configure --prefix=/usr $TARGET
make
cat which > $PKG/usr/bin/which
cat which.1 | gzip -9c > $PKG/usr/man/man1/which.1.gz
cat which.info | gzip -9c > $PKG/usr/info/which.info.gz
mkdir -p $PKG/usr/doc/which-2.16
cp -a AUTHORS COPYING EXAMPLES INSTALL NEWS README README.alias $PKG/usr/doc/which-2.16
chown -R root.root $PKG/usr/doc/which-2.16

# Add a very handy tool for scanning new SCSI devices.  Most useful for 
# finding new USB and Firewire storage devices which show up as SCSI. 
cp -a $CWD/rescan-scsi-bus $PKG/sbin/rescan-scsi-bus
chmod 755 $PKG/sbin/rescan-scsi-bus

# Strip everything for good measure:
cd $PKG
( cd usr/bin ; rm -rf unarj zoo fiz lha bpe )
( cd usr/man ; rm -rf fr )
( cd usr/share/locale ; rm -rf * )
( cd usr/man ; gzip -9f man{1,3,5,8}/* )
( strip --strip-unneeded bin/* usr/bin/* usr/lib/*.so.* )
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
echo "n" | makepkg $TMP/bin-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/bin.build.log
