#!/bin/sh
# Build snort for AlphaSlack.
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-snort
VERSION=2.6.1.2
ARCH=alpha
BUILD=1
TARGET=$ARCH-alphaslack-linux

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf snort-$VERSION
tar xzf $CWD/snort-$VERSION.tar.gz
cd snort-$VERSION
chown -R root.root .
find . -perm 775 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
./configure \
 --prefix=/usr \
 --with-mysql \
 --with-postgresql \
 $TARGET
make || exit
make DESTDIR=$PKG install
mkdir -p $PKG/usr/doc/snort-$VERSION
cd doc
cp -a README TODO BUGS CREDITS AUTHORS NEWS PROBLEMS RULES.todo USAGE WISHLIST $PKG/usr/doc/snort-$VERSION
cd ..
gzip -9 $PKG/usr/man/man?/*.?
( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/snort-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/snort.build.log
