#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://www.divineinvasion.net/musicextras/
# Packager Andrea Sciucca  ( gohanz at infinito.it )
# http://www.slacky.eu
# Required: Ruby-Mp3info

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp
fi
PKG=$TMP/package-musicextras
NAME=musicextras
VERSION=0.6.8
ARCH=${ARCH:-noarch}
BUILD=1as

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 $NAME-$VERSION

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 .

ruby setup.rb config --disable-nls
ruby setup.rb setup

mkdir -p $PKG/usr/bin
cp -a $TMP/$NAME-$VERSION/bin/* $PKG/usr/bin

mkdir -p $PKG/usr/lib/ruby/site_ruby/1.8/musicextras
cp -a $TMP/$NAME-$VERSION/lib/musicextras/*.rb $PKG/usr/lib/ruby/site_ruby/1.8/musicextras

mkdir -p $PKG/usr/lib/ruby/site_ruby/1.8/musicextras/gui
cp -a $TMP/$NAME-$VERSION/lib/musicextras/gui/*.rb $PKG/usr/lib/ruby/site_ruby/1.8/musicextras/gui

mkdir -p $PKG/usr/lib/ruby/site_ruby/1.8/musicextras/musicsites
cp -a $TMP/$NAME-$VERSION/lib/musicextras/musicsites/*.rb $PKG/usr/lib/ruby/site_ruby/1.8/musicextras/musicsites

mkdir -p $PKG/usr/share/musicextras
cp -a $TMP/$NAME-$VERSION/data/musicextras/musicextras.glade  $PKG/usr/share/musicextras
cp -a $TMP/$NAME-$VERSION/data/musicextras/no_image.png       $PKG/usr/share/musicextras

mkdir -p $PKG/usr/share/musicextras/html
cp -a $TMP/$NAME-$VERSION/data/musicextras/html/*.html        $PKG/usr/share/musicextras/html

mkdir -p $PKG/usr/share/musicextras/html/css
cp -a $TMP/$NAME-$VERSION/data/musicextras/html/css/*.css   $PKG/usr/share/musicextras/html/css

mkdir -p $PKG/usr/share/musicextras/html/images
cp -a $TMP/$NAME-$VERSION/data/musicextras/html/images/*.gif   $PKG/usr/share/musicextras/html/images/

mkdir -p $PKG/usr/share/locale/de/LC_MESSAGES
cp -a $TMP/$NAME-$VERSION/data/locale/de/LC_MESSAGES/* $PKG/usr/share/locale/de/LC_MESSAGES

mkdir -p $PKG/usr/share/locale/es/LC_MESSAGES
cp -a $TMP/$NAME-$VERSION/data/locale/es/LC_MESSAGES/* $PKG/usr/share/locale/es/LC_MESSAGES

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a \
BUGS COPYING ChangeLog NEWS README THANKS TODO \
  $PKG/usr/doc/$NAME-$VERSION

cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION

chmod ugo+x    $PKG/usr/bin/*

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
chown -R root.root .
requiredbuilder -v -y $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/$NAME-$VERSION
  rm -rf $PKG
fi
