#!/bin/bash

piece=$1
ooo_build_tag=$2

source $OO_TOOLSDIR/piece/sys-setup

custom_install="$OO_TOOLSDIR/piece/inst-$piece"
if test -f $custom_install; then
    $custom_install $piece $ooo_build_tag $DISTRO
fi

# ----- monster make_installer section -----

# can't just source $SOLARENV/inc/minor.mk [ sadly ] - missing quotes.
export BUILD=9319
export LAST_MINOR=m21
export OUT="`pwd`/solver/install"
export LOCAL_OUT=$OUT;
export LOCAL_COMMON_OUT=$OUT;
# install from the copy in the solver - to the system
export SOLARVERSION="`pwd`/solver"
export LANGS="en-US,en-GB"

if test "z$DESTDIR" == "z"; then
    echo "install-generic requires a destdir to be set"
    exit 1
fi

perl -w $SOLARENV/bin/make_installer.pl \
     -f $OO_INSTDIR/solver/instsetoo_native/util/openoffice.lst \
     -l $LANGS -p OpenOffice -debug -verbose -log -buildid $BUILD -destdir $DESTDIR \
     -dontstrip -simple $OO_INSTDIR

# ----- end monster make_installer section -----

# Now try to copy the bits we didn't install into a -devel RPM ...

SRCDIR="$SOLARPIECEVERSION/$INPATH"
DEST="$DESTDIR$OO_SOLVERDIR"
echo "Copy / install remaining devel pieces ..."
filelist="$DESTDIR/all_filelist.txt"
touch $filelist
$OO_TOOLSDIR/piece/copyexcept -x $filelist $SRCDIR/* $DEST
rm -f $filelist

find $DEST -depth -name "CVS" -type d -exec rm -rf {} \;
find $DEST -name "*.orig" -exec rm -rf {} \;
find $DEST -type f -exec chmod go-w {} \;
find $DEST -name "*.h" -exec chmod a-x {} \;

# custom post install stuff
custom_post_install="$OO_TOOLSDIR/piece/post-inst-$piece"
echo test -f $custom_post_install
if test -f $custom_post_install; then
    $custom_post_install $piece $ooo_build_tag $DISTRO
fi
