#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# http://thinliquidfilm.org
# Packager Andrea Sciucca ( gohanz at infinito.it)
# http://www.slacky.it
#
# Required: FFmpeg, Xvidcore, Libgpod.

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package/tlf
NAME=tlf
VERSION=1.00
ARCH=${ARCH:-noarch}
BUILD=1as

SOURCE=http://thinliquidfilm.org/$NAME-$VERSION.tar.bz2

if [ ! -e $NAME-$VERSION.tar.bz2 ]; then
wget -c $SOURCE
fi

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

cd $TMP
tar xvjf $CWD/$NAME-$VERSION.tar.bz2

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"

cd thinliquidfilm

find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;

chown -R root:root .

mkdir -p $PKG/usr/bin
mkdir -p $PKG/usr/share/thinliquidfilm

( cd $PKG/usr/bin
  ln -s  /usr/share/thinliquidfilm/thinliquidfilm.py thinliquidfilm
)

cp -a *  $PKG/usr/share/thinliquidfilm

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a README.txt $PKG/usr/doc/$NAME-$VERSION

mkdir -p  $PKG/usr/share/applications/kde

cat << EOF > $PKG/usr/share/applications/kde/thinliquidfilm.desktop
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=ThinLiquidFilm
GenericName=Ipod video converter
GenericName[it]=Convertertitore video per Ipod
Comment=Convert video files into a format suitable for playing on the video capable ipods
Icon=package_multimedia
Exec=thinliquidfilm
Terminal=false
Categories=Qt;KDE;AudioVideo
EOF

mkdir -p  $PKG/usr/share/apps/konqueror/servicemenus

cat << EOF > $PKG/usr/share/apps/konqueror/servicemenus/thinliquidfilm.desktop
[Desktop Action thinliquidfilm]
Exec=thinliquidfilm %U
Icon=package_multimedia
Name=Add to thinliquidfilm
Name[it]=Aggiungi a Thinliquidfilm

[Desktop Entry]
Actions=thinliquidfilm
Icon=package_multimedia
Name=add2thinliquidfilm
ServiceTypes=video/*
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.tgz

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