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

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf smartmontools-$VERSION
tar xjf $CWD/smartmontools-$VERSION.tar.bz2
cd smartmontools-$VERSION
./configure \
 --prefix=/usr \
 --sysconfdir=/etc \
 --mandir=/usr/man \
 --with-docdir=/usr/doc/smartmontools-$VERSION \
 --build=$TARGET || exit 1
make || exit 1
make install DESTDIR=$PKG
rm -f $PKG/usr/doc/smartmontools-$VERSION/CHANGELOG $PKG/usr/doc/smartmontools-$VERSION/smartd.conf
( 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/etc/smartd.conf $PKG/etc/smartd.conf.new
chmod 755 $PKG/usr/sbin/*
chown -R root.bin $PKG/usr/sbin
gzip -9 $PKG/usr/man/man{5,8}/*
chmod 644 $PKG/usr/doc/smartmontools-$VERSION/*
chown -R root.root $PKG/usr/doc/smartmontools-$VERSION
rm -rf $PKG/etc/rc.d
mkdir -p $PKG/install
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/smartmontools-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/smartmon.build.log
