#!/bin/bash

piece=$1
ooo_build_tag=$2

source $OO_TOOLSDIR/piece/sys-setup

# generate the common file list
$OO_TOOLSDIR/piece/merge-file-lists "files-$piece.txt" $DESTDIR/gid_*

if test "$VENDORNAME" = "Novell" ; then
    # We want to update an existing gallery. Unfortunately, gengal does not work
    # because of missing services.rdb, ... Therefore we need to use a prebuilt
    # version
    echo "Adding Novell specific Draft.jpg to Backgrounds gallery..."
    GAL_DIR=$OO_INSTDIR/basis$VERSION/share/gallery
    if test `du --block-size=1 --apparent-size $DESTDIR$GAL_DIR/sg3.sdg | cut -f1` -eq 270058 ; then
	cp "$OO_TOOLSDIR/../src/Draft.jpg" "$DESTDIR$GAL_DIR/www-back/" || exit 1;
	chmod 644 $DESTDIR$GAL_DIR/www-back/Draft.jpg || exit 1;
	echo $GAL_DIR/www-back/Draft.jpg >>files-$piece.txt
	for file in sg3.sdg sg3.sdv sg3.thm ; do
	    cp -f "$OO_TOOLSDIR/../src/$file" "$DESTDIR$GAL_DIR/$file" || exit 1;
	    chmod 644 "$DESTDIR$GAL_DIR/$file" || exit 1;
	done
    else
	echo "Error: The upstream gallery sg3.sdg has changed. Please, update the prebuilt"
	echo "       Novell variant in $OO_TOOLSDIR/../src/"
	exit 1;
    fi
fi

# prune .orig files created by patch tool
remove_file "files-$piece.txt" "$OO_INSTDIR/basis$VERSION/presets/config/standard.soc.orig"

# prune redundant files the scp2 likes to make for us
remove_file "files-$piece.txt" "$OO_INSTDIR/basis-link"
remove_file "files-$piece.txt" "$OO_INSTDIR/basis$VERSION/ure-link"
remove_dir  "files-$piece.txt" "$OO_INSTDIR/ure"

# move the stuff to /usr/share when enabled
if test "$OOO_BUILD_NOARCH" = 'YES' ; then
    $OO_TOOLSDIR/piece/install-l10n-helper $piece $ooo_build_tag "$DESTDIR" files-$piece.txt
    $OO_TOOLSDIR/piece/install-devel-helper $piece $ooo_build_tag
fi
