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

rm -rf $PKG
mkdir -p $PKG
# This old version is the only one that won't clobber synlinks, e.g.:
# someone moves /opt to /usr/opt and makes a symlink.  With newer
# versions of tar, installing any new package will remove the /opt
# symlink and plop down a new directory there.
# Well, there's a lot of other bugs (the remote stuff particularly I'm
# told is flaky) in tar-1.13, so it'll only be here now for use by the
# Slackware package utils.  And, we'll even let people remove it and
# the pkgutils will still try to work (but eventually they'll pay the
# price :)
( cd $TMP
rm -rf tar-1.13
tar xzf $CWD/tar-1.13.tar.gz
cd tar-1.13
zcat $CWD/bzip2-tar.diff.gz | patch -p1 --verbose || exit 1
chown -R root.root .

./configure \
 --prefix=/usr \
 --disable-nls \
 --build=$TARGET \
 --host=$TARGET || exit 1

make || exit 1
mkdir -p $PKG/bin
cat src/tar > $PKG/bin/tar-1.13
chmod 755 $PKG/bin/tar-1.13

cd $TMP
rm -rf tar-$VERSION
tar xf $CWD/tar-$VERSION.tar.bz2
cd tar-$VERSION

# Don't spew "Record size = foo blocks" messages:
zcat $CWD/tar.norecordsizespam.diff.gz | patch -p1 --verbose || exit 1
# The "A lone zero block at %s" messages also cause problems:
zcat $CWD/tar.nolonezero.diff.gz | patch -p1 --verbose || exit 1
# Add support for *.txz files (our packages)
zcat $CWD/tar-1.23-support_txz.diff.gz | patch -p1 --verbose || exit1
chown -R root:root .

./configure \
 --prefix=/usr \
 --enable-backup-scripts \
 --infodir=/usr/info \
 --build=$TARGET \
 --host=$TARGET || exit 1

make || exit 1
make install DESTDIR=$PKG || exit 1
mv $PKG/usr/bin/tar $PKG/bin
( cd $PKG/usr/bin ; ln -sf /bin/tar . )
( cd $PKG/bin ; ln -sf tar tar-$VERSION )
# Support "historic" rmt locations:
( mkdir $PKG/etc
 cd $PKG/etc
 ln -sf /usr/libexec/rmt .
)
( mkdir -p $PKG/sbin
 cd $PKG/sbin
 ln -sf /usr/libexec/rmt .
)
chown -R root:bin $PKG/usr/bin $PKG/bin $PKG/sbin $PKG/usr/sbin
rm -f $PKG/usr/info/dir
gzip -9 $PKG/usr/info/*
mkdir -p $PKG/usr/doc/tar-$VERSION
cp -a ABOUT-NLS AUTHORS COPYING NEWS README THANKS TODO $PKG/usr/doc/tar-$VERSION
mkdir -p $PKG/usr/man/man{1,8}
cat $CWD/tar.1.gz > $PKG/usr/man/man1/tar.1.gz
cat $CWD/rmt.8.gz > $PKG/usr/man/man8/rmt.8.gz
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
( 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
)
# Build the package:
cd $PKG
makepkg -l y -c n $TMP/tar-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/tar.build.log
