#!/bin/sh
# Heavily based on the Slackware 13.0 SlackBuild
# http://sourceforge.net/projects/pokerth
# Packagers Andrea Sciucca  ( gohanz at infinito.it)
# http://www.slacky.eu

CWD=`pwd`
TMP=${TMP:-/tmp/txz}
NAME=pokerth
PKG=$TMP/package-$NAME
VERSION=0.7.1
ARCH=${ARCH:-i686}
BUILD=1as
SOURCE=http://downloads.sourceforge.net/project/pokerth/pokerth/0.7/PokerTH-$VERSION-linux.zip?use_mirror=surfnet

if [ ! -e PokerTH-$VERSION-linux.zip ]; then
wget -c $SOURCE
fi

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

cd $TMP
unzip $CWD/PokerTH-$VERSION-linux.zip
cd PokerTH-$VERSION

echo -e "\E[0;32m+------------------------------+\E[0;0m"
echo -e "\E[0;32m| Start SlackBuild $NAME-$VERSION |\E[0;0m"
echo -e "\E[0;32m+------------------------------+\E[0;0m"

find . \( -perm 777 -o -perm 775 -o -perm 711 \) -exec chmod 755 {} \;
find . \( -perm 700 -o -perm 555 -o -perm 744 \) -exec chmod 755 {} \;
find . \( -perm 666 -o -perm 664 -o -perm 600 \) -exec chmod 644 {} \;
find . \( -perm 444 -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;

chown -R root:root .

mkdir -p $PKG/usr/share/$NAME
cp -a * $PKG/usr/share/$NAME
mkdir -p $PKG/usr/bin
cp $CWD/pokerth $PKG/usr/bin
chmod 755 $PKG/usr/bin/pokerth
mkdir -p $PKG/usr/doc/$NAME-$VERSION
mkdir -p $PKG/usr/share/applications

cat << EOF > $PKG/usr/share/applications/$NAME.desktop
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=PokerTH
Name[it]=PokerTH
GenericName=Poker Game 
GenericName[it]=Gioco del Poker
Comment=Single-Player Poker Game written in C++/QT4
Icon=package_games_card
TryExec=pokerth
Exec=pokerth
Terminal=false
Categories=Qt;KDE;Game;CardGame;
EOF

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 -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.txz

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