#!/bin/sh
# Heavily based on the Slackware 13 SlackBuild
# http://www.divineinvasion.net/musicextras/
# Packager Andrea Sciucca Gohanz ( gohanz@infinito.it )
# http://www.slacky.eu

CWD=`pwd`
TMP=${TMP:-/tmp/txz}
PKG=$TMP/package-ruby-mp3info
NAME=ruby-mp3info
VERSION=0.6.13
ARCH=${ARCH:-noarch}
BUILD=2as

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

cd $TMP
tar xzvf $CWD/$NAME-$VERSION.tgz

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 install.rb config
ruby install.rb setup

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

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

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

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

cd $PKG
chown -R root:root .
ADD=$(ls /var/log/packages/ | sed -ne 's/\(ruby\)-\([^-]\+-[^-]\+-[^-]\+\)/\1 >= \2/p') \
requiredbuilder -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/ruby_mp3info-$VERSION-$ARCH-$BUILD.txz

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