#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-xfsdump
VERSION=2.2.48-1
ARCH=alpha
BUILD=1

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf xfsdump-$(echo $VERSION | cut -f 1 -d '-')
tar xzf $CWD/xfsdump_$VERSION.tar.gz
cd xfsdump-$(echo $VERSION | cut -f 1 -d '-')
zcat $CWD/xfsdump.destdir.diff.gz | patch -p1 --verbose || exit 1
chown -R root:root .
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
# Make sure you have the same version of autoconf as the
# developers did...  ;-)
autoconf
./configure \
 --prefix=/usr \
 --sbindir=/sbin \
 --bindir=/usr/sbin \
 --enable-gettext=yes \
 --mandir=/usr/man \
 --datadir=/usr/share
make || exit 1
make install DESTDIR=$PKG
( cd $PKG/usr/sbin
 rm -f xfsdump xfsrestore
 ln -sf /sbin/xfsdump xfsdump
 ln -sf /sbin/xfsrestore xfsrestore
)
# Strip libraries:
( 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
)
mv $PKG/usr/share/doc $PKG/usr
rm -rf $PKG/usr/share
( cd $PKG/usr/doc ; mv xfsdump xfsdump-$VERSION )
# It would be nice to keep the same timestamps that the files have in the source:
cp -a README doc/COPYING doc/PORTING $PKG/usr/doc/xfsdump-$VERSION
mkdir -p $PKG/usr/doc/xfsdump-$VERSION/html
( cd doc
 cp -a *.gif *.html $PKG/usr/doc/xfsdump-$VERSION/html
)
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/xfsdump-$(echo $VERSION | tr - _ )-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/xfsdump.build.log
