#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# http://www.skype.com/
# Packager Vincenzi Loris - slacky@slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-skype
NAME=skype
VERSION=1.4.0.118
ARCH=i686
BUILD=2sl

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

mkdir -p $PKG
cd $TMP
tar xjvf $CWD/skype_static-$VERSION.tar.bz2
cd skype_static-$VERSION
chown -R root:root .

mkdir -p $PKG/usr/bin
cat << EOF > $PKG/usr/bin/$NAME
#!/bin/bash
cd /usr/share/skype
exec /usr/share/skype/skype
EOF
chmod 755 $PKG/usr/bin/$NAME

mkdir -p $PKG/usr/share/skype
cp -a skype $PKG/usr/share/skype

mkdir -p $PKG/etc/dbus-1/system.d
cp skype.conf $PKG/etc/dbus-1/system.d

mkdir -p $PKG/usr/share/skype
cp -a sounds avatars lang $PKG/usr/share/skype

mkdir -p $PKG/usr/share/applications
cp -a skype.desktop $PKG/usr/share/applications

mkdir -p  $PKG/usr/share/icons/hicolor/16x16/apps
mkdir -p  $PKG/usr/share/icons/hicolor/32x32/apps
mkdir -p  $PKG/usr/share/icons/hicolor/48x48/apps

( cd icons
cp -a SkypeBlue*16*.png $PKG/usr/share/icons/hicolor/16x16/apps/skype.png
cp -a SkypeBlue*32*.png $PKG/usr/share/icons/hicolor/32x32/apps/skype.png
cp -a SkypeBlue*48*.png $PKG/usr/share/icons/hicolor/48x48/apps/skype.png
)

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

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
ADD="qt4 >= 4.3.1-i686-3as, libsigc++-2.0.18-i686-1a, dbus >= 1.0.2-i486-3, alsa-lib >= 1.0.14a-i486-1" \
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
