#!/bin/sh
# Heavily based on the Slackware 11.0 SlackBuild
# www.openoffice.org
# Packager Vincenzi Loris - slacky@slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-openoffice
NAME=openoffice-en-us
VERSION=2.2.1
ARCH=${ARCH:-i586}
BUILD=1sl

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

cd $TMP
tar xzvf $CWD/OOo_2.2.1_LinuxIntel_install_en-US.tar.gz
cd OOF680_m18_native_packed-1_en-US.9161/RPMS
mv desktop-integration/openoffice.org-freedesktop-menus-2.2-9153.noarch.rpm .
rpm2tgz *.rpm
explodepkg *.tgz
cp -a opt usr $PKG
rm $PKG/usr/share/applications/*
cp -a $CWD/*.desktop $PKG/usr/share/applications
cd $PKG/opt/openoffice.org2.2
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a LICENSE* README* THIRDPARTYLICENSEREADME.html $PKG/usr/doc/$NAME-$VERSION
cd $PKG/usr/bin
sed -i "s|etc/|opt/|g" openoffice.org2.2
sed -i "s|etc/|opt/|g" openoffice.org2.2-printeradmin
ln -sf /opt/openoffice.org2.2/program/soffice $PKG/usr/bin/soffice
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
mkdir -p $PKG/opt/kde/share/icons
cp -a $PKG/usr/share/icons/hicolor $PKG/opt/kde/share/icons
cp -a $PKG/usr/share/icons/locolor $PKG/opt/kde/share/icons
mkdir -p $PKG/install
cat $CWD/slack-desc-en > $PKG/install/slack-desc
cat $CWD/slack-desc-en > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/openoffice-en_us.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/openoffice-en_us.SlackBuild
find . -perm 775 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 755 {} \;
find . -perm 444 -exec chmod 755 {} \;
chown -R root:root .
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

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