#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://www.rootkit.nl/projects/lynis.html
# Packager Michelino Chionchio - Thanks to www.slacky.eu

set -e

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-lynis
NAME=lynis
VERSION=1.2.1
ARCH=${ARCH:-noarch}
BUILD=1mch

if [ ! -d $TMP ]; then
 mkdir -p $TMP
fi
if [ ! -d $PKG ]; then
 mkdir -p $PKG
fi

mkdir -p $PKG/usr/share
cd $PKG/usr/share
tar xvzf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION

chown -R root:root .

mkdir -p $PKG/usr/bin
cat << EOF > $PKG/usr/bin/lynis
#! /bin/bash
EOF
echo "cd /usr/share/lynis-$VERSION" >> $PKG/usr/bin/lynis
echo "./lynis \$*" >> $PKG/usr/bin/lynis
chmod 755 $PKG/usr/bin/lynis

mkdir -p $PKG/usr/doc/$NAME-$VERSION
mv CHANGELOG FAQ LICENSE README TODO $PKG/usr/doc/$NAME-$VERSION

mkdir -p $PKG/usr/man/man8/
cp -a lynis.8 $PKG/usr/man/man8/
gzip -9 $PKG/usr/man/man8/*

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild
cd $PKG

requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP
fi
