#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild
# http://freshmeat.net/projects/wbar/
# Packager harakei - "harakei84 AT gmail DOT com"

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-wbar
NAME=wbar
VERSION=1.3.3
ARCH=${ARCH:-i686}
BUILD=5hrk
SOURCE=http://freshmeat.net/redir/wbar/66660/url_mirror/$NAME-$VERSION.tbz2

if [ ! -e $CWD/$NAME-$VERSION.tbz2 ]; then
   wget $SOURCE || exit 1
fi

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

cd $TMP
tar xjvf $CWD/$NAME-$VERSION.tbz2
cd $NAME-$VERSION
chown -R root:root .

#Patch per nascondere la barra, da usare con parametro -balfa 0
#cat hide.patch | patch -p0

make || exit 1
mkdir -p $PKG/usr/share
make PREFIX=$PKG/usr/share/wbar install
mkdir -p $PKG/usr/share/wbar/iconpack/wbar.osx/font/12/
mkdir -p $PKG/usr/bin
cp wbar $PKG/usr/bin
cp -a $PKG/usr/share/wbar/iconpack/comic.ttf $PKG/usr/share/wbar/iconpack/wbar.osx/font/12/

# dot.wbar Fix
sed -i 's/\/tmp\/tgz\/package-wbar//g' $PKG/usr/share/wbar/dot.wbar

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a AUTHORS COPYING NEWS README $PKG/usr/doc/$NAME-$VERSION
make uninstall
cd $PKG
find . | xargs file | grep "shared object" | 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
cat $CWD/doinst.sh > $PKG/install/doinst.sh
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild
requiredbuilder -v -y -s $CWD $PKG
makepkg -l n -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

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