#!/bin/bash

piece=$1
ooo_build_tag=$2
pack=$3

source $OO_TOOLSDIR/piece/sys-setup

# do we need to do anything?
test "$src_root" = "$DESTDIR" && exit 0

echo "Installing $pack registry to the final location..."

registry_system=$OO_INSTDIR/basis$VERSION/share/registry
registry_solver=$OO_SOLVERDIR/registry
filelist_prebuilt=files-$pack-registry.txt
filelist_final=files-$pack.txt

if test ! -f $registry_solver/$filelist_prebuilt ; then
    echo "Error: cannot find prebuilt registry for $pack"
    exit 1;
fi

# we wants to create even empty directories
for dir in `grep "^%dir" $registry_solver/$filelist_prebuilt | sed "s|^%dir[[:blank:]]*||" | sort -ru` ; do
    mkdir -p "$DESTDIR$dir"
done

# install files
for file in `grep -v "^%dir" $registry_solver/$filelist_prebuilt | sort -ru` ; do
    file_prebuilt=`echo $file | sed "s|$registry_system|$registry_solver|"`
    cp "$file_prebuilt" "$DESTDIR$file"
done

# update the final filelist
cat $registry_solver/$filelist_prebuilt >>$filelist_final
