#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-module-init-tools
VERSION=3.2.2
ARCH=alpha
BUILD=1

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf module-init-tools-$VERSION
tar xjf $CWD/module-init-tools-$VERSION.tar.bz2
cd module-init-tools-$VERSION
find . -perm 664 | xargs chmod 644
chown -R root.root .
zcat $CWD/modprobe.favor.etc.modprobe.d.diff.gz | patch -p1 --verbose || exit 1
./configure \
 --prefix=/ \
 --enable-zlib || exit
make || exit
make install DESTDIR=$PKG || exit
( cd $PKG/sbin ; ln -sf /bin/lsmod . )
( gzip -9 $PKG/usr/share/man/man{5,8}/* )
chown -R root.bin $PKG/bin $PKG/sbin
# Strip things:
( 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/etc/cron.hourly
zcat $CWD/kmod.gz > $PKG/etc/cron.hourly/kmod
chmod 755 $PKG/etc/cron.hourly/kmod
touch $PKG/etc/modules.conf.new
touch $PKG/etc/modprobe.conf.new
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
cd $PKG
makepkg -l y -c n $TMP/module-init-tools-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/module-init.build.log
