#!/bin/bash
# install bash script - invoked from package-ooo

ln -sf . "$OOINSTDIR/solver/$INPATH"

# environment
cp $OOBUILDDIR/*.[sS]et.sh $DEST

# openoffice lst
cp -R $OOBUILDDIR/instsetoo_native $DEST

# setup_native - not built; odd deps ...
cp $OOBUILDDIR/../setup_native/source/packinfo/*.txt $DEST/bin

# autoconf stuff (needed for SDK)
cp $OOBUILDDIR/config.guess  $DEST/bin
cp $OOBUILDDIR/config.sub  $DEST/bin

LOINSTTOOLSDIR=$OOINSTDIR/build

# build
mkdir -p $LOINSTTOOLSDIR/bin
mkdir -p $LOINSTTOOLSDIR/patches
mkdir -p $LOINSTTOOLSDIR/po
mkdir -p $LOINSTTOOLSDIR/desktop
mkdir -p $LOINSTTOOLSDIR/man
cp -a $TOOLSDIR/bin/* $LOINSTTOOLSDIR/bin || exit 1;
cp -a $TOOLSDIR/patches/* $LOINSTTOOLSDIR/patches || exit 1;
cp -a $TOOLSDIR/po/lo-build-*.sdf $LOINSTTOOLSDIR/po || exit 1;
cp -a $TOOLSDIR/desktop/* $LOINSTTOOLSDIR/desktop || exit 1;
cp -a $TOOLSDIR/man/* $LOINSTTOOLSDIR/man || exit 1;

# the split scripts requires libreoffice.1.in
# rename the original file for LO-3.4
cp $LOINSTTOOLSDIR/man/openoffice.1.in $LOINSTTOOLSDIR/man/libreoffice.1.in

# copy pieces of interest into src to be moved out later ...
echo "copy source pieces"
mkdir -p $LOINSTTOOLSDIR/src
cp -a \
   $TOOLSDIR/src/*.dic \
   $TOOLSDIR/src/*.bmp \
   $TOOLSDIR/src/*.config.in \
   $TOOLSDIR/src/*.pc.in \
   $TOOLSDIR/src/*.png \
   $TOOLSDIR/src/*.jpg \
   $TOOLSDIR/src/*.patch \
   $TOOLSDIR/src/sg3.* \
   $TOOLSDIR/src/sofficerc-upstream \
   $TOOLSDIR/src/default_images \
   $TOOLSDIR/src/helpcontent2 \
   $TOOLSDIR/src/icons \
   $TOOLSDIR/src/layout \
   $LOINSTTOOLSDIR/src || exit 1;
# src/sdf
mkdir -p $LOINSTTOOLSDIR/src/sdf
cp -a \
    $TOOLSDIR/src/sdf/*.sdf \
    $TOOLSDIR/src/sdf/README \
    $LOINSTTOOLSDIR/src/sdf || exit 1;

# branding stuff should go into noarch path
if test "$OOO_BUILD_NOARCH" = 'YES' ; then
    OO_INSTDIR_SHARE=`echo $OOINSTDIR | sed -e "s|/lib6\?4\?/|/share/|"`
    mkdir -p $OO_INSTDIR_SHARE/build/src
    mv \
	$LOINSTTOOLSDIR/src/sofficerc-upstream \
	$OO_INSTDIR_SHARE/build/src || exit 1;
fi

# bin mess and stuff that won't be needed
find $LOINSTTOOLSDIR -depth -name "CVS" -type d -exec rm -rf {} \;
find $LOINSTTOOLSDIR -name "*.orig" -exec rm -rf {} \;
find $LOINSTTOOLSDIR -type f -exec chmod go-w {} \;
find $LOINSTTOOLSDIR -name "Makefile*" -exec rm -rf {} \;
# .in files does not make sense without configure
# in addition, rpm/find-provides goes mad with incomplete script headers, e.g. #!@PERL@ -pi.bak -w
rm -f \
    $LOINSTTOOLSDIR/bin/setup.in \
    $LOINSTTOOLSDIR/bin/font-munge.in \
    $LOINSTTOOLSDIR/bin/help-font-munge.in \
    $LOINSTTOOLSDIR/bin/piece/sys-setup.in

echo "done bootstrap specific install"
