#!/bin/sh

DIRPATH1="Serendipity Blackmagic"
DIRPATH2="Serendipity Megarip"
DIRPATH3="Veripress"

PRODUCTDIR1="$2/$DIRPATH1"
PRODUCTDIR2="$2/$DIRPATH2"
PRODUCTDIR3="$2/$DIRPATH3"


# copy testprints

SOURCEDIR="$1/../../testprn"

DESTDIR1="$2/$DIRPATH1/lib/testprints"
DESTDIR2="$2/$DIRPATH2/lib/testprints"
DESTDIR3="$2/$DIRPATH3/lib/testprints"

if [ -d "$DESTDIR1" ]; then
    DESTDIR="$DESTDIR1"
    PRODUCTDIR="$PRODUCTDIR1"
elif [ -d "$DESTDIR2" ]; then
    DESTDIR="$DESTDIR2"
    PRODUCTDIR="$PRODUCTDIR2"
elif [ -d "$DESTDIR3" ]; then
    DESTDIR="$DESTDIR3"
    PRODUCTDIR="$PRODUCTDIR3"
else
    echo "Could not find product installation directory"
    exit 0
fi

if [ -d "$SOURCEDIR" ]; then
    if [ -d "$DESTDIR" ]; then
	cd "$SOURCEDIR"
	cp -pf * "$DESTDIR"
    fi
fi


# copy any epson related plugins

SOURCEDIR="$1/../../macosx/epson"
DESTDIR="$PRODUCTDIR/lib/epson"

if [ -d "$SOURCEDIR" ]; then
    if [ -d "$DESTDIR" ]; then
	cd "$SOURCEDIR"
	cp -RpfX * "$DESTDIR"
    fi
fi


#cleanup any ._ files
if [ -d "$PRODUCTDIR" ]; then
    cd "$PRODUCTDIR"
    if [ $? != 0 ]; then
	echo "Cannot change directory to $PRODUCTDIR"
	exit 10
    fi
    find . -name '._*' |
    (
	while  { read i; }
	do
	    rm -f "$i"
	done
    )
    find . -name '.AppleDouble' |
    (
	while  { read i; }
	do
	    rm -rf "$i"
	done
    )
fi


