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

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-vnc
NAME=vnc
VERSION=4.1.2
ARCH=${ARCH:-i386}
BUILD=1sl

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

cd $TMP
tar xzvf $CWD/vnc-4_1_2-x86_linux.tar.gz
cd vnc-4_1_2-x86_linux
chown -R root:root .
mkdir -p $PKG/usr/bin
mkdir -p $PKG/usr/man/man1
mkdir -p $PKG/usr/share/vnc
mkdir -p $PKG//usr/lib/xorg/modules/extensions
./vncinstall $PKG/usr/bin
cp vnc.so $PKG//usr/lib/xorg/modules/extensions
cp -a java/* $PKG/usr/share/vnc
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a LICENCE.txt README $PKG/usr/doc/$NAME-$VERSION
cd $PKG
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find $PKG/usr/man -type f -exec gzip -9 {} \;
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
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
