#!/bin/bash

piece=$1
ooo_build_tag=$2

source $OO_TOOLSDIR/piece/sys-setup

# icon themes subpackages
$OO_TOOLSDIR/piece/merge-file-lists "files-icon-themes.txt" $DESTDIR/gid_Module_Root_Files_Images

# generate the common file list
$OO_TOOLSDIR/piece/merge-file-lists "files-$piece.txt" $DESTDIR/gid_*
$OO_TOOLSDIR/piece/desktop-support-app "$piece" "$ooo_build_tag" "fromtemplate"
$OO_TOOLSDIR/piece/desktop-support-app "$piece" "$ooo_build_tag" "ooffice"

# install the common files for the helpcontent
# make compat symlinks for if the primary files are in /usr/share
target_instdir="$OO_INSTDIR"
test "$OOO_BUILD_NOARCH" = 'YES' && target_instdir="$OO_INSTDIR_SHARE"
mkdir -p $DESTDIR$target_instdir/basis$VERSION/help
echo "%dir $target_instdir/basis$VERSION/help" >>files-$piece.txt
if test "$OOO_BUILD_NOARCH" = 'YES' ; then
    mkdir -p $DESTDIR$OO_INSTDIR/basis$VERSION/help
    echo "%dir $OO_INSTDIR/basis$VERSION/help" >>files-$piece.txt
fi
for file in main_transform.xsl idxcaption.xsl idxcontent.xsl ; do
    cp -a $OO_TOOLSDIR/../src/helpcontent2/$file $DESTDIR$target_instdir/basis$VERSION/help/
    echo "$target_instdir/basis$VERSION/help/$file" >>files-$piece.txt
    if test "$OOO_BUILD_NOARCH" = 'YES' ; then
	ln -sf "$target_instdir/basis$VERSION/help/$file" $DESTDIR$OO_INSTDIR/basis$VERSION/help/$file
	echo "$OO_INSTDIR/basis$VERSION/help/$file" >>files-$piece.txt
    fi
done

# extra shared MIME info
mkdir -p $DESTDIR/usr/share/mime/packages
cp $OO_TOOLSDIR/../desktop/openoffice.xml $DESTDIR/usr/share/mime/packages
echo /usr/share/mime/packages/openoffice.xml >>files-$piece.txt
if test "z$RUN_POST_INSTALL_SCRIPTS" = "zyes" && 
    which update-mime-database >/dev/null 2>&1 ; then
    update-mime-database /usr/share/mime || :
fi

# create bash completion
mkdir -p $DESTDIR/etc/bash_completion.d
$OO_TOOLSDIR/generate-bash-completion --binsuffix="$BINSUFFIX" $OO_TOOLSDIR/bash-completion.in $DESTDIR/etc/bash_completion.d/ooffice${BINSUFFIX}.sh || exit 1;
echo /etc/bash_completion.d/ooffice${BINSUFFIX}.sh >>files-$piece.txt

echo "Installing $OO_INSTDIR/basis$VERSION/program/java-set-classpath"
sed -e "s|@OOINSTBASE@|$OO_INSTDIR|g" $OO_TOOLSDIR/java-set-classpath.in >$DESTDIR$OO_INSTDIR/basis$VERSION/program/java-set-classpath || exit 1;
chmod 755 $DESTDIR$OO_INSTDIR/basis$VERSION/program/java-set-classpath
echo "$OO_INSTDIR/basis$VERSION/program/java-set-classpath" >>files-$piece.txt

# FIXME: about, intro are not isntalled by the installer
if test "$OOO_BUILD_NOARCH" = 'YES' ; then
    # create only symlinks; the icons will be packaged separately
    ln -sf $OO_INSTDIR_SHARE/program/about.bmp $DESTDIR$OO_INSTDIR/program
    ln -sf $OO_INSTDIR_SHARE/program/intro.bmp $DESTDIR$OO_INSTDIR/program
else
    cp $OO_SOLVERDIR/default_images/introabout/about.bmp $DESTDIR$OO_INSTDIR/program || exit 1;
    cp $OO_SOLVERDIR/default_images/introabout/intro.bmp $DESTDIR$OO_INSTDIR/program || exit 1;
fi
echo "$OO_INSTDIR/program/about.bmp" >>files-$piece.txt
echo "$OO_INSTDIR/program/intro.bmp" >>files-$piece.txt
