#!/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"

# 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/libreoffice${BINSUFFIX}.sh || exit 1;
echo /etc/bash_completion.d/libreoffice${BINSUFFIX}.sh >>files-$piece.txt
if test "$COMPAT_OOWRAPPERS" == 'YES' ; then
    $OO_TOOLSDIR/generate-bash-completion --compat-oowrappers --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
fi

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
for file in intro.png intro-pt_BR.png about.png about-pt_BR.png ; do
    if test "$OOO_BUILD_NOARCH" = 'YES' ; then
        # create only symlinks; the icons will be packaged separately
        ln -sf $OO_INSTDIR_SHARE/program/$file $DESTDIR$OO_INSTDIR/program
    else
        cp $OO_SOLVERDIR/default_images/brand/$file $DESTDIR$OO_INSTDIR/program || exit 1;
    fi
    echo "$OO_INSTDIR/program/$file" >>files-$piece.txt
done
# welcome screen
mkdir -p $DESTDIR$OO_INSTDIR/program/shell
echo "%dir $OO_INSTDIR/program/shell" >>files-$piece.txt
for file in backing_left.png backing_left-pt_BR.png backing_right.png \
            backing_right-pt_BR.png backing_rtl_left.png \
            backing_rtl_right.png backing_space.png ; do
    if test "$OOO_BUILD_NOARCH" = 'YES' ; then
        # create only symlinks; the icons will be packaged separately
        ln -sf $OO_INSTDIR_SHARE/program/shell/$file $DESTDIR$OO_INSTDIR/program/shell
    else
        cp $OO_SOLVERDIR/default_images/brand/shell/$file $DESTDIR$OO_INSTDIR/program/shell || exit 1;
    fi
    echo "$OO_INSTDIR/program/shell/$file" >>files-$piece.txt
done
